Reformated output methods and added more logging, changed standard spacing to 2 spaces
This commit is contained in:
parent
95cbc10033
commit
32b156de81
60
manager
60
manager
|
@ -23,17 +23,23 @@ COLOR=(
|
||||||
|
|
||||||
if ${DEV}; then
|
if ${DEV}; then
|
||||||
function output () {
|
function output () {
|
||||||
declare input="${*:2}";
|
while read LINE; do
|
||||||
echo -e "${COLOR[$1]}$(date +%F\ %T\ %z) | ${1} | ${input}${COLOR[nc]}"
|
if [[ ${LINE%% *} =~ ^erro|done|info|warn$ ]]; then
|
||||||
|
echo -e "${COLOR[${LINE%% *}]}$(date +%F\ %T\ %z) | ${LINE%% *} | ${LINE#* }${COLOR[nc]}"
|
||||||
|
else
|
||||||
|
echo -e "${COLOR[nc]}$(date +%F\ %T\ %z) | ${LINE}${COLOR[nc]}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
function xt () {
|
function xt () {
|
||||||
output "$1" "Set return code to $2"
|
echo "$1 Set return code to $2"
|
||||||
return "$2"
|
return "$2"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
function output () {
|
function output () {
|
||||||
declare input=${*:2};
|
while read LINE; do
|
||||||
echo -e "${COLOR[$1]}${input}${COLOR[nc]}"
|
echo -e "${COLOR[${LINE%% *}]}${LINE#* }${COLOR[nc]}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
function xt () {
|
function xt () {
|
||||||
return "$2"
|
return "$2"
|
||||||
|
@ -46,14 +52,15 @@ function main () {
|
||||||
export CWDIR=${DIR}/plugins/${1}
|
export CWDIR=${DIR}/plugins/${1}
|
||||||
if (containsElement "$1" "${plugins[@]}"); then
|
if (containsElement "$1" "${plugins[@]}"); then
|
||||||
if [ "$2" = "help" ]; then
|
if [ "$2" = "help" ]; then
|
||||||
output "info" "$1"
|
echo "info $1"
|
||||||
else
|
else
|
||||||
source "${DIR}/plugins/${1}/main.sh"
|
[ -f "${CWDIR}/.env" ] && source "${CWDIR}/.env"
|
||||||
|
source "${CWDIR}/main.sh"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output "erro" "Plugin $1 not found."
|
echo "erro Plugin $1 not found."
|
||||||
avail-plugins
|
avail-plugins
|
||||||
output "info" "Tip: If you added the plugin recently, add it to the index with '${0##*/} index'"
|
echo "info Tip: If you added the plugin recently, add it to the index with '${0##*/} index'"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,58 +72,58 @@ function containsElement () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function nopluginlist {
|
function nopluginlist {
|
||||||
output "warn" "No plugin list found. Try running '${0##*/} index' to index everything."
|
echo "warn No plugin list found. Try running '${0##*/} index' to index everything."
|
||||||
}
|
}
|
||||||
|
|
||||||
function avail-plugins {
|
function avail-plugins {
|
||||||
if [ -f "${PLIST}" ]; then
|
if [ -f "${PLIST}" ]; then
|
||||||
output "warn" "Available plugins:"
|
echo "warn Available plugins:"
|
||||||
mapfile -t plugins < "${PLIST}" || output "erro" "Failed to load plugin list."
|
mapfile -t plugins < "${PLIST}" || echo "erro Failed to load plugin list."
|
||||||
output "warn" "${plugins[@]}"
|
echo "warn ${plugins[@]}"
|
||||||
else
|
else
|
||||||
nopluginlist
|
nopluginlist
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function index {
|
function index {
|
||||||
output "info" "Indexing plugins"
|
echo "info Indexing plugins"
|
||||||
truncate -s 0 "${PLIST}"
|
truncate -s 0 "${PLIST}"
|
||||||
for i in $(find "${DIR}"/plugins/* -type d | grep -P "(?<=\/plugins\/)([\w\d\-\_])*" -o); do
|
for i in $(find "${DIR}"/plugins/* -type d | grep -P "(?<=\/plugins\/)([\w\d\-\_])*" -o); do
|
||||||
echo "$i" >> "${PLIST}" && output "done" "Added plugin '$i'."
|
echo "$i" >> "${PLIST}" && echo "done Added plugin '$i'."
|
||||||
done
|
done
|
||||||
output "info" "Indexing extensions"
|
echo "info Indexing extensions"
|
||||||
truncate -s 0 "${ELIST}"
|
truncate -s 0 "${ELIST}"
|
||||||
for i in $(find "${DIR}"/extensions/* -type f | grep -P "(?<=\/extensions\/)([\w\d\-\_])*(\.func)" -o); do
|
for i in $(find "${DIR}"/extensions/* -type f | grep -P "(?<=\/extensions\/)([\w\d\-\_])*(\.func)" -o); do
|
||||||
echo "$i" >> "${ELIST}" && output "done" "Added extension '$i'."
|
echo "$i" >> "${ELIST}" && echo "done Added extension '$i'."
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadlists {
|
function loadlists {
|
||||||
mapfile -t plugins < "${PLIST}" || output "erro" "Failed to load plugin list."
|
mapfile -t plugins < "${PLIST}" || echo "erro Failed to load plugin list."
|
||||||
mapfile -t extensions < "${ELIST}" || output "erro" "Failed to load extension list."
|
mapfile -t extensions < "${ELIST}" || echo "erro Failed to load extension list."
|
||||||
for i in "${extensions[@]}"; do
|
for i in "${extensions[@]}"; do
|
||||||
source "${DIR}/extensions/$i" || output "warn" "Failed to import extension ${i}."
|
source "${DIR}/extensions/$i" || echo "warn Failed to import extension ${i}."
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function preparedirs {
|
function preparedirs {
|
||||||
if mkdir "${DIR}"/plugins/ "${DIR}"/extensions/; then
|
if mkdir "${DIR}"/plugins/ "${DIR}"/extensions/; then
|
||||||
output "info" "Created a empty plugins and extensions directory."
|
echo "info Created a empty plugins and extensions directory."
|
||||||
else
|
else
|
||||||
output "err" "Could not create directory."
|
echo "erro Could not create directory."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## Main run
|
## Main run
|
||||||
|
|
||||||
[ ${DEV} = "true" ] && output "warn" "Running in development mode!"
|
(
|
||||||
|
[ ${DEV} = "true" ] && echo "warn Running in development mode!"
|
||||||
if ! [ $# -eq 0 ] && ! [[ "$1" = "index" ]] && [ -f "${PLIST}" ] && [ -f "${ELIST}" ]; then
|
if ! [ $# -eq 0 ] && ! [[ "$1" = "index" ]] && [ -f "${PLIST}" ] && [ -f "${ELIST}" ]; then
|
||||||
loadlists
|
loadlists
|
||||||
main "$@"
|
main "$@"
|
||||||
elif [ -d "${DIR}"/plugins/ ] && [ -d "${DIR}"/extensions/ ]; then
|
elif [ -d "${DIR}"/plugins/ ] && [ -d "${DIR}"/extensions/ ]; then
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
output "warn" "Nothing to do!"
|
echo "warn Nothing to do!"
|
||||||
avail-plugins
|
avail-plugins
|
||||||
elif [[ "$1" = "index" ]]; then
|
elif [[ "$1" = "index" ]]; then
|
||||||
index
|
index
|
||||||
|
@ -126,4 +133,5 @@ elif [ -d "${DIR}"/plugins/ ] && [ -d "${DIR}"/extensions/ ]; then
|
||||||
else
|
else
|
||||||
preparedirs
|
preparedirs
|
||||||
fi
|
fi
|
||||||
! [[ "$1" = "rawpl" ]] && output "done" "Made with ♥ by casKd | t.me/casKd_dev"
|
! [[ "$1" = "rawpl" ]] && echo "info Made with ♥ by casKd | t.me/casKd_dev"
|
||||||
|
) | output
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
source "${CWDIR}/.env"
|
|
||||||
|
|
||||||
# MariaDB / MySQL
|
# MariaDB / MySQL
|
||||||
output info "Backing up MariaDB"
|
echo "info Backing up MariaDB"
|
||||||
mysqldump -h "${MSQL_HOST}" -P"${MSQL_PORT}" -u"${MSQL_USER}" -p"${MSQL_PASS}" -ARE | gzip -c > "${MSQL_PATH}"/mariadb-$(date +%s).sql.gz || output erro "Failed to backup MariaDB"
|
mysqldump -h "${MSQL_HOST}" -P"${MSQL_PORT}" -u"${MSQL_USER}" -p"${MSQL_PASS}" -ARE | gzip -c > "${MSQL_PATH}"/mariadb-$(date +%s).sql.gz || echo "erro Failed to backup MariaDB"
|
||||||
|
|
||||||
# Postgres (Docker)
|
# Postgres (Docker)
|
||||||
output info "Backing up PostgreSQL"
|
echo "info Backing up PostgreSQL"
|
||||||
docker exec main-db_postgres_1 pg_dumpall -U "${PSQL_USER}" | gzip -c > "${PSQL_PATH}"/postgres-$(date +%s).sql.gz || output erro "Failed to backup PostgreSQL"
|
docker exec main-db_postgres_1 pg_dumpall -U "${PSQL_USER}" | gzip -c > "${PSQL_PATH}"/postgres-$(date +%s).sql.gz || echo "erro Failed to backup PostgreSQL"
|
||||||
|
|
||||||
# InfluxDB (Docker)
|
# InfluxDB (Docker)
|
||||||
# output info "Backing up InfluxDB"
|
# echo "info Backing up InfluxDB"
|
||||||
# docker exec main-db_influxdb_1 bash -c "influxd backup -portable -database telegraf /backups > /dev/null 2>&1 && tar -cz /backups" > "${IFXDB_PATH}"/influxdb-telegraf-$(date +%s).tar.gz || output erro "Failed to backup InfluxDB"
|
# docker exec main-db_influxdb_1 bash -c "influxd backup -portable -database telegraf /backups > /dev/null 2>&1 && tar -cz /backups" > "${IFXDB_PATH}"/influxdb-telegraf-$(date +%s).tar.gz || echo "erro Failed to backup InfluxDB"
|
||||||
|
|
||||||
# Backup maintenance
|
# Backup maintenance
|
||||||
output info "Removing older backups"
|
echo "info Removing older backups"
|
||||||
find /root/main-db/backups/* -type f -ctime +${BR_DAYS} -exec rm -rf {} \;
|
find /root/main-db/backups/* -type f -ctime +${BR_DAYS} -exec rm -rf {} \;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
source "${CWDIR}/.env"
|
|
||||||
|
|
||||||
# Record name $3
|
# Record name $3
|
||||||
# Record type $4
|
# Record type $4
|
||||||
# Record content $5 (default: own IP)
|
# Record content $5 (TODO default: own IP)
|
||||||
# Cloudflare Proxy $6 (true/false)
|
# Cloudflare Proxy $6 (true/false)
|
||||||
|
|
||||||
if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \
|
if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \
|
||||||
|
@ -13,7 +11,12 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"list")
|
"list")
|
||||||
for ((i=0;i<${#DOMAIN[@]};++i)); do
|
for ((i=0;i<${#DOMAIN[@]};++i)); do
|
||||||
echo "$(echo "${FETCH}" | jq -r ".result[${i}].name") $(echo "${FETCH}" | jq -r ".result[${i}].type") $(echo "${FETCH}" | jq -r ".result[${i}].content") $(echo "${FETCH}" | jq -r ".result[${i}].id")" | output info $(</dev/stdin)
|
echo "info ----------------------------------------------------------"
|
||||||
|
echo "info Record name: $(echo "${FETCH}" | jq -r ".result[${i}].name")"
|
||||||
|
echo "info Record type: $(echo "${FETCH}" | jq -r ".result[${i}].type")"
|
||||||
|
echo "info Record cont: $(echo "${FETCH}" | jq -r ".result[${i}].content")"
|
||||||
|
echo "info Record iden: $(echo "${FETCH}" | jq -r ".result[${i}].id")"
|
||||||
|
echo "info ----------------------------------------------------------"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
"set")
|
"set")
|
||||||
|
@ -23,9 +26,9 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re
|
||||||
-H "X-Auth-Key: ${AUTH_KEY}" \
|
-H "X-Auth-Key: ${AUTH_KEY}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data "{\"type\":\"${4}\",\"name\":\"${3}\",\"content\":\"${5}\",\"proxied\":"${6}"}" | jq -r '.success'); then
|
--data "{\"type\":\"${4}\",\"name\":\"${3}\",\"content\":\"${5}\",\"proxied\":"${6}"}" | jq -r '.success'); then
|
||||||
output done "Registered entry successfully."
|
echo "done Registered entry successfully."
|
||||||
else
|
else
|
||||||
output erro "Failed to add entry"
|
echo "erro Failed to add entry"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
for ((i=0;i<${#DOMAIN[@]};++i)); do
|
for ((i=0;i<${#DOMAIN[@]};++i)); do
|
||||||
|
@ -35,9 +38,9 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re
|
||||||
-H "X-Auth-Key: ${AUTH_KEY}" \
|
-H "X-Auth-Key: ${AUTH_KEY}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data "{\"type\":\"${4}\",\"name\":\"${3}\",\"content\":\"${5}\",\"proxied\":"${6}"}" | jq -r '.success'); then
|
--data "{\"type\":\"${4}\",\"name\":\"${3}\",\"content\":\"${5}\",\"proxied\":"${6}"}" | jq -r '.success'); then
|
||||||
output done "Edited entry successfully."
|
echo "done Edited entry successfully."
|
||||||
else
|
else
|
||||||
output erro "Failed to edit entry"
|
echo "erro Failed to edit entry"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -51,14 +54,14 @@ if FETCH=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_re
|
||||||
-H "X-Auth-Email: ${EMAIL}" \
|
-H "X-Auth-Email: ${EMAIL}" \
|
||||||
-H "X-Auth-Key: ${AUTH_KEY}" \
|
-H "X-Auth-Key: ${AUTH_KEY}" \
|
||||||
-H "Content-Type: application/json" | jq -r '.success'); then
|
-H "Content-Type: application/json" | jq -r '.success'); then
|
||||||
output done "Removed entry successfully."
|
echo "done Removed entry successfully."
|
||||||
else
|
else
|
||||||
output erro "Failed to remove entry"
|
echo "erro Failed to remove entry"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
output warn "Entry ${3} does not exist."
|
echo "warn Entry ${3} does not exist."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
dockercont=$(docker ps) || xt "erro" "1" && exit
|
dockerstatus=$(systemctl status | grep -c docker) || xt "erro" "1" && exit
|
||||||
dockerstatus=$(systemctl status | grep -c docker)
|
dockercont=$(docker ps)
|
||||||
mapfile -t containers < "${CWDIR}"/containers.list
|
mapfile -t containers < "${CWDIR}"/containers.list
|
||||||
for i in "${containers[@]}"; do
|
for i in "${containers[@]}"; do
|
||||||
if (( "${dockerstatus}" > 0 )); then
|
if (( "${dockerstatus}" > 0 )); then
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"start")
|
"start")
|
||||||
if (( $(echo "${dockercont}" | grep -c "$i") > 0 )); then
|
if (( $(echo "${dockercont}" | grep -c "$i") > 0 )); then
|
||||||
output warn "Container $i was already up and running!"
|
output "warn Container $i was already up and running!"
|
||||||
else
|
else
|
||||||
if (docker start "$i" > /dev/null 2>&1); then
|
if (docker start "$i" > /dev/null 2>&1); then
|
||||||
output done "Started container $i succesfully!"
|
output "done Started container $i succesfully!"
|
||||||
else
|
else
|
||||||
output erro "Failed to start container $i!"
|
output "erro Failed to start container $i!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"stop")
|
"stop")
|
||||||
if (( $(echo "${dockercont}" | grep -c "$i") > 0 )); then
|
if (( $(echo "${dockercont}" | grep -c "$i") > 0 )); then
|
||||||
if (docker stop --time=20 "$i" > /dev/null 2>&1); then
|
if (docker stop --time=20 "$i" > /dev/null 2>&1); then
|
||||||
output done "Stopped container $i succesfully!"
|
output "done Stopped container $i succesfully!"
|
||||||
else
|
else
|
||||||
output erro "Failed to stop container $i!"
|
output "erro Failed to stop container $i!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output warn "Container $i was already stopped!"
|
output "warn Container $i was already stopped!"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"status")
|
"status")
|
||||||
if (( $(echo "${dockercont}" | grep -c "$i") > 0 )); then
|
if (( $(echo "${dockercont}" | grep -c "$i") > 0 )); then
|
||||||
output warn "Container $i is up and running!"
|
output "warn Container $i is up and running!"
|
||||||
else
|
else
|
||||||
output erro "Container $i is stopped!"
|
output "erro Container $i is stopped!"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
elif (systemctl -q is-active docker); then
|
elif (systemctl -q is-active docker); then
|
||||||
output erro "An error has occured, we are sorry!"
|
output "erro An error has occured, we are sorry!"
|
||||||
else
|
else
|
||||||
output erro "Docker is stopped, cannot perform check!"
|
output "erro Docker is stopped, cannot perform check!"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
if [ -x "$(command -v docker)" ]; then
|
if [ -x "$(command -v docker)" ]; then
|
||||||
output info "Clearing Docker remainings"
|
output "info Clearing Docker remainings"
|
||||||
docker system prune --all -f
|
docker system prune --all -f
|
||||||
fi
|
fi
|
||||||
case $(uname -rv) in
|
case $(uname -rv) in
|
||||||
*Ubuntu*)
|
*Ubuntu*)
|
||||||
output info "Clearing & Updating APT"
|
output "info Clearing & Updating APT"
|
||||||
apt-get -y update
|
apt-get -y update
|
||||||
apt-get -y autoclean
|
apt-get -y autoclean
|
||||||
apt-get -y autoremove
|
apt-get -y autoremove
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
output info "Clearing logs"
|
output "info Clearing logs"
|
||||||
if [ -x "$(command -v nginx)" ]; then
|
if [ -x "$(command -v nginx)" ]; then
|
||||||
truncate -s 0 /var/log/nginx/*.*
|
truncate -s 0 "${LOGPATH:-/var/log/nginx/*.*}"
|
||||||
fi
|
fi
|
||||||
journalctl --vacuum-size=20M
|
journalctl --vacuum-size=20M
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"update")
|
"update")
|
||||||
cd /var/www/pterodactyl || exit
|
cd /var/www/pterodactyl || exit
|
||||||
php artisan down
|
php artisan down
|
||||||
output info "Fetching latest releases"
|
output "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/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
|
curl -L https://github.com/RXCommunity/RedXen-Panel/archive/"$(getlatest "RXCommunity/RedXen-Panel")".tar.gz | tar --strip-components=1 -xzv
|
||||||
output info "Ensuring permissions are correct"
|
output "info Ensuring permissions are correct"
|
||||||
chown -R www-data:www-data ./*
|
chown -R www-data:www-data ./*
|
||||||
chmod -R 755 storage/* bootstrap/cache
|
chmod -R 755 storage/* bootstrap/cache
|
||||||
output info "Getting latest deps"
|
output "info Getting latest deps"
|
||||||
composer install --no-dev --optimize-autoloader || output erro "Failed to get deps!"
|
composer install --no-dev --optimize-autoloader || output "erro Failed to get deps!"
|
||||||
|
|
||||||
artisanfunc=(
|
artisanfunc=(
|
||||||
"view:clear"
|
"view:clear"
|
||||||
"cache:clear"
|
"cache:clear"
|
||||||
"config:cache"
|
"config:cache"
|
||||||
"migrate --force"
|
"migrate --force"
|
||||||
"db:seed --force"
|
"db:seed --force"
|
||||||
"p:migration:clean-orphaned-keys -n"
|
"p:migration:clean-orphaned-keys -n"
|
||||||
"up"
|
"up"
|
||||||
)
|
)
|
||||||
|
|
||||||
output info "Running migrations and clearance"
|
output "info Running migrations and clearance"
|
||||||
for f in "${artisanfunc[@]}"; do
|
for f in "${artisanfunc[@]}"; do
|
||||||
php artisan $f || output erro "Failed to execute 'artisan ${f}'"
|
php artisan $f || output "erro Failed to execute 'artisan ${f}'"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
*); echo "Nothing to do";;
|
*); echo "Nothing to do";;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
source "${CWDIR}/.env"
|
|
||||||
|
|
||||||
function join { local IFS="$1"; shift; echo "$*"; }
|
function join { local IFS="$1"; shift; echo "$*"; }
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
output "info" "Getting addresses"
|
echo "info Getting addresses"
|
||||||
ipv4=$(curl https://www.cloudflare.com/ips-v4) || output erro "Failed to get IPv4 addresses"
|
ipv4=$(curl -sS https://www.cloudflare.com/ips-v4) || echo "erro Failed to get IPv4 addresses"
|
||||||
ipv6=$(curl https://www.cloudflare.com/ips-v6) || output erro "Failed to get IPv6 addresses"
|
ipv6=$(curl -sS https://www.cloudflare.com/ips-v6) || echo "erro Failed to get IPv6 addresses"
|
||||||
ip=("${ipv4[@]}" "${ipv6[@]}")
|
ip=("${ipv4[@]}" "${ipv6[@]}")
|
||||||
output "info" "Truncating existing list"
|
echo "info Truncating existing list"
|
||||||
truncate -s 0 $FILE
|
truncate -s 0 $FILE
|
||||||
output "info" "Writing new IPs to the list"
|
echo "info Writing new IPs to the list"
|
||||||
for i in ${ip[@]}; do
|
for i in ${ip[@]}; do
|
||||||
echo "set_real_ip_from ${i};" >> $FILE
|
echo "set_real_ip_from ${i};" >> $FILE
|
||||||
done
|
done
|
||||||
echo "real_ip_header X-Forwarded-For;" >> $FILE
|
echo "real_ip_header X-Forwarded-For;" >> $FILE
|
||||||
output "info" "Reloading nginx"
|
echo "info Reloading nginx"
|
||||||
nginx -t && nginx -s reload || echo "Failed to reload nginx" | output erro
|
nginx -s reload || echo "erro Failed to reload nginx"
|
||||||
output "info" "Updating DigitalOcean Firewall(s)"
|
echo "info Updating DigitalOcean Firewall(s)"
|
||||||
DOLIST=()
|
DOLIST=()
|
||||||
DLETS=()
|
DLETS=()
|
||||||
for i in ${ip[@]}; do
|
for i in ${ip[@]}; do
|
||||||
DOLIST+=(address:${i})
|
DOLIST+=(address:${i})
|
||||||
done
|
done
|
||||||
snap run doctl compute firewall update ${FWID} --name ${NAME} --droplet-ids $(join , ${DROPLETS[@]}) --inbound-rules protocol:tcp,ports:443,$(join , ${DOLIST[@]})
|
if (snap run doctl compute firewall update ${FWID} --name ${NAME} --droplet-ids $(join , ${DROPLETS[@]}) --inbound-rules protocol:tcp,ports:443,$(join , ${DOLIST[@]}) > /dev/null 2>&1); then
|
||||||
|
echo "done Updated firewall(s) successfully"
|
||||||
|
else
|
||||||
|
echo "erro Failed to update firewalls via doctl"
|
||||||
|
fi
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
if [ -x "$(command -v git)" ]; then
|
|
||||||
cd "${DIR}" || exit
|
|
||||||
output info "Self-updating:"
|
|
||||||
if (git diff --name-only origin/master | grep -q manager); then
|
|
||||||
git reset --hard HEAD | output info
|
|
||||||
git pull https://github.com/RXCommunity/manager master | output info
|
|
||||||
else
|
|
||||||
output info "Already latest version!"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
output erro "You do not have GIT installed!"
|
|
||||||
fi
|
|
|
@ -1,35 +1,35 @@
|
||||||
servicelist=$(systemctl list-units --type=service --state=active | grep -oe ".*\.service")
|
servicelist=$(systemctl list-units --type=service --state=active | grep -oe ".*\.service")
|
||||||
mapfile -t services < ${CWDIR}/services.list
|
mapfile -t services < ${CWDIR}/services.list
|
||||||
for i in "${services[@]}"; do
|
for i in "${services[@]}"; do
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"start")
|
"start")
|
||||||
if (( $(echo "${servicelist}" | grep -c "$i") > 0 )); then
|
if (( $(echo "${servicelist}" | grep -c "$i") > 0 )); then
|
||||||
output warn "Service $i was already running!"
|
echo "warn Service $i was already running!"
|
||||||
else
|
else
|
||||||
if (systemctl start "$i" > /dev/null 2>&1); then
|
if (systemctl start "$i" > /dev/null 2>&1); then
|
||||||
output done "Started service $i succesfully!"
|
echo "done Started service $i succesfully!"
|
||||||
else
|
else
|
||||||
output erro "Failed to start service $i!"
|
echo "erro Failed to start service $i!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"stop")
|
"stop")
|
||||||
if (( $(echo "${servicelist}" | grep -c "$i") > 0 )); then
|
if (( $(echo "${servicelist}" | grep -c "$i") > 0 )); then
|
||||||
if (systemctl stop "$i" > /dev/null 2>&1); then
|
if (systemctl stop "$i" > /dev/null 2>&1); then
|
||||||
output done "Stopped service $i succesfully!"
|
echo "done Stopped service $i succesfully!"
|
||||||
else
|
else
|
||||||
output erro "Failed to stop service $i!"
|
echo "erro Failed to stop service $i!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output warn "Service $i is already stopped!"
|
echo "warn Service $i is already stopped!"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"status")
|
"status")
|
||||||
if (( $(echo "${servicelist}" | grep -c "$i") > 0 )); then
|
if (( $(echo "${servicelist}" | grep -c "$i") > 0 )); then
|
||||||
output warn "Service $i is up and running!"
|
echo "warn Service $i is up and running!"
|
||||||
else
|
else
|
||||||
output erro "Service $i is stopped!"
|
echo "erro Service $i is stopped!"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
|
# TODO: More variables and push statsh if encountering problems
|
||||||
|
|
||||||
cd /root/yagpdb || exit
|
cd /root/yagpdb || exit
|
||||||
|
echo "info Getting latest version"
|
||||||
git pull
|
git pull
|
||||||
cd ./yagpdb_docker || exit
|
cd ./yagpdb_docker || exit
|
||||||
|
echo "info Building latest version"
|
||||||
docker-compose build --force-rm --no-cache --pull
|
docker-compose build --force-rm --no-cache --pull
|
||||||
|
echo "info Starting bot"
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
|
Reference in New Issue