]> ###Development releases - This package includes unstable development branch and should only be used for testing or instructed to do so. - New versioning for devel branch will include hour and minute (YYYY.MM.DD-HHmm) from now on. ###Change Log - The change log will be found in the "master" branch file: --- https://github.com/olehj/disklocation/blob/devel/disklocation-master.plg logit() { echo "" echo "$1" } DOWNLOAD_PKG="false" INSTALL_PKG="false" if [[ -f "/tmp/disklocation/db.lock" ]]; then logit "Existing cronjob is running in the background, retrying every 5 seconds until it finish..." while [ -f "/tmp/disklocation/db.lock" ]; do sleep 5 logit "retrying..." done logit "Done. Continuing plugin installation..." fi logit "Removing old plugin data before installing, if they exists..." [ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;" [ -f "/usr/local/bin/smartlocate" ] && rm -f "/usr/local/bin/smartlocate" [ -f "/tmp/disklocation/db.lock" ] && rm -f "/tmp/disklocation/db.lock" [ -f "/etc/cron.hourly/disklocation.sh" ] && rm -f "/etc/cron.hourly/disklocation.sh" [ -f "/etc/cron.daily/disklocation.sh" ] && rm -f "/etc/cron.daily/disklocation.sh" [ -f "/etc/cron.weekly/disklocation.sh" ] && rm -f "/etc/cron.weekly/disklocation.sh" [ -f "/etc/cron.monthly/disklocation.sh" ] && rm -f "/etc/cron.monthly/disklocation.sh" [ -f "/etc/cron.monthly/disklocation.sh" ] && rm -f "/etc/cron.monthly/disklocation.sh" [ -f "&pluginLOC;/disklocation.noscan" ] && rm -f "&pluginLOC;/disklocation.noscan" [ -f "&pluginLOC;-&branch;/powermode.cron" ] && rm -f "&pluginLOC;-&branch;/powermode.cron" logit "Installing plugin..." if [ ! -d "&pluginLOC;" ] ; then logit "Creating plugin folder &pluginLOC;" mkdir -p "&pluginLOC;" else logit "Plugin folder &pluginLOC; already exists" fi if [ ! -d "&pluginLOC;-&branch;" ] ; then logit "Creating plugin folder &pluginLOC;-&branch;" mkdir -p "&pluginLOC;-&branch;" else logit "Plugin folder &pluginLOC;-&branch; already exists" fi logit "Checking existing package &pluginLOC;/&packagefile;..." if [ -f "&pluginLOC;/&packagefile;" ] ; then INSTALL_PKG="true" 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" TEMPOLD="&pluginLOC;/&name;.*.tar.bz2" TEMP="&pluginLOC;/&name;.*.zip" mv -f $TEMPOLD $TEMP "/tmp/&name;-packages/" logit "Attempting to download plugin package &packageURL;..." wget -O &pluginLOC;/&packagefile; --quiet --no-check-certificate --timeout=30 &packageURL; if [ ! $? == "0" ] ; then logit "Package server down &packageURL; - Plugin cannot install" INSTALL_PKG="false" else if [ ! -f "&pluginLOC;/&packagefile;" ] ; then logit "Package download failed &packageURL; - Plugin cannot install" INSTALL_PKG="false" else logit "Package &packagefile; downloaded to &pluginLOC;" INSTALL_PKG="true" fi fi fi if [ "$INSTALL_PKG" == "true" ] ; then logit "Extracting plugin package..." [ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;" unzip "&pluginLOC;/&packagefile;" -d /tmp/&name;-packages/ mv "/tmp/&name;-packages/&name;-&branch;/&name;" "&emplugLOC;/" if [ -f "&emhttpLOC;/&name;.page" ] ; then echo "Version=\"&version;\"" >> "&emhttpLOC;/&name;.page" logit "Extraction done." EXTRACT_PKG="true" else logit "Extraction failed." EXTRACT_PKG="false" fi fi if [ "$EXTRACT_PKG" == "true" ] ; then logit "Installing files..." cat >/usr/local/bin/smartlocate <<EOL #!/bin/bash # Simple hack to locate harddrives in hotswap arrays, # might not work on all drives or SSD's. # # Run: ./smartlocate [address] # Ex: ./smartlocate 8:0:0:0 # # Check addresses available: ls -l /dev/bsg/ # # Script needs to be interrupted: [CTRL]+[C] # or killed: pkill -f smartlocate # # Made by &author; <ole@gidderikke.no> while sleep 0.5; do pkill -f smartctl &> /dev/null smartctl -x /dev/bsg/\$1 &> /dev/null done EOL chmod +x /usr/local/bin/smartlocate rm -Rf "/tmp/&name;-packages" rm -f "/tmp/&name;-install" php -f &emhttpLOC;/pages/page_system.php backup auto logit "Configuring..." if [ -f "&pluginLOC;/disklocation.conf" ]; then DISKLOCATION_CSS_SIGNALS=($(jq -re '.signal_css // empty' &pluginLOC;/disklocation.conf)) fi if [ -f "&pluginLOC;/settings.json" ]; then DISKLOCATION_CSS_SIGNALS=($(jq -re '.signal_css // empty' &pluginLOC;/settings.json)) fi if [ -z $DISKLOCATION_CSS_SIGNALS ]; then DISKLOCATION_CSS_SIGNALS="signals.dynamic.css" fi ln -s &emhttpLOC;/pages/styles/$DISKLOCATION_CSS_SIGNALS &emhttpLOC;/pages/styles/signals.css logit "Stylesheets: $DISKLOCATION_CSS_SIGNALS activated." logit "Installing cronjob..." cat >&pluginLOC;-&branch;/disklocation.cron <<EOL # Crontab for Disk Location plugin to retrieve SMART data, power status and run backup in the background. 56 */12 * * * php -f &emhttpLOC;/pages/cronjob.php start silent &> /dev/null */5 * * * * php -f &emhttpLOC;/pages/cronjob.php start status silent &> /dev/null */5 * * * * php -f &emhttpLOC;/pages/cronjob.php start syslogread silent &> /dev/null 0 0 * * * php -f &emhttpLOC;/pages/page_system.php backup auto silent &> /dev/null 0 5 1 * * php -f &emhttpLOC;/pages/benchmark.php auto silent &> /dev/null EOL php -f &emhttpLOC;/pages/cronjob.php start status chmod +x &pluginLOC;-&branch;/disklocation.cron UPTIME_DATE=`uptime -s` UPTIME_UNIX=`date --date "$UPTIME_DATE" +%s` UPTIME_SEC=$((`date +%s` - $UPTIME_UNIX)) if [ $UPTIME_SEC -lt 900 ]; then logit "System newly booted, gathering SMART data" php -f &emhttpLOC;/pages/cronjob.php install else logit "Uptime is above 15 minutes: Force SMART must be started manually unless the files already exists." fi /usr/local/sbin/update_cron logit "Plugin 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 OLDTEMP="/tmp/&name;-packages/&name;.*.tar.bz2" TEMP="/tmp/&name;-packages/&name;.*.zip" mv -f $OLDTEMP "&pluginLOC;" 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 "" } if [[ -f "/tmp/disklocation/db.lock" ]]; then logit "Existing cronjob is running in the background, retrying every 5 seconds until it finish..." while [ -f "/tmp/disklocation/db.lock" ]; do sleep 5 logit "retrying..." done logit "Done. Continuing plugin removal..." fi logit "Removing plugin..." [ -f "/tmp/&name;-install" ] && rm -f "/tmp/&name;-install" [ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;" [ -f "/usr/local/bin/smartlocate" ] && rm -f "/usr/local/bin/smartlocate" [ -f "/etc/cron.hourly/disklocation.sh" ] && rm -f "/etc/cron.hourly/disklocation.sh" [ -f "/etc/cron.daily/disklocation.sh" ] && rm -f "/etc/cron.daily/disklocation.sh" [ -f "/etc/cron.weekly/disklocation.sh" ] && rm -f "/etc/cron.weekly/disklocation.sh" [ -f "/etc/cron.monthly/disklocation.sh" ] && rm -f "/etc/cron.monthly/disklocation.sh" [ -f "&pluginLOC;/disklocation.noscan" ] && rm -f "&pluginLOC;/disklocation.noscan" [ -d "/tmp/disklocation" ] && rm -rf "/tmp/disklocation" [ -f "&pluginLOC;-&branch;/powermode.cron" ] && rm -f "&pluginLOC;-&branch;/powermode.cron" [ -f "&pluginLOC;-&branch;/disklocation.cron" ] && rm -f "&pluginLOC;-&branch;/disklocation.cron" [ -d "&pluginLOC;-&branch;" ] && rmdir "&pluginLOC;-&branch;" /usr/local/sbin/update_cron rm -f &pluginLOC;/disklocation.*.tar.bz2 rm -f &pluginLOC;/disklocation.*.zip logit "Plugin stopped and removed, package files removed from &pluginLOC;, database, settings and the backups are not removed."