87 lines
2.3 KiB
Bash
Executable File
87 lines
2.3 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_FILE="$WDIR/${toolName}.cfg"
|
|
CONFIG_FILE_DEFAULT="${CONFIG_FILE}.example"
|
|
|
|
step_config() {
|
|
if [ ! -s "$CONFIG_FILE" ] && [ ! -s "$CONFIG_FILE_DEFAULT" ] ; then
|
|
echoerr " [E] No configuration \"$CONFIG_FILE_DEFAULT\" or \"$CONFIG_FILE\" found"
|
|
exit 1;
|
|
fi
|
|
if [ -s "$CONFIG_FILE" ] ; then
|
|
. "$CONFIG_FILE"
|
|
else
|
|
echoerr " [E] No user configuration \"$CONFIG_FILE\" found. (See template $CONFIG_FILE_DEFAULT)"
|
|
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 "Invalid domain list"
|
|
endCheckEmpty CERTBOT_WEBROOT "Invalid web root"
|
|
endCheckEmpty CERTBOT_MAIL "Invalid mail address"
|
|
|
|
exe certbot certonly --webroot -w "$CERTBOT_WEBROOT" --rsa-key-size 4096 --expand --agree-tos \
|
|
-m "$CERTBOT_MAIL" ${CERTBOT_DOMAINS[@]/#/-d }
|
|
}
|
|
|
|
VERSION_SEQREV=8
|
|
. /usr/local/bin/sequencer.sh
|