Files
shell_sequencer/seqs/certbot.sh

84 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Certbot installation and creation supporting Raspbian and Ubuntu.
# Certificate can be created/updated as "certonly" only.
toolName=certbot
# Get script working directory
# (when called from a different directory)
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
CONFIG=0
CONFIG_FILE_NAME="${toolName}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
step_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
local confReturn=$?
if [ $confReturn -eq 0 ] ; then
CONFIG=1
fi
}
step_1_info() { echo "Install $toolName for letsencrypt"; }
step_1_alias() { ALIAS="install"; }
step_1() {
local osName=
local distName=
if [ "$(which lsb_release)" == "" ] ; then
echoerr " [W] Cannot detect OS. Assuming Ubuntu"
osName="Ubuntu"
else
osName=$(lsb_release -is)
distName=$(lsb_release -cs)
fi
if [ "$osName" == "" ] ; then
echoerr " [W] Error dedecting OS. Assuming Ubuntu"
osName="Ubuntu"
fi
echo " [I] Detected OS: $osName $distName"
local aptOption=
if [ $QUIET -ne 0 ] ; then
aptOption="-y"
else
aptOption=""
fi
if [ "$osName" == "Ubuntu" ] ; then
exe apt-get update
exe apt-get install software-properties-common $aptOption
saveReturn $?
exe add-apt-repository universe $aptOption
saveReturn $?
exe add-apt-repository ppa:certbot/certbot $aptOption
saveReturn $?
exe apt-get update
exe apt-get install $toolName $aptOption
saveReturn $?
endReturn "$toolName installation for $osName failed"
elif [ "$osName" == "Raspbian" ] ; then
exe apt update
exe apt install certbot
endReturn "$toolName installation for $osName failed"
fi
}
step_2_info() { echo "Create or update letsencrypt certificate"; }
step_2_alias() { ALIAS="update"; }
step_2() {
endCheckEmpty CERTBOT_DOMAINS "No domain list found. Check configuration"
endCheckEmpty CERTBOT_WEBROOT "Invalid web root. Check configuration"
endCheckEmpty CERTBOT_MAIL "Invalid mail address. Check configuration"
exe certbot certonly --webroot -w "$CERTBOT_WEBROOT" --rsa-key-size 4096 --expand --agree-tos \
-m "$CERTBOT_MAIL" ${CERTBOT_DOMAINS[@]/#/-d }
}
VERSION_SEQREV=11
. /usr/local/bin/sequencer.sh