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
Branches
Tags
No related merge requests found
...@@ -7,15 +7,6 @@ ...@@ -7,15 +7,6 @@
# the certificate will be checked, if it is valid, if the key matches # the certificate will be checked, if it is valid, if the key matches
# and if it contains at least the cert-name # 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" REDIS_URL="https://redis.geant.org/GET"
VAULT_URL="https://vault.geant.org/v1" VAULT_URL="https://vault.geant.org/v1"
TMP_CERT=$(mktemp) TMP_CERT=$(mktemp)
...@@ -38,11 +29,35 @@ trap 'clean_up' SIGINT ...@@ -38,11 +29,35 @@ trap 'clean_up' SIGINT
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
echo -e "plase run this script as root\ngiving up..." echo -e "plase run this script as root\ngiving up..."
clean_up 2 clean_up 2
elif ! which curl jq &>/dev/null; then elif ! which jq &>/dev/null; then
echo -e "please install curl and jq\ngiving up..." 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 clean_up 2
fi 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 # lsb_release is not always installed
if ! source /etc/os-release &>/dev/null; then 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" 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 ...@@ -136,6 +151,9 @@ while true; do
--update) --update)
UPDATE='UPDATE' UPDATE='UPDATE'
;; ;;
--check-version)
CHECK='CHECK'
;;
--) --)
shift shift
break break
...@@ -146,6 +164,8 @@ done ...@@ -146,6 +164,8 @@ done
TYPE=$(echo $TYPE | tr '[:lower:]' '[:upper:]') TYPE=$(echo $TYPE | tr '[:lower:]' '[:upper:]')
check_version $0
if [ -n $UPDATE ]; then if [ -n $UPDATE ]; then
curl $SCRIPT_URL -o $0 curl $SCRIPT_URL -o $0
UPDATE_STATUS=$? UPDATE_STATUS=$?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment