-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
151 lines (112 loc) · 4.41 KB
/
setup.sh
File metadata and controls
151 lines (112 loc) · 4.41 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
###############################################################################
# Decklify setup script
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/decklify/decklify_client/master/setup.sh | sudo bash
#
# Testing:
# BASE=/tmp/decklify-test sudo ./setup.sh
###############################################################################
set -euo pipefail
# -----------------------------------------------------------------------------
# CONFIG
# -----------------------------------------------------------------------------
BASE="${BASE:-/opt/decklify}"
TMP="${BASE}.tmp"
SERVICE_NAME="decklify"
# -----------------------------------------------------------------------------
# PRECONDITIONS
# -----------------------------------------------------------------------------
[[ "$EUID" -eq 0 ]] || { echo "Please run as root (sudo)"; exit 1; }
[[ -n "${SUDO_USER:-}" ]] || { echo "SUDO_USER is not set"; exit 1; }
echo "✅ Running as root"
# -----------------------------------------------------------------------------
# CLEANUP
# -----------------------------------------------------------------------------
cleanup() { echo "❌ Setup failed — cleaning up"; rm -rf "$TMP"; }
trap cleanup ERR INT
# -----------------------------------------------------------------------------
# DEPENDENCIES
# -----------------------------------------------------------------------------
echo "📦 Installing dependencies"
apt update
apt install -y \
curl \
jq \
unzip \
zip
if [[ ! -d "/home/$SUDO_USER/.sdkman" ]]; then
sudo -u "$SUDO_USER" bash -c "curl -s 'https://get.sdkman.io?ci=true' | bash"
else
echo "✅ SDKman already installed"
fi
sudo -u "$SUDO_USER" bash -c "
source '/home/$SUDO_USER/.sdkman/bin/sdkman-init.sh'
sdk install java 23.0.2-tem
"
# -----------------------------------------------------------------------------
# STAGING
# -----------------------------------------------------------------------------
echo "📁 Preparing staging directory"
rm -rf "$TMP"
mkdir -p "$TMP/app/current" "$TMP/log"
touch "$TMP/app/version.txt" "$TMP/log/app.log"
# -----------------------------------------------------------------------------
# DOWNLOAD
# -----------------------------------------------------------------------------
echo "⬇️ Downloading launch script"
curl -fsSL \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "application/vnd.github.raw" \
"https://raw.githubusercontent.com/decklify/decklify_client/master/launch.sh" \
-o "$TMP/launch.sh"
chmod +x "$TMP/launch.sh"
# -----------------------------------------------------------------------------
# NETWORK MANAGER
# -----------------------------------------------------------------------------
echo "Configuring network manager..."
systemctl disable systemd-networkd-wait-online 2>/dev/null || true
systemctl enable NetworkManager-wait-online 2>/dev/null || true
echo "Network manager configured"
# -----------------------------------------------------------------------------
# SYSTEMD SERVICE
# -----------------------------------------------------------------------------
echo "🧠 Creating systemd service"
cat > "$TMP/${SERVICE_NAME}.service" <<EOF
[Unit]
Description=Decklify
After=NetworkManager-wait-online.service graphical.target
Wants=NetworkManager-wait-online.service
[Service]
Type=simple
User=$SUDO_USER
ExecStartPre=/bin/bash -c 'until ping -c1 -W1 224.0.0.251 >/dev/null 2>&1; do sleep 1; done'
ExecStart=${BASE}/launch.sh
Restart=always
RestartSec=2
Environment=DISPLAY=:0
[Install]
WantedBy=graphical.target
EOF
# -----------------------------------------------------------------------------
# COMMIT
# -----------------------------------------------------------------------------
echo "🚀 Installing"
rm -rf "$BASE"
mv "$TMP" "$BASE"
chown -R "$SUDO_USER:$SUDO_USER" "$BASE"
chmod -R 755 "$BASE"
mv "$BASE/${SERVICE_NAME}.service" "/etc/systemd/system/${SERVICE_NAME}.service"
# -----------------------------------------------------------------------------
# ACTIVATE
# -----------------------------------------------------------------------------
echo "🔧 Enabling service"
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
systemctl start "$SERVICE_NAME"
# -----------------------------------------------------------------------------
# DONE
# -----------------------------------------------------------------------------
trap - ERR INT
echo "✅ Decklify successfully installed! It will now start automatically on boot"