]> ###2015.09.21 - Changed start and stop events to "started" and "stopping_svcs" instead of "disks_mounted" and "unmounting_disks" to allow all array and non-array disks to be mounted before creating/using swap file ###2015.09.17 - Add unRAID 6.1 compatibility and keep backward compatibility ###2015.06.07 - Moved plugin icon to "User Utilities" section (unRAID v6) ###2015.06.05 - Added launch option from plugin manager (unRAID v6) - Changed package version to same as plugin version ###2015.04.22 - Added support for unRAID v6 Plugin Manager and Architecture - Changed timeout to 10 seconds for all network connections (was 60 seconds) ###0.5.3 - Added 60 second timeout to all network accesses - Added comment regarding swap file location in WEBUI ###0.5.2 - Fixed bottom of page is sometimes not visible due to unRAID progressframe ###0.5.1 - Fixed division by zero in usage percentage calculation for usage bar ###0.5 - Added existance check before deleting swap file - Cleaned up temporary file. ###0.4.4 - Fixed: Icon file couldn't be saved because plugin folder doesn't exist on first run ###0.4.3 - Fixed: Icon file deleted when upgrading plugin without restarting server ###0.4.1 - Fixed: local plugin version not shown ###0.4 - Workaround for downloading non exiting icon file ###0.3 - Fixed startup sequence - Swap file must be activated only after array mounted ###0.2.1 - Changed SWAP_ENABLE_ON_BOOT default value to "false" ###0.2 - Initial Release logit() { echo "" echo "$1" } DOWNLOAD_PKG="false" INSTALL_PKG="false" logit "Installing plugin..." if [ ! -d "&pluginLOC;" ] ; then logit "Creating plugin folder &pluginLOC;" mkdir -p "&pluginLOC;" else logit "Plugin folder &pluginLOC; already exists" fi logit "Checking existing package &pluginLOC;/&packagefile;..." if [ -f "&pluginLOC;/&packagefile;" ] ; then VBOX_PKG_LOCAL_MD5=$(/usr/bin/md5sum &pluginLOC;/&packagefile; | cut -d' ' -f1) if [ "$VBOX_PKG_LOCAL_MD5" == "&packageMD5;" ] ; then logit "Latest package already exists &pluginLOC;/&packagefile;" INSTALL_PKG="true" else logit "Local/Online package MD5 mismatch ($VBOX_PKG_LOCAL_MD5/&packageMD5;) on &pluginLOC;/&packagefile; - deleting local package" DOWNLOAD_PKG="true" fi else logit "Latest package does not exist &pluginLOC;/&packagefile;" DOWNLOAD_PKG="true" fi if [ "$DOWNLOAD_PKG" == "true" ]; then logit "Saving any previous packages from &pluginLOC;" mkdir -p "/tmp/&name;-packages" TEMP="&pluginLOC;/&name;-package-*" mv -f $TEMP "/tmp/&name;-packages" logit "Attempting to download plugin package &packageURL;..." wget --quiet --spider --no-check-certificate --timeout=10 &packageURL; if [ ! $? == "0" ] ; then logit "Package server down &packageURL; - Plugin cannot install" INSTALL_PKG="false" else wget --quiet --no-check-certificate --timeout=10 -O &pluginLOC;/&packagefile; &packageURL; if [ ! -f "&pluginLOC;/&packagefile;" ] ; then logit "Package download failed &packageURL; - Plugin cannot install" INSTALL_PKG="false" else VBOX_PKG_LOCAL_MD5=$(/usr/bin/md5sum &pluginLOC;/&packagefile; | cut -d' ' -f1) if [ "$VBOX_PKG_LOCAL_MD5" != "&packageMD5;" ] ; then logit "Package MD5 mismatch ($VBOX_PKG_LOCAL_MD5/&packageMD5;) on &pluginLOC;/&packagefile; - Plugin cannot install" INSTALL_PKG="false" else logit "Package &packagefile; downloaded to &pluginLOC; - MD5 match "$VBOX_PKG_LOCAL_MD5"" INSTALL_PKG="true" fi fi fi fi if [ "$INSTALL_PKG" == "true" ] ; then logit "Extracting plugin package..." [ -f "/etc/rc.d/rc.&name;" ] && rm -f "/etc/rc.d/rc.&name;" [ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;" tar -xf "&pluginLOC;/&packagefile;" -C "/" chmod 0770 "&emhttpLOC;/scripts/rc.&name;" ln -s "&emhttpLOC;/scripts/rc.&name;" "/etc/rc.d/rc.&name;" UNRAID_OS_BITS=$(getconf LONG_BIT) echo "Version=\"&version;\"" >> "&emhttpLOC;/&name;.page" if [ "$UNRAID_OS_BITS" == "64" ] ; then echo "Menu=\"Utilities\"" >> "&emhttpLOC;/&name;.page" echo "---" >> "&emhttpLOC;/&name;.page" echo "<?php include '&emhttpLOC;/php/&name;_main.php';?>" >> "&emhttpLOC;/&name;.page" else echo "Menu=\"OtherSettings\"" >> "&emhttpLOC;/&name;.page" mv -f "&emhttpLOC;/images/&name;.png" "&emhttpLOC;" mv -f "&emhttpLOC;/php/&name;_main.php" "&emhttpLOC;/&name;.php" fi if [ ! -f "&pluginLOC;/&name;.cfg" ] ; then logit "Configuration file not found. Creating configuration file..." echo "# SwapFile plugin configuration - Do not modify manually - Change via WEBUI" > "&pluginLOC;/&name;.cfg" fi logit "Checking all configuration file parameters exist" [ ! `cat "&pluginLOC;/&name;.cfg" | grep UPGRADE_PLG_ON_BOOT` ] && echo "UPGRADE_PLG_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg" [ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_ENABLE_ON_BOOT` ] && echo "SWAP_ENABLE_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg" [ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_DELETE` ] && echo "SWAP_DELETE=\"false\"" >> "&pluginLOC;/&name;.cfg" [ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_LOCATION` ] && echo "SWAP_LOCATION=\"/mnt/cache\"" >> "&pluginLOC;/&name;.cfg" [ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_FILENAME` ] && echo "SWAP_FILENAME=\"swapfile\"" >> "&pluginLOC;/&name;.cfg" [ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_NAME` ] && echo "SWAP_NAME=\"UNRAID-SWAP\"" >> "&pluginLOC;/&name;.cfg" [ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_SIZE_MB` ] && echo "SWAP_SIZE_MB=\"2048\"" >> "&pluginLOC;/&name;.cfg" rm -Rf "/tmp/&name;-packages" rm -f "/tmp/&name;-install" logit "Plugin and Package file &packagefile; extracted and installed successfully" exit 0 else if [ -f "&pluginLOC;/&packagefile;" ] ; then rm -f "&pluginLOC;/&packagefile;" fi logit "Reverting back to previously saved packages..." TEMP1="/tmp/&name;-packages" TEMP2=$(ls $TEMP1) if [ "$TEMP2" != "" ] ; then TEMP="/tmp/&name;-packages/&name;-package-*" mv -f $TEMP "&pluginLOC;" logit "Previous packages restored" else logit "No previous packages to restored" fi rm -Rf "/tmp/&name;-packages" rm -f "/tmp/&name;-install" logit "Plugin install failed" exit 1 fi logit() { echo "$1" echo "" } logit "Removing plugin..." [ -f "/tmp/&name;-install" ] && rm -f "/tmp/&name;-install" [ -f "/etc/rc.d/rc.&name;" ] && "/etc/rc.d/rc.&name;" stop [ -f "/etc/rc.d/rc.&name;" ] && rm -f "/etc/rc.d/rc.&name;" [ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;" logit "Plugin stopped and removed - no files removed from &pluginLOC;"