]> name="&name;" version="&version;" API_version="&API_version;" PLGTYPE="&env;" DLHOST=$(echo "&downloadserver;" | awk -F/ '{print $3}') JSHOST=$(echo "&js_dl_server;" | awk -F/ '{print $3}') /dev/null; then echo "⚠️ Unable to install as gzip is not available on this system. For help, post your diagnostics.zip to a new support thread in the forum." exit 1 fi dnscheck() { HOST=$1 if [ -x /usr/bin/host ] && ! /usr/bin/host "${HOST}" &>/dev/null; then echo "⚠️ Warning: Your DNS server (${DNS_SERVER1}) is unable to resolve '${HOST}'" DNSERR=yes fi } # shellcheck disable=SC1090 source <(grep "DNS_SERVER1" /usr/local/emhttp/state/network.ini 2>/dev/null) DNSERR=no echo "Checking DNS..." dnscheck "${DLHOST}" dnscheck "${JSHOST}" dnscheck "mothership.unraid.net" dnscheck "wanip4.unraid.net" dnscheck "backup.unraid.net" [[ "${DNSERR}" == "yes" && "${DNS_SERVER1}" != "8.8.8.8" ]] && echo " Recommend navigating to Settings -> Network Settings and changing your DNS server to 8.8.8.8" # Note: DNS checks will fail if the network is not available at boot. Cannot exit the install when DNS checks fail. if [[ "${version:0:3}" == "6.9" || "${version:0:4}" == "6.10" ]]; then echo echo "⚠️ Do not close this window yet" echo fi # compare expected SHA256 to actual SHA256, if not equal delete file # this is needed prior to Unraid 6.11.0 sha256check() { FILE=$1 EXPECTED=$2 if [[ -f "${FILE}" ]]; then echo -n "Validating ${FILE}... " ACTUAL=$(sha256sum "${FILE}" 2>/dev/null | grep -Po '^\S+') if [[ "$EXPECTED" != "$ACTUAL" ]]; then rm "${FILE}" echo " old. Deleted file." else echo " ok." fi fi } ]]> sha256check "&source;.txz" "&SHA256;" sha256check "/boot/config/plugins/dynamix.my.servers/unraid-api.tgz" "&API_SHA256;" exit 0 &downloadserver;/unraid-api/&name;-&version;.txz &MD5; &SHA256; &downloadserver;/unraid-api/unraid-api-&API_version;.tgz &API_MD5; &API_SHA256; MAINTXZ="&source;.txz" js_dl_server=&js_dl_server; /dev/null if [[ -f "/tmp/${JS_FILE}.tmp1" && -s "/tmp/${JS_FILE}.tmp1" ]]; then # simple validatation that the file was downloaded correctly if grep -q "sourceMappingURL=unraid.min.js.map" "/tmp/${JS_FILE}.tmp1"; then # remove source mapping from js head -n -1 "/tmp/${JS_FILE}.tmp1" >"/tmp/${JS_FILE}.tmp2" rm "/tmp/${JS_FILE}.tmp1" fi fi # if /tmp/${JS_FILE}.tmp2 was downloaded above, move it to JS_FLASH_DEST [[ -f "/tmp/${JS_FILE}.tmp2" ]] && mkdir -p "${JS_FLASH_DEST}" && mv "/tmp/${JS_FILE}.tmp2" "${JS_FLASH_DEST}${JS_FILE}" # NOTE: if download was not successful, there may still be a previous copy in JS_FLASH_DEST # if unraid.min.js exists in JS_FLASH_DEST, copy it from JS_FLASH_DEST to JS_FINAL_DEST # @TODO: validate that the unraid.min.js in JS_FLASH_DEST is not older than an existing one in JS_FINAL_DEST [[ -f "${JS_FLASH_DEST}${JS_FILE}" ]] && mkdir -p "${JS_FINAL_DEST}" && cp "${JS_FLASH_DEST}${JS_FILE}" "${JS_FINAL_DEST}" # NOTE: if file does not exist in JS_FLASH_DEST, there should still be a previous copy in JS_FINAL_DEST (unless Unraid 6.9) # if not, we have to exit [[ ! -f "${JS_FINAL_DEST}${JS_FILE}" ]] && echo "⚠️ Install failed - ${JS_FILE} missing" && exit 1 echo "✅ Finished installing web components" if [[ "${version:0:3}" == "6.9" || "${version:0:4}" == "6.10" ]]; then echo echo "⚠️ Do not close this window yet" echo fi exit 0 ]]> /dev/null"); # deactivate flash backup echo "\nDeactivating flash backup. Please wait…"; passthru("/usr/bin/php /usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php deactivate"); # delete local flash backup echo "\nDeleting local flash backup. Please wait…\n"; exec("rm -rf /boot/.git"); } # set "Allow Remote Access" to "No" and sign out from My Servers if ($msini !== false) { # stop unraid-api echo "\nStopping unraid-api. Please wait…"; exec("/etc/rc.d/rc.unraid-api stop &>/dev/null"); if (!empty($msini['remote']['username'])) { $var = parse_ini_file("/var/local/emhttp/var.ini"); $keyfile = @file_get_contents($var['regFILE']); if ($keyfile !== false) { echo "\nSigning out of My Servers\n"; $ch = curl_init('https://keys.lime-technology.com/account/server/unregister'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, ['keyfile' => @base64_encode($keyfile)]); curl_exec($ch); curl_close($ch); } } # remove myservers.cfg unlink('/boot/config/plugins/dynamix.my.servers/myservers.cfg'); # reload nginx echo "\nReloading Web Server\n"; exec("/etc/rc.d/rc.nginx reload &>/dev/null"); } exit(0); ]]> MAINNAME="&name;" /dev/null /etc/rc.d/rc.unraid-api uninstall # Uninstall the main source package [[ -f "/var/log/packages/${MAINNAME}" ]] && removepkg --terse "${MAINNAME}" # restore stock files FILE=/usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix/Registration.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix/DisplaySettings.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix.my.servers/MyServers.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers2.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" FILE=/sbin/upgradepkg && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE" # delete plugin files from flash drive and OS rm -f /boot/config/plugins/dynamix.my.servers/.gitignore rm -f /etc/rc.d/rc.unraid-api rm -f /etc/rc.d/rc.flash_backup rm -f /usr/local/sbin/unraid-api rm -rf /usr/local/emhttp/plugins/dynamix.unraid.net rm -rf /usr/local/emhttp/plugins/dynamix.unraid.net.staging rm -f /etc/rc.d/rc6.d/K10_flash_backup # delete any legacy files that may exist rm -rf /boot/config/plugins/dynamix.my.servers/libvirt.node rm -rf /boot/config/plugins/dynamix.my.servers/segfault-handler.node rm -rf /boot/config/plugins/dynamix.my.servers/wc rm -f /boot/config/plugins/Unraid.net/unraid-api.tgz rm -f /boot/config/plugins/Unraid.net/.gitignore rm -rf /boot/config/plugins/Unraid.net/webComps rm -rf /boot/config/plugins/Unraid.net/wc rm -f /usr/local/emhttp/webGui/javascript/vue.js rm -f /usr/local/emhttp/webGui/javascript/vue.min.js rm -rf /usr/local/emhttp/webGui/webComps rm -rf /usr/local/emhttp/webGui/wc # clean up our optional makestate modifications in rc.nginx (on 6.9 and 6.10.0-rc[12]) sed -i '/scripts\/makestate/d' /etc/rc.d/rc.nginx fi exit 0 ]]> PLGTYPE="&env;" MAINTXZ="&source;.txz" /boot/config/plugins/dynamix.my.servers/env fi if [[ "${version:0:3}" == "6.9" || "${version:0:4}" == "6.10" ]]; then echo echo "⚠️ Do not close this window yet" echo fi # Extra steps for Unraid 6.9.x, skip in 6.10.x if [[ "${version:0:3}" == "6.9" ]]; then # Update DefaultPageLayout.php, preserve in case plugin is removed FILE=/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php cp -f "$FILE" "$FILE-" sed -i 's/<\/head>/\n<\/head>/' "$FILE" sed -i 's/
/\n
/' "$FILE" sed -i '/
/,/<\/div>/d' "$FILE" # Update DisplaySettings.php, preserve in case plugin is removed FILE=/usr/local/emhttp/plugins/dynamix/DisplaySettings.page cp -f "$FILE" "$FILE-" echo -e "\n\n" >>/usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice1 echo -e "\n\n" >>/usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice2 sed -i $'/_(Header custom text color)_/{e cat /usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice1\n}' "$FILE" sed -i $'/_(Custom banner)_/{e cat /usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice2\n}' "$FILE" fi # delete this file regardless of Unraid version rm /usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice1 rm /usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice2 # run dynamix.cfg to myservers.cfg migration CFG_MIG=/usr/local/emhttp/plugins/dynamix.my.servers/scripts/cfgMigration php $CFG_MIG # Use myservers.cfg values to help prevent conflicts when installing CFG=/boot/config/plugins/dynamix.my.servers/myservers.cfg # shellcheck disable=SC1090 source <(grep 'email\|apikey="unraid_' "${CFG}" 2>/dev/null) CFG_CLEANED=0 # If user is signed in but has no apikey, or if the apikey is not 64 chars, wipe the [remote] section from the cfg if ([[ -n "${email}" && (-z "${apikey}" || "${#apikey}" -ne "64") ]]); then # remove only the [remote] section awk '{ if($0 ~ /\[remote\]/){output="off"; next} if($0 ~ /\[/){output="on"; print; next} if(output == "on"){print} }' "${CFG}" >"${CFG}-new" && mv "${CFG}-new" "${CFG}" CFG_CLEANED=1 echo "⚠️ Automatically signed out of Unraid.net" fi # if there wasn't an email or the CFG was cleaned if [[ -z "${email}" ]] || [[ CFG_CLEANED -eq 1 ]]; then echo "✨ Sign In to Unraid.net to get connected to My Servers ✨" fi # make the unraid-api work globally for easy cli access ln -s /usr/local/bin/unraid-api/unraid-api /usr/local/sbin/unraid-api # configure flash backup to stop when the system starts shutting down [[ ! -d /etc/rc.d/rc6.d ]] && mkdir /etc/rc.d/rc6.d [[ ! -h /etc/rc.d/rc0.d ]] && ln -s /etc/rc.d/rc6.d /etc/rc.d/rc0.d [[ ! -h /etc/rc.d/rc6.d/K10_flash_backup ]] && ln -s /etc/rc.d/rc.flash_backup /etc/rc.d/rc6.d/K10_flash_backup if [ -f /var/local/emhttp/var.ini ]; then echo "/etc/rc.d/rc.unraid-api install; /etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null elif grep -q 6.9.0-beta35 /etc/unraid-version; then echo "/etc/rc.d/rc.unraid-api install; /etc/rc.d/rc.flash_backup start" | at -M now + 1 minute &>/dev/null fi # modify older rc.nginx versions to run this makestate when it builds the nginx config files if ! grep -q 'scripts/makestate\|/var/local/nginx/state.ini\|/var/local/emhttp/nginx.ini' /etc/rc.d/rc.nginx; then placeafter="define_servers" if grep -q 'define_locations' /etc/rc.d/rc.nginx; then placeafter="define_locations" fi # splice makestate command in rc.nginx CMD_MAKESTATE="inotifywait --timeout 10 -qq -e moved_to /var/local/emhttp/var.ini; /usr/bin/php -f /usr/local/emhttp/plugins/dynamix.my.servers/scripts/makestate &>/dev/null" sed -i "/^ ${placeafter}/a echo '${CMD_MAKESTATE}' | at -M now &>/dev/null" /etc/rc.d/rc.nginx # run makestate now to go ahead and generate /var/local/emhttp/nginx.ini /usr/bin/php -f /usr/local/emhttp/plugins/dynamix.my.servers/scripts/makestate &>/dev/null fi if [[ "${version:0:3}" == "6.9" || "${version:0:4}" == "6.10" ]]; then echo echo "✅ Installation is complete, it is safe to close this window" echo else echo echo "✅ Installation is complete" echo fi exit 0 ]]>