Skip to content

Commit c9ac3a5

Browse files
committed
feat: use plugin file for install and uninstall
1 parent 54a893f commit c9ac3a5

File tree

2 files changed

+17
-55
lines changed

2 files changed

+17
-55
lines changed

plugin/plugins/dynamix.unraid.net.plg

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ if [ -e /etc/rc.d/rc.unraid-api ]; then
324324
# forcibly stop older clients
325325
kill -9 `pidof unraid-api` &>/dev/null
326326
# uninstall the api
327-
/etc/rc.d/rc.unraid-api uninstall &>/dev/null
327+
rm -rf /usr/local/unraid-api
328+
rm -rf /var/log/unraid-api/
329+
rm -f /var/run/unraid-api.sock
328330
# uninstall the main source package
329331
[[ -f "/var/log/packages/${MAINNAME}" ]] && removepkg --terse "${MAINNAME}"
330332
# restore stock files
@@ -837,13 +839,22 @@ if [[ "$webguiManifestTs" -gt "$plgManifestTs" ]]; then
837839
echo "♻️ Reverted to stock web component files"
838840
fi
839841
840-
# start background process to install/start the api and flash backup
842+
# Install the API
843+
# unraid-api-handler flash="/boot/config/plugins/dynamix.my.servers"
844+
[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
845+
[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env" env=production
846+
# shellcheck disable=SC1091
847+
source "${flash}/env"
848+
# Install the API to /usr/local/unraid-api
849+
api_base_directory="/usr/local/unraid-api"
850+
unraid_binary_path="/usr/local/bin/unraid-api"
851+
852+
# start background process to start flash backup
841853
echo
842854
if [ -f /var/local/emhttp/var.ini ]; then
843855
# the system has fully booted, emhttpd and nginx are running
844-
echo "Installing and starting the Unraid API"
845856
echo "Starting flash backup (if enabled)"
846-
echo "/etc/rc.d/rc.unraid-api install; /etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
857+
echo "/etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
847858
# else
848859
# the system is booting, emhttpd will install the api and start rc.flash_backup. rc.nginx will start the api.
849860
# nothing to do here

plugin/source/dynamix.unraid.net/etc/rc.d/rc.unraid-api

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,13 @@
33
flash="/boot/config/plugins/dynamix.my.servers"
44
[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
55
[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env"
6-
env=production
7-
# shellcheck disable=SC1091
8-
source "${flash}/env"
9-
# Install the API to /usr/local/unraid-api
10-
api_base_directory="/usr/local/unraid-api"
116
unraid_binary_path="/usr/local/bin/unraid-api"
127

13-
148
install() {
15-
# Ensure installation tgz exists
16-
[[ ! -f "${flash}/unraid-api.tgz" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
17-
18-
# Stop old process
19-
[[ -f "${unraid_binary_path}" ]] && ${unraid_binary_path} stop
20-
21-
# Install unraid-api
22-
rm -rf "${api_base_directory}"
23-
mkdir -p "${api_base_directory}"
24-
tar -C "${api_base_directory}" -xzf "${flash}/unraid-api.tgz" --strip 1
25-
26-
# Copy env file
27-
cp "${api_base_directory}/.env.${env}" "${api_base_directory}/.env"
28-
29-
# Copy wc files from flash
30-
if [ -f "${flash}/webComps/unraid.min.js" ]; then
31-
rm -rf /usr/local/emhttp/webGui/webComps
32-
mkdir -p /usr/local/emhttp/webGui/webComps
33-
cp ${flash}/webComps/* /usr/local/emhttp/webGui/webComps
34-
else
35-
# not fatal, previous version of unraid.min.js should still exist in /usr/local/emhttp/webGui/webComps
36-
echo "Note: ${flash}/webComps/unraid.min.js is missing"
37-
fi
38-
39-
cd "${api_base_directory}" && npm link --force
40-
# bail if expected file does not exist
41-
[[ ! -f "${api_base_directory}/package.json" ]] && echo "unraid-api install failed" && exit 1
42-
43-
# if nginx is running, start the api. if not, it will be started by rc.nginx
44-
if /etc/rc.d/rc.nginx status &>/dev/null; then
45-
# Start new process
46-
${unraid_binary_path} start
47-
# Note: do not run another unraid-api command until you see "UNRAID API started successfully!" in syslog
48-
sleep 3
49-
echo "unraid-api installed and started"
50-
else
51-
echo "unraid-api installed"
52-
fi
53-
exit 0
9+
true;
5410
}
5511
uninstall() {
56-
# Stop old process
57-
[[ -f "${unraid_binary_path}" ]] && ${unraid_binary_path} stop
58-
59-
# Remove all unraid-api files
60-
rm -rf "${api_base_directory}"
61-
rm -f /var/run/unraid-api.sock
12+
true;
6213
}
6314

6415
case "$1" in

0 commit comments

Comments
 (0)