Skip to content

Instantly share code, notes, and snippets.

@jamenlang
Last active November 3, 2020 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamenlang/49513b92f2d063ea132ee583395c75e7 to your computer and use it in GitHub Desktop.
Save jamenlang/49513b92f2d063ea132ee583395c75e7 to your computer and use it in GitHub Desktop.
Dynamic postmulti management script
#!/bin/bash
# assuming all of the instances start with "postf" e.g. "postfix-2" or "postfix-test"
mapfile -t instance_array < <( find /etc* -maxdepth 1 -type d -name "postf*" -printf "%f\n" )
for instance in "${instance_array[@]}"
do
echo "copying resolv.conf for ${instance}"
cp /etc/resolv.conf "/var/spool/${instance}/etc/resolv.conf"
echo "updating ssl certs for ${instance}"
mkdir -p "/var/spool/${instance}/etc/ssl/certs"
cp /etc/ssl/certs/ca-certificates.crt "/var/spool/${instance}/etc/ssl/certs/ca-certificates.crt"
if [[ ${instance} != postfix ]]; then
echo "updating required libraries for ${instance}"
mkdir -p "/var/spool/${instance}/lib"
cp /var/spool/postfix/lib/x86_64-linux-gnu "/var/spool/${instance}/lib" -r
fi
echo "updating postfix token ownership for ${instance}"
chown -R postfix:postfix /var/spool/${instance}/etc/tokens
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment