From 47efae4e6cc9062f899bc6b5e65d4489706d8063 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sun, 4 Apr 2021 15:40:09 +0200 Subject: [PATCH] Keep a fresh copy of apps.json Ref #132 --- abra | 58 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/abra b/abra index 4928bf3..f069a02 100755 --- a/abra +++ b/abra @@ -6,6 +6,7 @@ ABRA_VERSION="0.6.0" ABRA_BACKUP_DIR="${ABRA_BACKUP_DIR:-$ABRA_DIR/backups}" ABRA_VENDOR_DIR="$ABRA_DIR/vendor" YQ="$ABRA_VENDOR_DIR/yq" +ABRA_APPS_JSON="${ABRA_DIR}/apps.json" ####################################### # Global help @@ -434,7 +435,29 @@ require_consent_for_update() { fi } -require_plugin (){ +require_apps_json() { + # Ensure we have the latest copy of apps.json + apps_url="https://abra-apps.cloud.autonomic.zone" + if [ -f "$ABRA_APPS_JSON" ]; then + modified=$(curl --silent --head $apps_url | \ + awk '/^Last-Modified/{print $0}' | \ + sed 's/^Last-Modified: //') + remote_ctime=$(date --date="$modified" +%s) + local_ctime=$(stat -c %Z "$ABRA_APPS_JSON") + + if [ "$local_ctime" -lt "$remote_ctime" ]; then + info "Downloading new apps.json" + wget -qO "$ABRA_APPS_JSON" $apps_url + else + debug "No apps.json update needed" + fi + else + info "Downloading apps.json" + wget -qO "$ABRA_APPS_JSON" $apps_url + fi +} + +require_plugin() { PLUGIN="$1" BRANCH="${abra___branch:-master}" @@ -501,32 +524,42 @@ require_app_latest() { fi } -require_yq() { +vendor_binary() { require_vendor_dir require_binary wget - YQ_VERSION="4.6.1" - YQ_BINARY="yq_linux_amd64" - YQ_RELEASE_URL="https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/${YQ_BINARY}" + local REPO="$1" + local VERSION="$2" + local FILE="$3" + local BINARY="${REPO##*/}" + local RELEASE_URL="$REPO/releases/download/${VERSION}/${FILE}" - if [ -f "$YQ" ]; then - debug "yq is already vendored" + if [ -f "$ABRA_DIR/vendor/$BINARY" ]; then + debug "$BINARY is already vendored" return fi case $(uname -m) in x86_64) - warning "Attempting to download the yq binary into $ABRA_VENDOR_DIR" - wget -q "$YQ_RELEASE_URL" && chmod +x "$YQ_BINARY" && mv "$YQ_BINARY" "$YQ" - success "yq is now vendored ☮" + warning "Attempting to download the $BINARY binary from $RELEASE_URL into $ABRA_VENDOR_DIR" + wget -qO "$ABRA_VENDOR_DIR/$BINARY" "$RELEASE_URL" && chmod +x "$ABRA_VENDOR_DIR/$BINARY" + success "$BINARY is now vendored ☮" ;; *) - error "Unable to automatically vendor yq, you'll have to manually manage this\n - Please see https://mikefarah.gitbook.io/yq/#install and place the yq binary in the $YQ path" + error "Unable to automatically vendor $BINARY, you'll have to manually manage this.\n + Please see $REPO and place the $BINARY binary in $ABRA_VENDOR_DIR." ;; esac } +require_jq() { + vendor_binary "https://github.com/stedolan/jq/" "jq-1.6" "jq-linux64" +} + +require_yq() { + vendor_binary "https://github.com/mikefarah/yq" "v4.6.1" "yq_linux_amd64" +} + require_docker_version (){ get_servers @@ -2039,6 +2072,7 @@ abra() { if [ -n "$abra__app_" ]; then load_instance load_instance_env + require_apps_json fi load_abra_sh