<?xml version='1.0' standalone='yes'?>

<!DOCTYPE PLUGIN [
<!ENTITY name      "unRAIDServer">
<!ENTITY author    "LimeTech">
<!ENTITY version   "6.12.10">
<!ENTITY kernel    "6.1.79-Unraid">
<!ENTITY category  "stable">
<!ENTITY pluginURL "https://stable.dl.unraid.net/unRAIDServer.plg">
<!ENTITY zip       "https://stable.dl.unraid.net/6.12.10/2c9f5b4333711eb5b0739b8597cfc70a41144ae785d09276b87b14ee9ebee585/unRAIDServer-6.12.10-x86_64.zip">
<!ENTITY md5       "https://stable.dl.unraid.net/6.12.10/2c9f5b4333711eb5b0739b8597cfc70a41144ae785d09276b87b14ee9ebee585/unRAIDServer-6.12.10-x86_64.md5">
<!ENTITY files     "bz*,make_bootable.bat,make_bootable_linux,make_bootable_mac,memtest,changes.txt,license.txt,syslinux/syslinux.cfg-">

<!ENTITY infozip   "infozip-6.0-i486-1.txz">
]>

<PLUGIN  name="&name;"
         author="&author;"
         version="&version;"
         category="&category;"
         kernel="&kernel;"
         pluginURL="&pluginURL;">

<CHANGES>
<![CDATA[
# Version 6.12.10 2024-04-03

Please see the: [6.12.10 release notes](https://docs.unraid.net/unraid-os/release-notes/6.12.10/)
]]>
</CHANGES>

<!--
Be compatible with unRAID-5 installplg
-->
<FILE Name="/tmp/&name;.sh" Run="/bin/bash">
<INLINE>
rm /tmp/&name;.sh
# cleanup possibly failed previous download/install attempt
rm -rf /tmp/&name;*
mkdir /tmp/&name;
# check if this is unRAID-5
source /etc/unraid-version
if [[ "${version:0:2}" == "5." ]]; then
  # prevent endless install loop
  rm -rf /boot/plugins/&name;.plg
  rm -rf /boot/config/plugins/&name;.plg
  # check if 64-bit capable CPU
  if ! grep -q " lm" /proc/cpuinfo ; then
    echo "CPU is not 64-bit capable"
    exit 1
  fi
  # Wait until network is ready by pinging google - thanks bonienl!
  ip=8.8.4.4
  timer=30
  while [[ $timer -gt 0 ]]; do
    if [[ -n $(route -n|awk '/^0.0.0.0/{print $2}') &amp;&amp; $(ping -qnc1 $ip|awk '/received/{print $4}') -eq 1 ]]; then
      break
    fi
    ((timer--))
    sleep 1
  done
  if [[ $timer -eq 0 ]]; then
    echo "No network communication !!!"
    exit 1
  fi
  # unRAID-5 needs infozip
  if [ ! -f /boot/extra/&infozip; ]; then
    echo "Downloading &infozip; package"
    mkdir -p /boot/extra
    wget http://slackware.cs.utah.edu/pub/slackware/slackware-13.1/slackware/a/&infozip; -O /boot/extra/&infozip;
    upgradepkg --install-new /boot/extra/&infozip;
  fi
  # download the release
  if ! wget --no-check-certificate &zip; -O /tmp/&name;.zip ; then
    echo "&zip; download error $?"
    exit 1
  fi
  if ! wget --no-check-certificate &md5; -O /tmp/&name;.md5 ; then
    echo "&md5; download error $?"
    exit 1
  fi
fi
</INLINE>
</FILE>

<!--
Download release from S3
For unRAID-5 this will be skipped because already downloaded above
For unRAID-6 we download here, verifying certificiate
-->
<FILE Name="/tmp/&name;.zip">
<URL>&zip;</URL>
</FILE>
<FILE Name="/tmp/&name;.md5">
<URL>&md5;</URL>
</FILE>

<FILE Name="/tmp/&name;.sh" Run="/bin/bash">
<INLINE>
rm /tmp/&name;.sh
# check download and extract
sum1=$(/usr/bin/md5sum /tmp/&name;.zip)
sum2=$(cat /tmp/&name;.md5)
if [[ "${sum1:0:32}" != "${sum2:0:32}" ]]; then
  echo "wrong md5"
  exit 1
fi
# check if enough free space on flash
have=$(df -B1 /boot | awk 'END {print $4}')
need=$(unzip -l /tmp/&name;.zip | awk 'END {print $1}')
source /etc/unraid-version
if [[ "${version:0:2}" == "5." ]]; then
  # to permit another upgrade
  need=$(($need * 2))
fi
if [[ $need -gt $have ]]; then
  echo "boot device shows $have free but upgrade needs $need"
  exit 1
fi
# detect if Plugin-Update-Helper for third party driver plugins is running and update it
plg_update_helper=$(ps aux | grep -E "inotifywait -q /boot/changes.txt -e move_self,delete_self" | grep -v "grep -E inotifywait" | awk '{print $2}')
if [ ! -z "${plg_update_helper}" ]; then
  echo "Plugin-Update-Helper for 3rd party driver plugins found, updating..."
  kill ${plg_update_helper} 2>/dev/null
  wget -q -T 5 -O /usr/bin/plugin_update_helper "https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper"
  chmod +x /usr/bin/plugin_update_helper 2>/dev/null
  echo "/usr/bin/plugin_update_helper" | at now > /dev/null 2>&amp;1
fi
# move release files to flash
echo
echo "writing flash device - please wait..."
mkdir -p /boot/&name;
rm -rf /boot/&name;/*
files=&files;
unzip -d /boot/&name; /tmp/&name;.zip ${files//,/ } || exit 1
# ensure writes to USB flash boot device have completed and bz*.sha256 matches
sync -f /boot ; echo 3 > /proc/sys/vm/drop_caches
for sha in /boot/&name;/*.sha256; do
  file=${sha%.sha256}
  echo "checking sha256 on ${file}"
  sha256expect=$(cat "${sha}")
  sha256actual=$(/usr/bin/sha256sum "${file}")
  if [[ "${sha256actual:0:64}" != "${sha256expect:0:64}" ]]; then
    echo "*** bad sha256 on ${file}"
    badsha256="yes"
  fi
done
if [[ -v badsha256 ]]; then
  echo "***"
  echo "*** The upgrade failed, but no changes were made to your configuration."
  echo "*** Your USB Flash is likely failing."
  echo "***"
  exit 1
fi
# preserve previous version
source /etc/unraid-version
if [[ "${version:0:2}" == "5." ]]; then
  mkdir -p /boot/unRAID5
  rm -rf /boot/unRAID5/*
  # preserve all files in root of flash except ldlinux.sys needed to boot
  find /boot -maxdepth 1 -type f -not -name ldlinux.sys -exec mv {} /boot/unRAID5 \;
  # preserve a few directories
  mv /boot/extra /boot/unRAID5 &amp;&gt; /dev/null
  mv /boot/packages /boot/unRAID5 &amp;&gt; /dev/null
  mv /boot/plugins /boot/unRAID5 &amp;&gt; /dev/null
  mkdir /boot/unRAID5/config
  mv /boot/config/plugins /boot/unRAID5/config &amp;&gt; /dev/null
  # grab a fresh 'go' file
  mv /boot/config/go /boot/unRAID5/config
  unzip -d /boot /tmp/&name;.zip config/go || exit 1
  # ensure key file is in the 'config' directory
  cp /boot/unRAID5/*.key /boot/config &amp;&gt; /dev/null
else
  mkdir -p /boot/previous
  # check for earlier upgrade without reboot
  if ! /sbin/mount | grep -q "/boot/previous/bz" ; then
    rm -rf /boot/previous/*
    mv /boot/{&files;} /boot/previous  &amp;&gt; /dev/null
  fi
fi
# capture the current hardware list
/sbin/lspci -nnmm > /boot/previous/hardware
# move new version files into place
mv /boot/&name;/{&files;} /boot
rm -r /boot/&name;
# Unraid-6/7 specific
if [[ "${version:0:2}" == "6." || "${version:0:2}" == "7." ]]; then
  # replace the readme file
  echo "**REBOOT REQUIRED!**" &gt; /usr/local/emhttp/plugins/&name;/README.md
  # update pre-6.12.2 wireguard configuration files
  if [[ $(php -r "echo version_compare('$version', '6.12.2');") -lt 0 ]]; then
    for wg in /boot/config/wireguard/*.conf; do
      sed -ri "s/^(Post(Up|Down)=logger -t wireguard .*(started|stopped)).*/\1';\/usr\/local\/emhttp\/webGui\/scripts\/update_services/" $wg
    done
  fi
  # when upgrading any version prior to 6.10
  if [[ $(php -r "echo version_compare('$version', '6.10');") -lt 0 ]]; then
    if [[ -f /boot/config/ssl/certs/certificate_bundle.pem ]]; then
      if grep -q 'USE_SSL="no"' /boot/config/ident.cfg &amp;&gt; /dev/null ; then
        rm /boot/config/ssl/certs/certificate_bundle.pem
      else
        sed -i 's|USE_SSL="auto"|USE_SSL="yes"|g' /boot/config/ident.cfg
      fi
    else
      sed -i 's|USE_SSL="auto"|USE_SSL="no"|g' /boot/config/ident.cfg
    fi
  fi
fi
# if Unraid-6.3 ensure GUI Safe Mode syslinux option exists
if [[ "${version:0:3}" == "6.3" ]]; then
  if ! grep -q 'initrd=/bzroot,/bzroot-gui unraidsafemode' /boot/syslinux/syslinux.cfg &amp;&gt; /dev/null ; then
    sed -i 's|label Memtest86+|label unRAID OS GUI Safe Mode (no plugins)\r\n  kernel /bzimage\r\n  append initrd=/bzroot,/bzroot-gui unraidsafemode\r\nlabel Memtest86+|g' /boot/syslinux/syslinux.cfg &amp;&gt; /dev/null
  fi
fi
# when upgrading any version prior to 6.2
if [[ "${version:0:3}" &lt; "6.2" ]]; then
  if ! grep -q '/bzroot-gui' /boot/syslinux/syslinux.cfg &amp;&gt; /dev/null ; then
    sed -i 's|menu title Lime Technology\r|menu title Lime Technology, Inc.\r|g' /boot/syslinux/syslinux.cfg &amp;&gt; /dev/null
    sed -i 's|label unRAID OS Safe Mode (no plugins)|label unRAID OS GUI Mode\r\n  kernel /bzimage\r\n  append initrd=/bzroot,/bzroot-gui\r\nlabel unRAID OS Safe Mode (no plugins, no GUI)|g' /boot/syslinux/syslinux.cfg &amp;&gt; /dev/null
  fi
fi
# when upgrading any version prior to 6.1
if [[ "${version:0:3}" &lt; "6.1" ]]; then
  if ! grep -q 'shareDisk' /boot/config/share.cfg &amp;&gt; /dev/null ; then
    echo 'shareDisk="yes"' &gt;&gt; /boot/config/share.cfg
  fi
fi
# when upgrading from 6.0.x
if [[ "${version:0:3}" == "6.0" ]]; then
  sed -i 's|dynamix.docker.manager/dockerupdate.php|dynamix.docker.manager/scripts/dockerupdate.php|g' /boot/config/plugins/dynamix/docker-update.cron &amp;&gt; /dev/null
  sed -i 's|sbin/monitor|emhttp/plugins/dynamix/scripts/monitor|g' /boot/config/plugins/dynamix/monitor.cron &amp;&gt; /dev/null
  sed -i 's|/root/mdcmd|/usr/local/sbin/mdcmd|g' /boot/config/plugins/dynamix/parity-check.cron &amp;&gt; /dev/null
  sed -i 's|sbin/plugincheck|emhttp/plugins/dynamix.plugin.manager/scripts/plugincheck|g' /boot/config/plugins/dynamix/plugin-check.cron &amp;&gt; /dev/null
  sed -i 's|sbin/statuscheck|emhttp/plugins/dynamix/scripts/statuscheck|g' /boot/config/plugins/dynamix/status-check.cron &amp;&gt; /dev/null
fi
# if template-repos does not exist
if [[ ! -e /boot/config/plugins/dockerMan/template-repos ]]; then
  mkdir -p /boot/config/plugins/dockerMan
  echo "https://github.com/limetech/docker-templates" &gt; /boot/config/plugins/dockerMan/template-repos
fi
# if EFI or EFI- directory does not exist
if [[ ! -e /boot/EFI &amp;&amp; ! -e /boot/EFI- ]]; then
  unzip -d /boot /tmp/&name;.zip EFI-/* || exit 1
  sed -i 's|default /syslinux/menu.c32|default menu.c32|g' /boot/syslinux/syslinux.cfg &amp;&gt; /dev/null
fi
# if metric appended to GATEWAY get rid of it
if [[ -f /boot/config/network.cfg ]]; then
  sed -ri 's|^(GATEWAY.+)#[0-9]+|\1|' /boot/config/network.cfg
fi
# if legacy dynamix.plg file exists, delete it
rm -f /boot/config/plugins/dynamix.plg
# ensure writes to USB flash boot device have completed
sync -f /boot
if [ -z "${plg_update_helper}" ]; then
  echo "Update successful - PLEASE REBOOT YOUR SERVER"
else
  echo "Third party plugins found - PLEASE CHECK YOUR UNRAID NOTIFICATIONS AND WAIT FOR THE MESSAGE THAT IT IS SAFE TO REBOOT!"
fi
</INLINE>
</FILE>

<!--
The 'remove' script.
-->
<FILE Name="/tmp/&name;.sh" Run="/bin/bash" Method="remove">
<INLINE>
rm /tmp/&name;.sh
# unRAID-5 doesn't support 'remove' method, so we're done
source /etc/unraid-version
if [[ "${version:0:2}" == "5." ]]; then
  exit 0
fi
if [[ -d /boot/previous ]]; then
  # restore previous Unraid-6 release
  rm -f /boot/previous/hardware
  mv /boot/previous/* /boot
  rmdir /boot/previous
  echo "**REBOOT REQUIRED!**" &gt; /usr/local/emhttp/plugins/&name;/README.md
elif [[ -d /boot/unRAID5 ]]; then
  # restore previous unRAID-5 release
  rm -rf /boot/extra
  mv /boot/unRAID5/extra /boot &amp;&gt; /dev/null
  rm -rf /boot/plugins
  mv /boot/unRAID5/plugins /boot &amp;&gt; /dev/null
  rm -rf /boot/packages
  mv /boot/unRAID5/packages /boot &amp;&gt; /dev/null
  rm -rf /boot/config/plugins
  mv /boot/unRAID5/config/plugins /boot/config &amp;&gt; /dev/null
  mv /boot/unRAID5/config/go /boot/config
  rmdir /boot/unRAID5/config
  mv /boot/unRAID5/* /boot
  rmdir /boot/unRAID5
else
  echo "Cannot remove, no previous version"
  exit 1
fi
echo "syncing..."
sync
echo "Remove successful - PLEASE REBOOT YOUR SERVER"
</INLINE>
</FILE>

</PLUGIN>
