forked from calagopus/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.heavy.sh
More file actions
146 lines (115 loc) · 4.14 KB
/
Copy pathentrypoint.heavy.sh
File metadata and controls
146 lines (115 loc) · 4.14 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
#!/bin/ash
REPO_DIR="/app/repo"
cd "$REPO_DIR" || exit 1
touch /tmp/rebuild_trigger
export EXTENSION_LOG="/tmp/extension_build.log"
export EXTENSION_BUILD_LOCK="/tmp/extension_build.lock"
if [ ! -d "/app/binaries" ]; then
echo "Error: /app/binaries directory is missing. Please mount the binaries volume."
exit 1
fi
if [ ! -d "/app/translations" ]; then
echo "Error: /app/translations directory is missing. Please mount the translations volume."
exit 1
fi
if [ ! -d "/app/extensions" ]; then
echo "Error: /app/extensions directory is missing. Please mount the extensions volume."
exit 1
fi
if [ ! -d "/app/repo/database/extension-migrations" ]; then
echo "Error: /app/repo/database/extension-migrations directory is missing. Please mount a volume for database extension migrations."
exit 1
fi
cp -R /app/translations/* /app/repo/frontend/public/translations/
# calculate the combined sha256 hash of all arguments' contents
hash_many() {
local hash=""
for file in "$@"; do
if [ -f "$file" ]; then
file_hash=$(sha256sum "$file" | awk '{print $1}')
hash="${hash}${file_hash}"
fi
done
echo -n "$hash" | sha256sum | awk '{print $1}'
}
PANEL_PID=""
start_panel() {
local bin="$1"
echo "Starting panel-rs with binary: $bin"
if [ -n "$PANEL_PID" ]; then
echo "Stopping existing panel-rs with PID: $PANEL_PID"
kill "$PANEL_PID"
wait "$PANEL_PID"
PANEL_PID=""
fi
"$bin" &
PANEL_PID=$!
echo "panel-rs started with PID: $PANEL_PID"
}
PANEL_VERSION=$(/app/repo/target/heavy-release/panel-rs version)
PANEL_VERSION=$(echo $PANEL_VERSION | awk '{print $2}')
execute_build() {
if [ -f "$EXTENSION_BUILD_LOCK" ]; then
echo "Extension build already in progress. spin looping."
while [ -f "$EXTENSION_BUILD_LOCK" ]; do
sleep 1
done
echo "Extension build completed by another process."
fi
touch "$EXTENSION_BUILD_LOCK"
local EXT_HASH=$(hash_many /app/extensions/*.c7s.zip)
BINARY_PATH="/app/binaries/$PANEL_VERSION/$EXT_HASH/panel-rs"
echo "Building new binary with current extensions..."
# loop over all extension files
for ext_file in /app/extensions/*.c7s.zip; do
echo "Adding extension: $ext_file"
/app/repo/target/heavy-release/panel-rs extensions add "$ext_file" --skip-version-check >> "$EXTENSION_LOG" 2>&1
done
local PROFILE="balanced"
local PROFILE_PATH="heavy-release"
# resync internal extension list
/app/repo/target/heavy-release/panel-rs extensions resync >> "$EXTENSION_LOG" 2>&1
# apply changes
export NODE_OPTIONS="--max-old-space-size=2048"
/app/repo/target/heavy-release/panel-rs extensions apply --skip-replace-binary --profile $PROFILE >> "$EXTENSION_LOG" 2>&1
cp -R /app/repo/frontend/public/translations/* /app/translations/
local EXIT_CODE=$?
# check status of last command
if [ $EXIT_CODE -eq 0 ]; then
echo "Extension build successful. Saving new binary."
echo 0 > /tmp/extension_build.exitcode
# create directory for new binary
mkdir -p "/app/binaries/$PANEL_VERSION/$EXT_HASH"
# copy new binary to binaries directory
cp "/app/repo/target/$PROFILE_PATH/panel-rs" "$BINARY_PATH"
# restart panel with new binary
echo "Restarting panel-rs with new binary."
start_panel "$BINARY_PATH"
else
echo "Extension build failed. Check the log at $EXTENSION_LOG for details."
echo $EXIT_CODE > /tmp/extension_build.exitcode
fi
rm "$EXTENSION_BUILD_LOCK"
}
# get combined hash of all extension files
EXT_HASH=$(hash_many /app/extensions/*.c7s.zip)
# check if binary with this hash exists
BINARY_PATH="/app/binaries/$PANEL_VERSION/$EXT_HASH/panel-rs"
if [ -f "$BINARY_PATH" ]; then
echo "Found existing binary for current extensions."
start_panel "$BINARY_PATH"
else
echo "No existing binary found for current extensions. Temporarily using default binary."
start_panel "/app/repo/target/heavy-release/panel-rs"
# execute build if extensions directory is not empty
if [ "$(ls -A /app/extensions)" ]; then
execute_build
else
echo "No extensions found in /app/extensions. Skipping build."
fi
fi
# watch for changes in /tmp/rebuild_trigger
inotifywait -m -e create,modify /tmp/rebuild_trigger | while read -r directory events filename; do
echo "Rebuild trigger detected: $events on $filename"
execute_build
done