From 2ef30d6382781d525dd0e99822777b7012fc26b9 Mon Sep 17 00:00:00 2001 From: caskd Date: Mon, 6 May 2019 23:18:27 +0200 Subject: [PATCH] Refactor to use stdout instead of functions, remove pterodactyl plugin --- plugins/cloudflare/main.sh | 18 +++++++++--------- plugins/pterodactyl/main.sh | 30 ------------------------------ 2 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 plugins/pterodactyl/main.sh diff --git a/plugins/cloudflare/main.sh b/plugins/cloudflare/main.sh index 8e62202..70308a5 100644 --- a/plugins/cloudflare/main.sh +++ b/plugins/cloudflare/main.sh @@ -1,7 +1,7 @@ # Record name $3 -# Record type $4 -# Record content $5 (TODO default: own IP) -# Cloudflare Proxy $6 (true/false) +# Record type $4 (A) +# Record content $5 (own IP) +# Cloudflare Proxy $6 (true) if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \ -H "X-Auth-Email: ${EMAIL}" \ @@ -21,11 +21,11 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re ;; "set") if ! (containsElement "$3" "${DOMAIN[@]}"); then - if $(curl -sX POST "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \ + if (curl -sX POST "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \ -H "X-Auth-Email: ${EMAIL}" \ -H "X-Auth-Key: ${AUTH_KEY}" \ -H "Content-Type: application/json" \ - --data "{\"type\":\"${4}\",\"name\":\"${3}\",\"content\":\"${5}\",\"proxied\":"${6}"}" | jq -r '.success'); then + --data "{\"type\":\"${4:-A}\",\"name\":\"${3}\",\"content\":\"${5:-$(curl -sS https://api.ipify.org)}\",\"proxied\":"${6:-true}"}" > /dev/null 2>&1); then echo "done Registered entry successfully." else echo "erro Failed to add entry" @@ -33,11 +33,11 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re else for ((i=0;i<${#DOMAIN[@]};++i)); do if [[ "${DOMAIN[$i]}" = "$3" ]]; then - if $(curl -sX PUT "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records/$(echo "${FETCH}" | jq --compact-output -r "{(.result[$i].id): .result[$i].name}" | grep -oP "(?<=\{\")(.*)(?=\"\:\".*\"\})")" \ + if (curl -sX PUT "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records/$(echo "${FETCH}" | jq --compact-output -r "{(.result[$i].id): .result[$i].name}" | grep -oP "(?<=\{\")(.*)(?=\"\:\".*\"\})")" \ -H "X-Auth-Email: ${EMAIL}" \ -H "X-Auth-Key: ${AUTH_KEY}" \ -H "Content-Type: application/json" \ - --data "{\"type\":\"${4}\",\"name\":\"${3}\",\"content\":\"${5}\",\"proxied\":"${6}"}" | jq -r '.success'); then + --data "{\"type\":\"${4:-A}\",\"name\":\"${3}\",\"content\":\"${5:-$(curl -sS https://api.ipify.org)}\",\"proxied\":"${6:-true}"}" > /dev/null 2>&1); then echo "done Edited entry successfully." else echo "erro Failed to edit entry" @@ -50,10 +50,10 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re if (containsElement "$3" "${DOMAIN[@]}"); then for ((i=0;i<${#DOMAIN[@]};++i)); do if [[ "${DOMAIN[$i]}" = "$3" ]]; then - if $(curl -sX DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records/$(echo "${FETCH}" | jq --compact-output -r "{(.result[$i].id): .result[$i].name}" | grep -oP "(?<=\{\")(.*)(?=\"\:\".*\"\})")" \ + if (curl -sX DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records/$(echo "${FETCH}" | jq --compact-output -r "{(.result[$i].id): .result[$i].name}" | grep -oP "(?<=\{\")(.*)(?=\"\:\".*\"\})")" \ -H "X-Auth-Email: ${EMAIL}" \ -H "X-Auth-Key: ${AUTH_KEY}" \ - -H "Content-Type: application/json" | jq -r '.success'); then + -H "Content-Type: application/json" > /dev/null 2>&1); then echo "done Removed entry successfully." else echo "erro Failed to remove entry" diff --git a/plugins/pterodactyl/main.sh b/plugins/pterodactyl/main.sh deleted file mode 100644 index 83727d1..0000000 --- a/plugins/pterodactyl/main.sh +++ /dev/null @@ -1,30 +0,0 @@ -case "$2" in - "update") - cd /var/www/pterodactyl || exit - php artisan down - echo "info Fetching latest releases" - curl -L https://github.com/pterodactyl/panel/releases/download/"$(getlatest "Pterodactyl/panel")"/panel.tar.gz | tar --strip-components=1 -xzv - curl -L https://github.com/RXCommunity/RedXen-Panel/archive/"$(getlatest "RXCommunity/RedXen-Panel")".tar.gz | tar --strip-components=1 -xzv - echo "info Ensuring permissions are correct" - chown -R www-data:www-data ./* - chmod -R 755 storage/* bootstrap/cache - echo "info Getting latest deps" - composer install --no-dev --optimize-autoloader || echo "erro Failed to get deps!" - - artisanfunc=( - "view:clear" - "cache:clear" - "config:cache" - "migrate --force" - "db:seed --force" - "p:migration:clean-orphaned-keys -n" - "up" - ) - - echo "info Running migrations and clearance" - for f in "${artisanfunc[@]}"; do - php artisan $f || echo "erro Failed to execute 'artisan ${f}'" - done - ;; - *); echo "warn Nothing to do";; -esac