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

<!DOCTYPE PLUGIN [
<!ENTITY name      "NerdPack">
<!ENTITY author    "dmacias72">
<!ENTITY version   "2016.10.20">
<!ENTITY launch    "Settings/&name;">
<!ENTITY gitURL    "https://raw.githubusercontent.com/&author;/unRAID-plugins/master">
<!ENTITY pluginURL "&gitURL;/plugins/&name;.plg">
<!ENTITY pkgURL    "&gitURL;/source/packages">
<!ENTITY plgPATH   "/boot/config/plugins/&name;">
<!ENTITY plgNAME   "&name;-&version;-x86_64-1">
<!ENTITY emhttp    "/usr/local/emhttp/plugins/&name;">
]>

<PLUGIN name="&name;" author="&author;" version="&version;" launch="&launch;" pluginURL="&pluginURL;">

<CHANGES>
##&name;
###&version;
- fix: php7 compatibility
###2016.10.09
- fix: not creating package directory
###2016.10.08
- fix: false positive of installed packages
- fix: packagemanager bug if cookies are missing 
###2016.09.18
- fix: packagemanager array errors
###2016.09.16
- fix: empty package list on new install or upgrade
- update tablesorter to 2.27.6
###2016.09.10
- add: popup for unRAID version change or empty downloads folder
- add: always compare package checksums
- fix: remove corrupted packages
- fix: remove failed downloads
- fix: add package desc and json to scandir filter
###2016.03.15
- enable apply button if update ready
- fix: remove old package settings from config after package update
- create separate package repos  for 6.1 and 6.2
- update plugin for unRAID 6.2 compatibility
- update packages for 6.2
###2016.02.23
- fix: search for a partial match of packages used in other plugins
###2016.02.17
- remove curl progress bar
- separate plugin depends by comma
- only show update status of selected packages when processing
###2016.02.15
- update tablesorter
- fix spacing of processing messages
- remove array start event package install
- move initial package install to plugin install
###2016.02.08
- fix permissions on event script
###2016.02.02
- add check for other plugin dependencies on uninstall
###2016.01.25
- Merge eschultz pull request
- tweaks to tablesorter to restore saved filters
- minor optimizations
###2016.01.24
- Merged eschultz's package repo and following fixes
- Fixed first time running warnings about missing packages.json / desc files
- Fixed bug preventing Select All from being toggle-able
- Fixed bug in Select All and dependent package checkboxes / race condition
- Eliminated vertical space gap between page header and table
###2016.01.16a
- add metric parser to sort units
###2016.01.16
- minor diplay changes
- add tablesorter as a separate package
###2016.01.15
- fix filter save
- add filter reset button
###2016.01.10a-c
- fix name of package description file
###2016.01.10
- added dynamic package description tootips
- updated tablesorter to v2.25.0
- add tablesorter widgets (filter, saveSort, stickyHeaders, hover-highlight)
- added cli options to packagemanager script
###2015.12.30
- create packages directory on install
###2015.12.15a
- remove command output
###2015.12.15
- minor fixes
###2015.12.14
- add update functions
- add delete package function
- fix some minor bugs
###2015.12.13
- initial commit of wrapper plugin for packages in repo
###2015.12.07
- Added perl 5.22.0
- Added vim 7.4.898 (thanks Ryan Detzel)

###2015.09.09
- Keep all packages installed after NerdPack uninstall so we don't break other plugin's dependancies. (thanks David Coppit)

###2015.08.09
- Added p7zip 9.38.1

###2015.07.31
- Added iperf 3.0.11

###2015.06.27
- Added sshfs 2.5

###2015.06.23
- Added python 2.7.9 (fixes iotop dependency)

###2015.05.16
- Added subversion 1.7.16
- Added MD5 checks for all packages

###2015.05.15
- Added lftp 4.6.1
- Replaced installpkg with upgradepkg to allow package upgrading
- Added removal of packages upon uninstall of NerdPack

###2015.04.29
- Added git 2.3.5

###2015.04.24
- Added strace 4.10

###2015.04.23
- Added bwm-ng 0.6

###2015.02.07
- Added unrar 5.2.5

###2015.01.06
- Inital release. includes:
 - iftop 1.0pre2
 - iotop 0.6
 - screen 4.2.1
 - lshw B.02.17
 - kbd 1.15.3
 - inotify-tools 3.14
 - cpio 2.11
</CHANGES>

<!--
The 'tablesorter' package file.
-->
<FILE Name="/boot/config/plugins/tablesorter/tablesorter-2.27.6-x86_64-1.txz" Run="/sbin/upgradepkg --install-new">
<URL>&gitURL;/archive/tablesorter-2.27.6-x86_64-1.txz</URL>
<MD5>ead9fb4c4a317e7d6426b3521f0e0c0b</MD5>
</FILE>

<FILE Name="&plgPATH;/&name;.cfg">
<INLINE>
<![CDATA[

]]>
</INLINE>
</FILE>

<!--
The 'plugin' package file.
-->
<FILE Name="&plgPATH;/&plgNAME;.txz">
<URL>&gitURL;/archive/&plgNAME;.txz</URL>
</FILE>

<!--
The 'plugin' package MD5 hash.
-->
<FILE Name="&plgPATH;/&plgNAME;.md5">
<URL>&gitURL;/archive/&plgNAME;.md5</URL>
</FILE>

<!--
The 'install' script.
-->
<FILE Run="/bin/bash" Method="install">
<INLINE>
#Verify unRAID Version
source /etc/unraid-version
VER=${version:0:3}
if [[ $VER == 6.0 ]]; then
  echo "unRAID version 6.1 or higher is required"
  exit 1
fi

# Verify and install plugin package
sum1=$(/usr/bin/md5sum &plgPATH;/&plgNAME;.txz)
sum2=$(/usr/bin/cat &plgPATH;/&plgNAME;.md5)
if [ "${sum1:0:32}" != "${sum2:0:32}" ]; then
    echo "Wrong 'plugin' package md5 hash."
    rm &plgPATH;/&plgNAME;.txz \
        &plgPATH;/&plgNAME;.md5
    exit 1
else
    count=`ls -1 /boot/config/plugins/NerdPack/packages/*.txz 2>/dev/null | wc -l`
    if [ $count != 0 ]; then
        if [ ! -d &plgPATH;/packages/6.1 ]; then
            mkdir -p &plgPATH;/packages/6.1
        fi
        echo "Moving package files..."
        mv  &plgPATH;/packages/*txz  &plgPATH;/packages/6.1
    fi

    if [[ $VER == 6.3 ]]; then
        if [ ! -d &plgPATH;/packages/$VER ]; then
            mkdir -p &plgPATH;/packages/$VER
            if [ -d &plgPATH;/packages/6.2 ]; then
                count2=`ls -1 /boot/config/plugins/NerdPack/packages/6.2/*.txz 2>/dev/null | wc -l`
                if [ $count2 != 0 ]; then
                    echo "Copying package files..."
                    cp &plgPATH;/packages/6.2/* &plgPATH;/packages/$VER/
                fi
            fi
        fi
    fi

    if [ ! -d &plgPATH;/packages/$VER ]; then
        mkdir -p &plgPATH;/packages/$VER
    fi

    upgradepkg --install-new &plgPATH;/&plgNAME;.txz

    /usr/sbin/packagemanager

    # Cleaning old source files
    find &plgPATH;/ -type f -iname "&name;*.txz" ! -iname "*&version;*" -delete
    find &plgPATH;/ -type f -iname "&name;*.md5" ! -iname "*&version;*" -delete

echo ""
echo "-----------------------------------------------------------"
echo " &name; has been installed."
echo " This plugin requires Dynamix webGui to operate"
echo " Copyright 2016, &author;, eschultz"
echo " Version: &version;"
echo "-----------------------------------------------------------"
echo ""
fi
</INLINE>
</FILE>

<!--
The 'remove' script.
-->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
removepkg &plgPATH;/&plgNAME;.txz
rm -rf &emhttp;
rm -f &plgPATH;/&plgNAME;.txz
rm -f &plgPATH;/&plgNAME;.md5

echo ""
echo "-----------------------------------------------------------"
echo " &name; has been removed."
echo " Copyright 2016, &author;, eschultz"
echo " Version: &version;"
echo "-----------------------------------------------------------"
echo ""
</INLINE>
</FILE>

</PLUGIN>