From 73fb0af07f06d96ac34fb18f0b9d7b8043772884 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 10 Nov 2024 14:14:43 +0100 Subject: [PATCH] feat: Display version info --- entrypoint.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index c69c0e5..3eae195 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,21 +1,33 @@ #!/usr/bin/env bash set -Eeuo pipefail +info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; } +error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; } +warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; } + +trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR + +[ ! -f "/entrypoint.sh" ] && error "Script must run inside Docker container!" && exit 11 +[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12 + +echo "❯ Starting CasaOS for Docker v$(/dev/null; then - echo "ERROR: Failed to find a container with name '$target'!" && exit 16 + error "Failed to find a container with name '$target'!" && exit 16 fi resp=$(docker inspect "$target") mount=$(echo "$resp" | jq -r '.[0].Mounts[] | select(.Destination == "/DATA").Source') if [ -z "$mount" ] || [[ "$mount" == "null" ]] || [ ! -d "/DATA" ]; then - echo "ERROR: You did not bind the /DATA folder!" && exit 18 + error "You did not bind the /DATA folder!" && exit 18 fi # Convert Windows paths to Linux path @@ -26,7 +38,7 @@ if [[ "$mount" == *":\\"* ]]; then fi if [[ "$mount" != "/"* ]]; then - echo "ERROR: Please bind the /DATA folder to an absolute path!" && exit 19 + error "Please bind the /DATA folder to an absolute path!" && exit 19 fi # Mirror external folder to local filesystem @@ -54,11 +66,12 @@ touch /var/log/casaos-main.log # Wait for the Gateway service to start while [ ! -f /var/run/casaos/management.url ]; do - echo "Waiting for the Gateway service to start..." + info "Waiting for the Management service to start..." sleep 1 done + while [ ! -f /var/run/casaos/static.url ]; do - echo "Waiting for the Gateway service to start..." + info "Waiting for the Gateway service to start..." sleep 1 done @@ -67,7 +80,7 @@ done # Wait for the Gateway service to start while [ ! -f /var/run/casaos/message-bus.url ]; do - echo "Waiting for the Gateway service to start..." + info "Waiting for the Message service to start..." sleep 1 done @@ -75,7 +88,7 @@ done ./casaos-main > /var/log/casaos-main.log 2>&1 & # Wait for the Main service to start while [ ! -f /var/run/casaos/casaos.url ]; do - echo "Waiting for the Main service to start..." + info "Waiting for the Main service to start..." sleep 1 done @@ -85,7 +98,7 @@ done # wait for /var/run/casaos/routes.json to be created and contains local_storage # Wait for /var/run/casaos/routes.json to be created and contains local_storage while [ ! -f /var/run/casaos/routes.json ] || ! grep -q "local_storage" /var/run/casaos/routes.json; do - echo "Waiting for /var/run/casaos/routes.json to be created and contains local_storage..." + info "Waiting for /var/run/casaos/routes.json to be created and contains local_storage..." sleep 1 done