Skip to content

Commit d99dba2

Browse files
committed
feat: enhance setup and deploy scripts to fetch helper scripts from remote if not available locally
1 parent 4194895 commit d99dba2

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

pi-node/setup.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,34 @@ SERVER_URL=$SERVER_URL
5656
FLOOR_ID=$FLOOR_ID
5757
EOF
5858

59-
# ── 3. Copy scripts ──
59+
# ── 3. Copy or fetch helper scripts ──
6060
echo "[3/5] Installing scripts..."
61-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
62-
cp "$SCRIPT_DIR/kiosk.sh" "$INSTALL_DIR/kiosk.sh"
63-
cp "$SCRIPT_DIR/update.sh" "$INSTALL_DIR/update.sh"
61+
62+
# determine the directory containing this script. When the file is
63+
# executed via stdin (e.g. curl | bash) BASH_SOURCE may not be set, so
64+
# fall back to $0. Avoid unbound-variable errors by testing with -v.
65+
if [[ -v BASH_SOURCE ]]; then
66+
SCRIPT_PKG="${BASH_SOURCE[0]}"
67+
else
68+
SCRIPT_PKG="$0"
69+
fi
70+
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PKG")" && pwd)"
71+
72+
# helper to either copy from local tree or download a fresh copy
73+
fetch_or_copy() {
74+
local name="$1" url
75+
url="https://raw.githubusercontent.com/IN4300-Embedded-Systems-Project/B22_Group06/main/pi-node/$name"
76+
77+
if [[ -f "$SCRIPT_DIR/$name" ]]; then
78+
cp "$SCRIPT_DIR/$name" "$INSTALL_DIR/$name"
79+
else
80+
echo "-> fetching $name from remote"
81+
curl -sSL "$url" -o "$INSTALL_DIR/$name"
82+
fi
83+
}
84+
85+
fetch_or_copy kiosk.sh
86+
fetch_or_copy update.sh
6487
chmod +x "$INSTALL_DIR"/*.sh
6588

6689
# ── 4. Install systemd services ──

scripts/deploy.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.."
66

77
echo "=== Deploying Display System ==="
88

9-
# Load .env if exists
10-
[[ -f .env ]] && { set -a; source .env; set +a; }
9+
# Load .env if exists (strip any Windows CRs first so bash won't complain)
10+
if [[ -f .env ]]; then
11+
# remove stray carriage returns in case the file has CRLF line endings
12+
sed -i 's/\r$//' .env || true
13+
set -a; source .env; set +a
14+
fi
1115

1216
# Build and start
1317
docker compose -f deploy/docker-compose.yml up -d --build

0 commit comments

Comments
 (0)