Skip to content

Commit

Permalink
feat: Display version info
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Nov 10, 2024
1 parent 846169c commit 73fb0af
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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$(</run/version)..."
echo "❯ For support visit https://github.com/dockur/casaos/issues"

if [ ! -S /var/run/docker.sock ]; then
echo "ERROR: Docker socket is missing? Please bind /var/run/docker.sock in your compose file." && exit 13
error "Docker socket is missing? Please bind /var/run/docker.sock in your compose file." && exit 13
fi

target=$(hostname)

if ! docker inspect "$target" &>/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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -67,15 +80,15 @@ 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

# Start the Main service and redirect stdout and stderr to the log files
./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

Expand All @@ -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

Expand Down

0 comments on commit 73fb0af

Please sign in to comment.