feat: use plugin file for install and uninstall

This commit is contained in:
Eli Bosley
2024-12-30 09:54:36 -05:00
parent 7dcf947527
commit bbf28075c6
2 changed files with 17 additions and 55 deletions

View File

@@ -324,7 +324,9 @@ if [ -e /etc/rc.d/rc.unraid-api ]; then
# forcibly stop older clients # forcibly stop older clients
kill -9 `pidof unraid-api` &>/dev/null kill -9 `pidof unraid-api` &>/dev/null
# uninstall the api # uninstall the api
/etc/rc.d/rc.unraid-api uninstall &>/dev/null rm -rf /usr/local/unraid-api
rm -rf /var/log/unraid-api/
rm -f /var/run/unraid-api.sock
# uninstall the main source package # uninstall the main source package
[[ -f "/var/log/packages/${MAINNAME}" ]] && removepkg --terse "${MAINNAME}" [[ -f "/var/log/packages/${MAINNAME}" ]] && removepkg --terse "${MAINNAME}"
# restore stock files # restore stock files
@@ -837,13 +839,22 @@ if [[ "$webguiManifestTs" -gt "$plgManifestTs" ]]; then
echo "♻️ Reverted to stock web component files" echo "♻️ Reverted to stock web component files"
fi fi
# start background process to install/start the api and flash backup # Install the API
# unraid-api-handler flash="/boot/config/plugins/dynamix.my.servers"
[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env" env=production
# shellcheck disable=SC1091
source "${flash}/env"
# Install the API to /usr/local/unraid-api
api_base_directory="/usr/local/unraid-api"
unraid_binary_path="/usr/local/bin/unraid-api"
# start background process to start flash backup
echo echo
if [ -f /var/local/emhttp/var.ini ]; then if [ -f /var/local/emhttp/var.ini ]; then
# the system has fully booted, emhttpd and nginx are running # the system has fully booted, emhttpd and nginx are running
echo "Installing and starting the Unraid API"
echo "Starting flash backup (if enabled)" echo "Starting flash backup (if enabled)"
echo "/etc/rc.d/rc.unraid-api install; /etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null echo "/etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
# else # else
# the system is booting, emhttpd will install the api and start rc.flash_backup. rc.nginx will start the api. # the system is booting, emhttpd will install the api and start rc.flash_backup. rc.nginx will start the api.
# nothing to do here # nothing to do here

View File

@@ -3,62 +3,13 @@
flash="/boot/config/plugins/dynamix.my.servers" flash="/boot/config/plugins/dynamix.my.servers"
[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1 [[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env" [[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env"
env=production
# shellcheck disable=SC1091
source "${flash}/env"
# Install the API to /usr/local/unraid-api
api_base_directory="/usr/local/unraid-api"
unraid_binary_path="/usr/local/bin/unraid-api" unraid_binary_path="/usr/local/bin/unraid-api"
install() { install() {
# Ensure installation tgz exists true;
[[ ! -f "${flash}/unraid-api.tgz" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
# Stop old process
[[ -f "${unraid_binary_path}" ]] && ${unraid_binary_path} stop
# Install unraid-api
rm -rf "${api_base_directory}"
mkdir -p "${api_base_directory}"
tar -C "${api_base_directory}" -xzf "${flash}/unraid-api.tgz" --strip 1
# Copy env file
cp "${api_base_directory}/.env.${env}" "${api_base_directory}/.env"
# Copy wc files from flash
if [ -f "${flash}/webComps/unraid.min.js" ]; then
rm -rf /usr/local/emhttp/webGui/webComps
mkdir -p /usr/local/emhttp/webGui/webComps
cp ${flash}/webComps/* /usr/local/emhttp/webGui/webComps
else
# not fatal, previous version of unraid.min.js should still exist in /usr/local/emhttp/webGui/webComps
echo "Note: ${flash}/webComps/unraid.min.js is missing"
fi
cd "${api_base_directory}" && npm link --force
# bail if expected file does not exist
[[ ! -f "${api_base_directory}/package.json" ]] && echo "unraid-api install failed" && exit 1
# if nginx is running, start the api. if not, it will be started by rc.nginx
if /etc/rc.d/rc.nginx status &>/dev/null; then
# Start new process
${unraid_binary_path} start
# Note: do not run another unraid-api command until you see "UNRAID API started successfully!" in syslog
sleep 3
echo "unraid-api installed and started"
else
echo "unraid-api installed"
fi
exit 0
} }
uninstall() { uninstall() {
# Stop old process true;
[[ -f "${unraid_binary_path}" ]] && ${unraid_binary_path} stop
# Remove all unraid-api files
rm -rf "${api_base_directory}"
rm -f /var/run/unraid-api.sock
} }
case "$1" in case "$1" in