Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Acme Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Geant DevOps
Acme Downloader
Commits
18d5b4e6
Unverified
Commit
18d5b4e6
authored
2 years ago
by
Max Adamo
Browse files
Options
Downloads
Patches
Plain Diff
added crontab installation option
parent
ec2ee9e1
No related branches found
No related tags found
No related merge requests found
Pipeline
#77328
passed
2 years ago
Stage: sonarqube
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
acme-downloader.sh
+48
-3
48 additions, 3 deletions
acme-downloader.sh
with
48 additions
and
3 deletions
acme-downloader.sh
+
48
−
3
View file @
18d5b4e6
...
...
@@ -84,7 +84,7 @@ fi
usage
()
{
echo
"Usage:
$(
basename
$0
)
"
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
" --cert-name (Certificate name)"
echo
" --team-name (Team name: swd, it, neteng, nmaas ...)"
...
...
@@ -102,7 +102,7 @@ usage() {
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
"
while
true
;
do
...
...
@@ -159,6 +159,9 @@ while true; do
--force-update
)
FORCE_UPDATE
=
'FORCE_UPDATE'
;;
--install-crontab
)
INSTALL_CRONTAB
=
'INSTALL_CRONTAB'
;;
--check-version
)
CHECK
=
'CHECK'
;;
...
...
@@ -179,6 +182,48 @@ if [[ -n $PARAM_VERSION ]]; then
clean_up 0
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_version
VERSION_STATUS
=
$?
...
...
@@ -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
-H
"X-Vault-Token:
${
VAULT_TOKEN
}
"
${
VAULT_URL
}
/
${
TEAM_NAME
}
/
${
CERT_NAME
}
/vault_
${
CERTNAME_PREFIX
}
_key | jq
-j
.data.value
>
$TMP_KEY
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
}
_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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment