mirror of
https://github.com/unraid/api.git
synced 2026-04-22 07:10:42 -05:00
80 lines
2.2 KiB
Bash
Executable File
80 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# 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/"
|
|
|
|
restart() {
|
|
"${api_base_directory}/unraid-api" restart
|
|
}
|
|
install() {
|
|
# Ensure installation tgz exists
|
|
[[ ! -f "${flash}/unraid-api.tgz" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
|
|
|
|
# Stop old process
|
|
[[ -f "${api_base_directory}nraid-api" ]] && 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
|
|
# 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
|
|
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() {
|
|
# Stop old process
|
|
[[ -f "${api_base_directory}/unraid-api" ]] && stop
|
|
|
|
# Remove all unraid-api files
|
|
rm -rf "${api_base_directory}"
|
|
rm -f /var/run/unraid-api.sock
|
|
}
|
|
|
|
case "$1" in
|
|
'install')
|
|
install "$2"
|
|
;;
|
|
'reload')
|
|
restart
|
|
;;
|
|
'uninstall')
|
|
uninstall
|
|
;;
|
|
*)
|
|
# Pass all other commands to unraid-api
|
|
"${api_base_directory}/unraid-api" "$@"
|
|
;;
|
|
esac
|