@@ -839,15 +839,48 @@ if [[ "$webguiManifestTs" -gt "$plgManifestTs" ]]; then
839839 echo "♻️ Reverted to stock web component files"
840840fi
841841
842- # Install the API
843- # unraid-api-handler flash="/boot/config/plugins/dynamix.my.servers"
842+ # Install the API (previously in rc.d script)
843+
844+ flash="/boot/config/plugins/dynamix.my.servers"
844845[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
845846[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env" env=production
846847# shellcheck disable=SC1091
847848source "${flash}/env"
848849# Install the API to /usr/local/unraid-api
849850api_base_directory="/usr/local/unraid-api"
850851unraid_binary_path="/usr/local/bin/unraid-api"
852+ # Ensure installation tgz exists
853+ [[ ! -f "${flash}/unraid-api.tgz" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
854+ # Stop old process
855+ [[ -f "${unraid_binary_path}" ]] && ${unraid_binary_path} stop
856+ # Install unraid-api
857+ rm -rf "${api_base_directory}"
858+ mkdir -p "${api_base_directory}"
859+ tar -C "${api_base_directory}" -xzf "${flash}/unraid-api.tgz" --strip 1
860+ # Copy env file
861+ cp "${api_base_directory}/.env.${env}" "${api_base_directory}/.env"
862+ # Copy wc files from flash
863+ if [ -f "${flash}/webComps/unraid.min.js" ]; then
864+ rm -rf /usr/local/emhttp/webGui/webComps
865+ mkdir -p /usr/local/emhttp/webGui/webComps
866+ cp ${flash}/webComps/* /usr/local/emhttp/webGui/webComps
867+ else
868+ # not fatal, previous version of unraid.min.js should still exist in /usr/local/emhttp/webGui/webComps
869+ echo "Note: ${flash}/webComps/unraid.min.js is missing"
870+ fi
871+ cd "${api_base_directory}" && npm link --force
872+ # bail if expected file does not exist
873+ [[ ! -f "${api_base_directory}/package.json" ]] && echo "unraid-api install failed" && exit 1
874+ # if nginx is running, start the api. if not, it will be started by rc.nginx
875+ if /etc/rc.d/rc.nginx status &>/dev/null; then
876+ # Start new process
877+ ${unraid_binary_path} start
878+ # Note: do not run another unraid-api command until you see "UNRAID API started successfully!" in syslog
879+ sleep 3
880+ echo "unraid-api installed and started"
881+ else
882+ echo "unraid-api installed"
883+ fi
851884
852885# start background process to start flash backup
853886echo
0 commit comments