Refactor entrypoint script for improved readability and add upgrade functionality
This commit is contained in:
@@ -163,7 +163,6 @@ get_repositories() {
|
|||||||
local TREES=""
|
local TREES=""
|
||||||
local REPO
|
local REPO
|
||||||
|
|
||||||
|
|
||||||
REPOS=$(jq -r .repositories[] /etc/user/config/repositories.json) # list of repos, delimiter by space
|
REPOS=$(jq -r .repositories[] /etc/user/config/repositories.json) # list of repos, delimiter by space
|
||||||
for REPO in $REPOS; do
|
for REPO in $REPOS; do
|
||||||
|
|
||||||
@@ -434,12 +433,13 @@ check_update() {
|
|||||||
|
|
||||||
CURL_CHECK="curl -m 5 -s -o /dev/null -w "%{http_code}" https://$REPOSITORY_URL/v2/"
|
CURL_CHECK="curl -m 5 -s -o /dev/null -w "%{http_code}" https://$REPOSITORY_URL/v2/"
|
||||||
CURL_CHECK_CODE=$(eval $CURL_CHECK)
|
CURL_CHECK_CODE=$(eval $CURL_CHECK)
|
||||||
if [[ "$CURL_CHECK_CODE" == "200" ]]; then
|
|
||||||
|
if [[ "$CURL_CHECK_CODE" == "200" ]] || [[ "$(echo "$REPOSITORY_URL" | grep '\.')" == "" ]]; then
|
||||||
debug "$REPOSITORY_URL accessed successful"
|
debug "$REPOSITORY_URL accessed successful"
|
||||||
|
|
||||||
# if repository url is not set
|
# if repository url is not set
|
||||||
if [[ "$(echo "$REPOSITORY_URL" | grep '\.')" == "" ]]; then
|
if [[ "$(echo "$REPOSITORY_URL" | grep '\.')" == "" ]]; then
|
||||||
REPOSITORY_URL="docker.io"
|
REPOSITORY_URL="hub.docker.com"
|
||||||
TEMP_PATH=$IMAGE
|
TEMP_PATH=$IMAGE
|
||||||
else
|
else
|
||||||
# -f2- IMAGE can contain subdirectories
|
# -f2- IMAGE can contain subdirectories
|
||||||
@@ -784,7 +784,7 @@ execute_task() {
|
|||||||
|
|
||||||
elif [ "$TASK_NAME" == "save_vpn" ]; then
|
elif [ "$TASK_NAME" == "save_vpn" ]; then
|
||||||
|
|
||||||
VPN_PROXY_REPO="wireguard-proxy-client";
|
VPN_PROXY_REPO="wireguard-proxy-client"
|
||||||
if [ ! -d "/tmp/$VPN_PROXY_REPO" ]; then
|
if [ ! -d "/tmp/$VPN_PROXY_REPO" ]; then
|
||||||
git clone https://git.format.hu/safebox/$VPN_PROXY_REPO.git /tmp/$VPN_PROXY_REPO >/dev/null
|
git clone https://git.format.hu/safebox/$VPN_PROXY_REPO.git /tmp/$VPN_PROXY_REPO >/dev/null
|
||||||
else
|
else
|
||||||
@@ -795,8 +795,8 @@ execute_task() {
|
|||||||
cp -av /tmp/$VPN_PROXY_REPO/*.json $SERVICE_DIR/
|
cp -av /tmp/$VPN_PROXY_REPO/*.json $SERVICE_DIR/
|
||||||
|
|
||||||
VPN_VOLUMES=$(jq -r .containers[0].VOLUMES[0].SOURCE $SERVICE_DIR/vpn-proxy.json)
|
VPN_VOLUMES=$(jq -r .containers[0].VOLUMES[0].SOURCE $SERVICE_DIR/vpn-proxy.json)
|
||||||
VOLUME=$(dirname $VPN_VOLUMES);
|
VOLUME=$(dirname $VPN_VOLUMES)
|
||||||
mkdir -p $VOLUME;
|
mkdir -p $VOLUME
|
||||||
|
|
||||||
# install vpn only
|
# install vpn only
|
||||||
sh /scripts/install.sh "$B64_JSON" "$service_exec" "vpn" "$GLOBAL_VERSION"
|
sh /scripts/install.sh "$B64_JSON" "$service_exec" "vpn" "$GLOBAL_VERSION"
|
||||||
@@ -807,7 +807,12 @@ execute_task() {
|
|||||||
CONTAINERS=$(docker ps -a --format '{{.Names}} {{.Status}}' | grep -v framework-scheduler)
|
CONTAINERS=$(docker ps -a --format '{{.Names}} {{.Status}}' | grep -v framework-scheduler)
|
||||||
RESULT=$(echo "$CONTAINERS" | base64 -w0)
|
RESULT=$(echo "$CONTAINERS" | base64 -w0)
|
||||||
JSON_TARGET=$(echo '{ "DATE": "'$DATE'", "RESULT": "'$RESULT'" }' | jq -r . | base64 -w0)
|
JSON_TARGET=$(echo '{ "DATE": "'$DATE'", "RESULT": "'$RESULT'" }' | jq -r . | base64 -w0)
|
||||||
|
elif [ "$TASK_NAME" == "upgrade" ]; then
|
||||||
|
JSON_TARGET=$(echo '{ "DATE": "'$DATE'", "UPGRADE_STATUS": "0" }' | jq -r . | base64 -w0) # install has started
|
||||||
|
install -m 664 -g 65534 /dev/null $SHARED/output/$TASK.json
|
||||||
|
echo $JSON_TARGET | base64 -d >$SHARED/output/$TASK.json
|
||||||
|
sh /scripts/upgrade.sh "$B64_JSON" "$service_exec" "true" "$GLOBAL_VERSION"
|
||||||
|
JSON_TARGET=$(echo '{ "DATE": "'$DATE'", "UPGRADE_STATUS": "'$UPGRADE_STATUS'" }' | jq -r . | base64 -w0)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
debug "JSON_TARGET: $JSON_TARGET"
|
debug "JSON_TARGET: $JSON_TARGET"
|
||||||
|
9
scripts/scheduler/upgrade.sh
Executable file
9
scripts/scheduler/upgrade.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
B64_JSON=$1
|
||||||
|
SERVICE_EXEC=$2
|
||||||
|
GLOBAL_VERSION=$4
|
||||||
|
|
||||||
|
for SERVICE in $(echo $B64_JSON | base64 -d | jq -r 'keys[]'); do
|
||||||
|
|
||||||
|
done
|
Reference in New Issue
Block a user