Skip to content
Snippets Groups Projects
Unverified Commit 18d5b4e6 authored by Max Adamo's avatar Max Adamo
Browse files

added crontab installation option

parent ec2ee9e1
Branches
Tags
No related merge requests found
Pipeline #77328 passed
...@@ -84,7 +84,7 @@ fi ...@@ -84,7 +84,7 @@ fi
usage() { usage() {
echo "Usage: $(basename $0)" echo "Usage: $(basename $0)"
echo " -h | --help [Print this help and exit]" echo " -h | --help [Print this help and exit]"
echo " --redis-token (Redis access token)" echo " --install-crontab (Install nightly crontab entry)"
echo " --vault-token (Vault access token)" echo " --vault-token (Vault access token)"
echo " --cert-name (Certificate name)" echo " --cert-name (Certificate name)"
echo " --team-name (Team name: swd, it, neteng, nmaas ...)" echo " --team-name (Team name: swd, it, neteng, nmaas ...)"
...@@ -102,7 +102,7 @@ usage() { ...@@ -102,7 +102,7 @@ usage() {
clean_up 2 clean_up 2
} }
OPTS=$(getopt -o "h" --longoptions "help,redis-token:,vault-token:,cert-name:,team-name:,days:,type:,cert-destination:,fullchain-destination:,key-destination:,ca-destination:,check-version,update,force-update,version,wildcard" -- "$@") OPTS=$(getopt -o "h" --longoptions "help,install-crontab,redis-token:,vault-token:,cert-name:,team-name:,days:,type:,cert-destination:,fullchain-destination:,key-destination:,ca-destination:,check-version,update,force-update,version,wildcard" -- "$@")
eval set -- "$OPTS" eval set -- "$OPTS"
while true; do while true; do
...@@ -159,6 +159,9 @@ while true; do ...@@ -159,6 +159,9 @@ while true; do
--force-update) --force-update)
FORCE_UPDATE='FORCE_UPDATE' FORCE_UPDATE='FORCE_UPDATE'
;; ;;
--install-crontab)
INSTALL_CRONTAB='INSTALL_CRONTAB'
;;
--check-version) --check-version)
CHECK='CHECK' CHECK='CHECK'
;; ;;
...@@ -179,6 +182,48 @@ if [[ -n $PARAM_VERSION ]]; then ...@@ -179,6 +182,48 @@ if [[ -n $PARAM_VERSION ]]; then
clean_up 0 clean_up 0
fi fi
# install crontab and say goodbye (got this from OpenAI)
generate_crontab_time() {
min=$1
max=$2
string=$3
range=$((max - min + 1))
# Generate a fixed random seed from a constant value
RANDOM=$(echo "$3" | sha256sum | awk '{print $1}' | cut -c1-8)
echo $((RANDOM % range + min))
}
if [[ -n $INSTALL_CRONTAB ]]; then
if [[ -z $REDIS_TOKEN ]] || [[ -z $VAULT_TOKEN ]] || [[ -z $CERT_NAME ]] || [[ -z $TEAM_NAME ]] || [[ -z $TYPE ]]; then
echo -e "\n--redis-token, --vault-token, --cert-name, --team-name and --type are mandatory\n"
usage
fi
echo ""
echo "when the certificate will be renewed and installed you may need to restart a service: nginx, apache2, mysql..."
echo "You can change this setting later"
read -p "please enter the name of the service : " SERVICE_NAME
VM_ID=$(cat /sys/class/dmi/id/product_uuid)
CRON_HOUR=$(generate_crontab_time 0 8 "$VM_ID")
CRON_MINUTE=$(generate_crontab_time 0 30 "$VM_ID")
CRON_HOUR_UPDATE=$(generate_crontab_time 0 8 "$VM_ID")
CRON_MINUTE_UPDATE=$(generate_crontab_time 31 59 "$VM_ID")
cat <<EOF >/etc/cron.d/acme-downloader-update
# update acme-downloader script
$CRON_MINUTE_UPDATE $CRON_HOUR_UPDATE * * * root $0 --update >/dev/null
EOF
cat <<EOF >/etc/cron.d/acme-downloader
# run ACME Downloader
$CRON_MINUTE $CRON_HOUR * * * root $0 --redis-token $REDIS_TOKEN --vault-token $VAULT_TOKEN --team-name $TEAM_NAME --cert-name $TEAM_NAME --type $TYPE >/dev/null; if [ "\$?" -eq 64 ]; then /bin/systemctl restart $SERVICE_NAME; fi
EOF
echo ""
echo "crontab was succesfully installed"
echo "You can edit and change the following file: /etc/cron.d/acme-downloader"
echo ""
fi
# check if we are using the latest version # check if we are using the latest version
check_version check_version
VERSION_STATUS=$? VERSION_STATUS=$?
...@@ -268,7 +313,7 @@ if [[ -z $WILDCARD ]]; then ...@@ -268,7 +313,7 @@ if [[ -z $WILDCARD ]]; then
curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:${CERT_NAME}:redis_${CERTNAME_PREFIX}_chain_pem.txt >$TMP_CA curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:${CERT_NAME}:redis_${CERTNAME_PREFIX}_chain_pem.txt >$TMP_CA
curl -s -H "X-Vault-Token: ${VAULT_TOKEN}" ${VAULT_URL}/${TEAM_NAME}/${CERT_NAME}/vault_${CERTNAME_PREFIX}_key | jq -j .data.value >$TMP_KEY curl -s -H "X-Vault-Token: ${VAULT_TOKEN}" ${VAULT_URL}/${TEAM_NAME}/${CERT_NAME}/vault_${CERTNAME_PREFIX}_key | jq -j .data.value >$TMP_KEY
else else
if [[ "$TEAM_NAME" == "puppet" ]]; then # TLD Wildcard if [[ "$TEAM_NAME" == "puppet" ]]; then # TLD Wildcard
curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:common:redis_${WILDCARD_CERTNAME_PREFIX}_pem.txt >$TMP_CERT curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:common:redis_${WILDCARD_CERTNAME_PREFIX}_pem.txt >$TMP_CERT
curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:common:redis_${WILDCARD_CERTNAME_PREFIX}_fullchain_pem.txt >$TMP_FULLCHAIN curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:common:redis_${WILDCARD_CERTNAME_PREFIX}_fullchain_pem.txt >$TMP_FULLCHAIN
curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:common:redis_${WILDCARD_CERTNAME_PREFIX}_chain_pem.txt >$TMP_CA curl -s -u redis:$REDIS_TOKEN ${REDIS_URL}/${TEAM_NAME}:common:redis_${WILDCARD_CERTNAME_PREFIX}_chain_pem.txt >$TMP_CA
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment