Recursively find files with the same filename

I needed a way to find files with the same filename, but were not identical files. Thankfully Reddit had the solution I was looking for: a combination of find, sort, and while loop with if statements.

https://www.reddit.com/r/bash/comments/fjsr8v/recursively_find_files_with_same_name_under_a/

find . -type f -printf '%f/%p\0' | { sort -z -t/ -k1; printf '\0';} |
while IFS=/ read -r -d '' name file; do
    if [[ "$name" = "$oldname" ]]; then
        repeated+=("$file")  # duplicate file
        continue
    fi
    if (( ${#repeated[@]} > 1)); then
        printf '%s\n' "$oldname" "${repeated[@]}" ''
        # do something with list "${repeated[@]}"
    fi
    repeated=("$file")
    oldname=$name
done

Load balancing behind Nginx Proxy Manager

Nginx proxy manager is a really convenient UI wrapped around nginx. It covers the most common use cases very well. If you have more advanced needs, then it requires some custom configuration. In my case, I wanted to load balance my Proxmox servers. This is how you do that, as per https://nginxproxymanager.com/advanced-config/#custom-nginx-configurations and https://www.reddit.com/r/selfhosted/comments/1fp5mxz/nginx_proxy_manager_fails_when_adding_load/

  1. Make directories & create data/nginx/custom/root_top.conf
  2. Populate with your upstream server list
    upstream proxmox-backend {
    server first_server.fqdn:8006;
    server second_server.fqdn:8006;
    server nth_server.fqdn:8006;
    }
  3. Set proxy host for http://backend and edit proxy host to have the following in the Advanced tab:
    location / {
    proxy_pass https://proxmox-backend;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    4.Profit

In my case it is very simple load balancing with no persistent cookies/session (not needed for my application.) But all those options exist for nginx and it’s just a matter of adding them in custom configuration for NPM.

Configure Proxmox Mail Gateway to use AnyMX relay

I needed to configure Proxmox Mail Gateway to use an authenticated SMTP relay for outgoing mail. There is no way to add a username and password in the PMG GUI; however, you can do it in the command line and it follows standard postfix syntax. Thanks to this post for helping me get it set up: https://forum.proxmox.com/threads/relay-username-and-password.129586

To get it to work you have to drop to the CLI and configure your username and password. Then copy the template file over and make your changes there, as editing postfix directly gets overwritten with subsequent GUI changes.

mkdir /etc/pmg/templates/

cp /var/lib/pmg/templates/main.cf.in /etc/pmg/templates/main.cf.in

create /etc/postfix/smtp_auth and populate it:

relay.host.tld   username:password

Append the following to the /etc/pmg/templates/main.cf.in template:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
smtp_sasl_security_options = noanonymous

Change permissions to smtp_auth file, run postmap to generate the db with the password, and run pmgconfig to refresh the configuration.

chmod 640 /etc/postfix/smtp_auth
postmap /etc/postfix/smtp_auth
pmgconfig sync --restart 1

This worked for me.