#!/usr/bin/env bash # filename: get-acme # requires: crontab, curl (or wget), grep, sed # author: G. D. LaBossiere, Xview Solutions Inc. # last modified: 2017-03-25 # license: GNU GPL v3 # comments: custom installer for ################################# global vars ################################# acmeHome="${HOME}/.acme.sh" acmeCmd="${acmeHome}/acme.sh" agreeVar="DEFAULT_AGREEMENT=" agreeVal="https://acme-v01.api.letsencrypt.org/terms/" ################################ start program ################################ [[ $EUID -eq 0 ]] && { printf "Do not run this script as root.\n" exit 1 } # prompt if fd 0 (stdin) and fd 1 (stdout) point to a terminal (tty/pts) [[ -t 0 && -t 1 ]] && { printf "\n%b\n" "---------------------------------------------------------------------------------" printf "This script will download, install and modify the acme.sh environment for working\n" printf "with LetsEncrypt.org domain-validated SSL certificates. Enter C or c to continue,\n" printf "any other key to quit: "; read myChoice case $myChoice in c|C ) : ;; * ) exit 0 ;; esac printf "\n%b\n" "---------------------------------------------------------------------------------" } # prefer curl over wget as download tool type -p wget > /dev/null [[ $? -eq 0 ]] && pullCmd="wget -q -O - https://get.acme.sh | bash" type -p curl > /dev/null [[ $? -eq 0 ]] && pullCmd="curl -s https://get.acme.sh | bash" [[ -z $pullCmd ]] && { printf "Need curl or wget to retrieve acme.sh. Neither found. Quitting.\n" exit 1 } printf "[$(date)] Retrieving script from https://get.acme.sh and running it.\n" eval $pullCmd printf "[$(date)] Modifying URL for LetsEncrypt ToS doc (auto-redirects to latest version).\n" cmdResult="Failed" # to avoid escaping '/' inside a sed regex, use an alternate delimiter for #+ patterns in an address (e.g. '\| ... |') and after 's' (e.g. 's| ... |') sed -i "\|^[[:space:]]*$agreeVar.*$| s|$agreeVar.*|$agreeVar$agreeVal|" "${acmeCmd}" printf "[$(date)] "; grep "$agreeVar$agreeVal" "$acmeCmd" [[ $? -eq 0 ]] && cmdResult="[$(date)] Success" printf "${cmdResult}!\n" printf "[$(date)] Disabling certificate auto-renewal (removes cron job added by install script).\n" cmdResult="Failed" ${acmeCmd} --uninstall-cronjob [[ -z "$(crontab -l | grep 'acme.sh')" ]] && cmdResult="Success" printf "[$(date)] ${cmdResult}!\n" printf "[$(date)] Modifications complete.\n" printf "%b\n" "---------------------------------------------------------------------------------" printf "To update your environment without having to log out and then log back in again,\n" printf "type: \"source \$HOME/.acme.sh/acme.sh.env\" (omit the quotes) and press Enter.\n" # end program