mirror of
https://github.com/unraid/api.git
synced 2025-12-30 21:19:49 -06:00
feat: use plugin file for install and uninstall
This commit is contained in:
@@ -324,7 +324,9 @@ if [ -e /etc/rc.d/rc.unraid-api ]; then
|
||||
# forcibly stop older clients
|
||||
kill -9 `pidof unraid-api` &>/dev/null
|
||||
# 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
|
||||
[[ -f "/var/log/packages/${MAINNAME}" ]] && removepkg --terse "${MAINNAME}"
|
||||
# restore stock files
|
||||
@@ -837,13 +839,22 @@ if [[ "$webguiManifestTs" -gt "$plgManifestTs" ]]; then
|
||||
echo "♻️ Reverted to stock web component files"
|
||||
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
|
||||
if [ -f /var/local/emhttp/var.ini ]; then
|
||||
# the system has fully booted, emhttpd and nginx are running
|
||||
echo "Installing and starting the Unraid API"
|
||||
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
|
||||
# the system is booting, emhttpd will install the api and start rc.flash_backup. rc.nginx will start the api.
|
||||
# nothing to do here
|
||||
|
||||
@@ -3,62 +3,13 @@
|
||||
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"
|
||||
|
||||
|
||||
install() {
|
||||
# Ensure installation tgz exists
|
||||
[[ ! -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
|
||||
true;
|
||||
}
|
||||
uninstall() {
|
||||
# Stop old process
|
||||
[[ -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
|
||||
true;
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
||||
Reference in New Issue
Block a user