Skip to content
Snippets Groups Projects
Unverified Commit e082f404 authored by Massimiliano Adamo's avatar Massimiliano Adamo
Browse files

add check version to shell script

parent a22892f4
No related branches found
No related tags found
No related merge requests found
......@@ -7,15 +7,6 @@
# the certificate will be checked, if it is valid, if the key matches
# and if it contains at least the cert-name
#
LOCAL_MD5=$(md5sum $0 | awk '{print $1}')
SCRIPT_URL="https://artifactory.software.geant.org/artifactory/acme-downloader/acme-downloader.sh"
REMOTE_MD5=$(curl -s $SCRIPT_URL | md5sum | awk '{print $1}')
if [[ $LOCAL_MD5 != $REMOTE_MD5 ]]; then
echo "$0 differs from $SCRIPT_URL"
echo "suggesting that you are running an older version"
echo ""
fi
REDIS_URL="https://redis.geant.org/GET"
VAULT_URL="https://vault.geant.org/v1"
TMP_CERT=$(mktemp)
......@@ -38,11 +29,35 @@ trap 'clean_up' SIGINT
if [ $(id -u) -ne 0 ]; then
echo -e "plase run this script as root\ngiving up..."
clean_up 2
elif ! which curl jq &>/dev/null; then
echo -e "please install curl and jq\ngiving up..."
elif ! which jq &>/dev/null; then
echo -e "please install jq\ngiving up..."
clean_up 2
elif ! which curl &>/dev/null; then
echo -e "please install curl\ngiving up..."
clean_up 2
fi
check_version() {
# check upstrem version
LOCAL_MD5=$(md5sum $1 | awk '{print $1}')
SCRIPT_URL="https://artifactory.software.geant.org/artifactory/acme-downloader/acme-downloader.sh"
METADATA_URL="https://artifactory.software.geant.org/artifactory/api/storage/acme-downloader/acme-downloader.sh"
REMOTE_MD5=$(curl -s $METADATA_URL | jq -j .checksums.md5)
if [[ $LOCAL_MD5 != $REMOTE_MD5 ]]; then
echo "$1 differs from $SCRIPT_URL"
echo "suggesting that you are running an older version"
echo "in order to fetch and install the new version you can use the option: --update"
echo ""
else
if [ -n $CHECK ]; then
echo "you are running the latest version"
fi
fi
if [ -n $CHECK ]; then
exit 0
fi
}
# lsb_release is not always installed
if ! source /etc/os-release &>/dev/null; then
echo "no idea what to do with this OS: I was not able to access /etc/os-release"
......@@ -136,6 +151,9 @@ while true; do
--update)
UPDATE='UPDATE'
;;
--check-version)
CHECK='CHECK'
;;
--)
shift
break
......@@ -146,6 +164,8 @@ done
TYPE=$(echo $TYPE | tr '[:lower:]' '[:upper:]')
check_version $0
if [ -n $UPDATE ]; then
curl $SCRIPT_URL -o $0
UPDATE_STATUS=$?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment