-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-pi.sh
More file actions
112 lines (101 loc) · 3.68 KB
/
Copy pathdeploy-pi.sh
File metadata and controls
112 lines (101 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
set -euo pipefail
# Deploy Kiosk Print Agent to a Raspberry Pi
# Usage: ./deploy-pi.sh <user@host> [options]
#
# Options:
# --server <url> Foundation server URL (e.g. https://scale.example.com)
# --printer <name> CUPS printer name (run 'lpstat -p' on Pi to list)
# --printer-id <1|2> 1 = Inbound, 2 = Outbound (default 1)
# --key <ssh-key> SSH key file
#
# Examples:
# ./deploy-pi.sh pi@192.168.1.50
# ./deploy-pi.sh pi@192.168.1.50 --server https://scale.example.com --printer Zebra --printer-id 1
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARBALL="$SCRIPT_DIR/kioskprint-deploy.tar.gz"
# Parse arguments
REMOTE=""
SERVER_URL=""
PRINTER_NAME=""
PRINTER_ID=""
SSH_KEY=""
SKIP_BUILD="0"
while [[ $# -gt 0 ]]; do
case "$1" in
--server) SERVER_URL="$2"; shift 2 ;;
--printer) PRINTER_NAME="$2"; shift 2 ;;
--printer-id) PRINTER_ID="$2"; shift 2 ;;
--skip-build) SKIP_BUILD="1"; shift ;;
--key) SSH_KEY="$2"; shift 2 ;;
-*) echo "Unknown option: $1"; exit 1 ;;
*) REMOTE="$1"; shift ;;
esac
done
if [[ -z "$REMOTE" ]]; then
echo "Usage: ./deploy-pi.sh <user@host> [options]"
echo ""
echo "Options:"
echo " --server <url> Foundation server URL"
echo " --printer <name> CUPS printer name"
echo " --printer-id <1|2> 1=Inbound, 2=Outbound (default 1)"
echo " --key <ssh-key> SSH key file"
echo ""
echo "Examples:"
echo " ./deploy-pi.sh pi@192.168.1.50"
echo " ./deploy-pi.sh pi@192.168.1.50 --server https://scale.example.com --printer Zebra --printer-id 1"
exit 1
fi
# Build SSH options
SSH_OPTS="-o StrictHostKeyChecking=no"
SCP_OPTS="-o StrictHostKeyChecking=no"
if [[ -n "$SSH_KEY" ]]; then
SSH_OPTS="$SSH_OPTS -i $SSH_KEY"
SCP_OPTS="$SCP_OPTS -i $SSH_KEY"
fi
# Always publish a fresh build — a cached tarball silently deploys stale
# code. Pass --skip-build to reuse the existing tarball.
if [[ "$SKIP_BUILD" == "1" && -f "$TARBALL" ]]; then
echo "==> Reusing existing tarball (--skip-build)."
else
echo "==> Publishing fresh build..."
bash "$SCRIPT_DIR/publish-pi.sh"
fi
echo "==> Uploading to $REMOTE..."
scp $SCP_OPTS "$TARBALL" "$REMOTE:/tmp/kioskprint-deploy.tar.gz"
echo "==> Installing on Pi..."
ssh $SSH_OPTS "$REMOTE" "
cd /tmp && \
mkdir -p /tmp/kioskprint-install && \
tar -xzf /tmp/kioskprint-deploy.tar.gz -C /tmp/kioskprint-install && \
cd /tmp/kioskprint-install && \
sudo bash install-pi.sh && \
rm -rf /tmp/kioskprint-install /tmp/kioskprint-deploy.tar.gz
"
# Update appsettings.json if parameters were provided
if [[ -n "$SERVER_URL" || -n "$PRINTER_NAME" || -n "$PRINTER_ID" ]]; then
echo "==> Updating print agent config..."
CONFIG_CMD=""
if [[ -n "$SERVER_URL" ]]; then
CONFIG_CMD="$CONFIG_CMD sed -i 's|\"ServerUrl\":.*|\"ServerUrl\": \"$SERVER_URL\",|' /opt/kioskprint/appsettings.json &&"
fi
if [[ -n "$PRINTER_NAME" ]]; then
CONFIG_CMD="$CONFIG_CMD sed -i 's|\"PrinterName\":.*|\"PrinterName\": \"$PRINTER_NAME\",|' /opt/kioskprint/appsettings.json &&"
fi
if [[ -n "$PRINTER_ID" ]]; then
CONFIG_CMD="$CONFIG_CMD sed -i 's|\"PrinterId\":.*|\"PrinterId\": $PRINTER_ID|' /opt/kioskprint/appsettings.json &&"
fi
CONFIG_CMD="$CONFIG_CMD sudo systemctl restart kioskprint"
ssh $SSH_OPTS "$REMOTE" "$CONFIG_CMD"
echo " Config updated and service restarted."
fi
echo ""
echo "=========================================="
echo " Pi Deploy complete!"
echo "=========================================="
echo " Pi: $REMOTE"
if [[ -n "$SERVER_URL" ]]; then
echo " Server: $SERVER_URL"
fi
echo " Check: ssh $REMOTE 'systemctl status kioskprint'"
echo "=========================================="