Add script flags for optionally installing acme.sh or downloading default conf

This commit is contained in:
Alex Thomassen 2021-12-22 15:18:34 +01:00
parent e147736143
commit ab4daf41d4
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
1 changed files with 61 additions and 11 deletions

View File

@ -1,15 +1,60 @@
#!/bin/bash
INSTALL_ACMESH=0;
DOWNLOAD_DEFAULT=0;
GIST="https://gist.github.com/Decicus/2f09db5d30f4f24e39de3792bba75b72/raw"
NGINX="/etc/nginx"
SSL_BASE="/srv/ssl"
DEFAULT_DIR="$NGINX/conf.d";
DEFAULT_NAME="000-default.conf";
help()
{
cat << EOF
usage: $0
Install the \`nginx\` package via apt and add extra configuration files.
OPTIONS:
-h Shows helptext
-a Installs acme.sh and downloads "bootstrapping" files.
-d Downloads the $DEFAULT_NAME file into $DEFAULT_DIR
EOF
}
while getopts "had" opt; do
case $opt in
h)
help
exit 0
;;
a)
INSTALL_ACMESH=1;
echo "Installing and bootstrapping \`acme.sh\`";
;;
d)
DOWNLOAD_DEFAULT=1;
echo "Downloading 000-default.conf to /etc/nginx/conf.d";
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Make sure the 'essentials' are installed
# We use `nginx` as the script assumes the script for using nginx.org APT repos has been used (https://git.io/nginx-debian)
# Using `nginx-full` would in this case use the Debian/Ubuntu repos, which are a few versions behind.
sudo apt install -y nginx openssl curl
# Get acme.sh for issuing certificates
curl -L https://get.acme.sh/ | sudo bash
GIST="https://gist.github.com/Decicus/2f09db5d30f4f24e39de3792bba75b72/raw"
NGINX="/etc/nginx"
SSL_BASE="/srv/ssl"
if [[ $INSTALL_ACMESH ]]; then
# Get acme.sh for issuing certificates
curl -L https://get.acme.sh/ | sudo bash
fi
# Create preferred base directory for storing SSL certificates
mkdir -p $SSL_BASE
@ -22,7 +67,12 @@ chmod -R 600 $SSL_BASE
# But I use zsh as the main shell
# Therefore I need a shared "environment file" that loads acme.sh
# And related environment variables
curl -L "$GIST/.acmeenv" > "$HOME/.acmeenv"
if [[ $INSTALL_ACMESH ]]; then
# Add to ZSH/Bash config files
curl -L "$GIST/.acmeenv" > "$HOME/.acmeenv"
echo '. "$HOME/.acmeenv"' >> "$HOME/.zshrc";
echo '. "$HOME/.acmeenv"' >> "$HOME/.bashrc";
fi
# Get the alias config for Let's Encrypt challenges:
curl -L "$GIST/letsencrypt.conf" > "$NGINX/letsencrypt.conf"
@ -40,8 +90,8 @@ curl -L "$GIST/phpfpm.conf" > "$NGINX/phpfpm.conf"
# Get the dhparams file generation script, and execute.
curl -L "$GIST/generate-dhparams.sh" | sudo bash
# Add to ZSH/Bash config files
echo '. "$HOME/.acmeenv"' >> "$HOME/.zshrc";
echo '. "$HOME/.acmeenv"' >> "$HOME/.bashrc";
if [[ $DOWNLOAD_DEFAULT ]]; then
curl -L "$GIST/$DEFAULT_NAME" > "$DEFAULT_DIR/$DEFAULT_NAME"
fi
echo "Base setup done. Open this link for a base nginx site configuration: $GIST/000-default.conf"
echo "Base setup done. Open this link for a base nginx site configuration: $GIST/$DEFAULT_NAME"