diff --git a/plugins/NerdPack.plg b/plugins/NerdPack.plg new file mode 100644 index 00000000..78918812 --- /dev/null +++ b/plugins/NerdPack.plg @@ -0,0 +1,146 @@ + + + + + + + + + + + + + +]> + + + + +###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 &name; + +###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 + + + + +&gitURL;/archive/&plgname;.txz + + + + +&gitURL;/archive/&plgname;.md5 + + + + + +if [ ! -d &emhttp; ]; then + mkdir -p &emhttp; +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 + upgradepkg --install-new &plgpath;/&plgname;.txz +fi + +# Update file permissions of scripts +chmod +0755 &emhttp;/scripts/* + +# 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 2015, &author;, eschultz" +echo " Version: &version;" +echo "-----------------------------------------------------------" +echo "" + + + + + + +removepkg &plgpath;/&plgname;.txz \ + &plgpath;/&pkg; +rm -rf &emhttp; \ + -rf &plgpath; + +echo "" +echo "-----------------------------------------------------------" +echo " &name; has been removed." +echo " Copyright 2015, &author;, eschultz" +echo " Version: &version;" +echo "-----------------------------------------------------------" +echo "" + + + + diff --git a/plugins/NerdPack.png b/plugins/NerdPack.png new file mode 100644 index 00000000..6044749c Binary files /dev/null and b/plugins/NerdPack.png differ diff --git a/source/NerdPack/install/doinst.sh b/source/NerdPack/install/doinst.sh new file mode 100644 index 00000000..1a248525 --- /dev/null +++ b/source/NerdPack/install/doinst.sh @@ -0,0 +1 @@ +#!/bin/sh diff --git a/source/NerdPack/install/slack-desc b/source/NerdPack/install/slack-desc new file mode 100644 index 00000000..53dca856 --- /dev/null +++ b/source/NerdPack/install/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. +# Line up the first '|' above the ':' following the base package name, and +# the '|' on the right side marks the last column you can put a character in. +# You must make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + + |-----handy-ruler------------------------------------------------------| +nerdapck: Nerd Tools unRAID Plugin +nerdpack: +nerdpack: unRAID plugin wrapper for extra packages, mostly CLI, for advanced +nerdpack: users. Use at your own risk. Not officially supported by LimeTech. +nerdpack: +nerdpack: Supports: apr, apt-util, bwm-ng, cpio, git, iftop, inotify, iotop, +nerdpack: iperf, kbd, lftp, lshw, neon, p7zip, perl, python, readline, screen, +nerdpack: sshfs-fuse, strace, subversion, unrar, utempter, vim +nerdpack: +nerdpack: plugin: https://github.com/dmacias72/unRAID-plugins +nerdpack: packages: https://github.com/eschultz/unraid6-nerdpack diff --git a/source/NerdPack/pkg_build.sh b/source/NerdPack/pkg_build.sh new file mode 100755 index 00000000..68a24194 --- /dev/null +++ b/source/NerdPack/pkg_build.sh @@ -0,0 +1,37 @@ +#!/bin/bash +DIR="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")" +tmpdir=/tmp/tmp.$(( $RANDOM * 19318203981230 + 40 )) +plugin=$(basename ${DIR}) +archive="$(dirname $(dirname ${DIR}))/archive" +version=$(date +"%Y.%m.%d") +package="${archive}/${plugin}-${version}-x86_64-1.txz" +md5="${archive}/${plugin}-${version}-x86_64-1.md5" + +if [[ -f $package ]]; then + for x in a b c d e d f g h ; do + package="${archive}/${plugin}-${version}${x}-x86_64-1.txz" + md5="${archive}/${plugin}-${version}${x}-x86_64-1.md5" + if [[ ! -f $package ]]; then + break + fi + done +fi + +mkdir -p $tmpdir +cd "$DIR" +cp --parents -f $(find . -type f ! \( -iname "pkg_build.sh" -o -iname "sftp-config.json" -o -iname ".DS_Store" \) ) $tmpdir/ +cd "$tmpdir/" +makepkg -l y -c y "${package}" +cd "$archive/" +md5sum $(basename "$package") > "$md5" +rm -rf "$tmpdir" + +# Verify and install plugin package +sum1=$(md5sum "${package}") +sum2=$(cat "$md5") +if [ "${sum1:0:32}" != "${sum2:0:32}" ]; then + echo "Checksum mismatched."; + rm "$md5" "${package}" +else + echo "Checksum matched." +fi \ No newline at end of file diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page new file mode 100644 index 00000000..f4ff52a3 --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page @@ -0,0 +1,38 @@ +Icon="NerdPack.png" +Menu="NetworkServices" +Title="Nerd Pack" +--- + + + + +
+ + + + + + + + + + + + + + +
Name Version Size (kB) Downloaded Installed
+ +  +: +
+ + + diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/README.md b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/README.md new file mode 100644 index 00000000..f6abc852 --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/README.md @@ -0,0 +1,5 @@ +**Nerd Tools** + +Extra packages, mostly CLI, for advanced users. Use at your own risk. Not officially supported by LimeTech. + +Contains: iftop, iotop, screen, lshw, kbd, inotify-tools, cpio, unrar, bwm-ng, strace, git, lftp, subversion, python, sshfs, iperf, p7zip diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/event/started b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/event/started new file mode 100755 index 00000000..653b888e --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/event/started @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/icons/NerdPack.png b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/icons/NerdPack.png new file mode 100644 index 00000000..96cbbd40 Binary files /dev/null and b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/icons/NerdPack.png differ diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/images/NerdPack.png b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/images/NerdPack.png new file mode 100644 index 00000000..6044749c Binary files /dev/null and b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/images/NerdPack.png differ diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php new file mode 100644 index 00000000..4b4fd248 --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php @@ -0,0 +1,76 @@ + $previousProgress){ + $previousProgress = $progress; + + $pct=(double)($progress/100); + + $bar=round($pct * 30); + + $pct_disp=number_format($pct * 100, 0); + + $status_bar="\r["; + $status_bar.=str_repeat("|", $bar); + if($bar < 30){ + $status_bar.=">"; + $status_bar.=str_repeat("-", 30 - $bar); + } else { + $status_bar.="|"; + } + + $status_bar.="] $pct_disp%"; + + echo $status_bar; + + flush(); + + if($progress == 100) { + echo "\n"; + } + } + flush(); +} + +function get_file_from_url($file, $url) { + flush(); + $chfile = fopen($file, 'w'); + $ch = curl_init(); + $ch_vers = curl_version(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 3600); + curl_setopt($ch, CURLOPT_NOPROGRESS, false ); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . $ch_vers['version'] ); + curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progressBar' ); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FILE, $chfile ); + curl_exec($ch); + curl_close($ch); + fclose($chfile); + flush(); +} + +function get_content_from_github($repo, $file){ + flush(); + $ch = curl_init(); + $ch_vers = curl_version(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); + curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . $ch_vers['version'] ); + curl_setopt($ch, CURLOPT_URL, $repo); + $content = curl_exec($ch); + curl_close($ch); + if (!empty($content)) + file_put_contents($file, $content); + flush(); +} +?> diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageDownload.php b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageDownload.php new file mode 100644 index 00000000..e0ed5550 --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageDownload.php @@ -0,0 +1,46 @@ + diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php new file mode 100644 index 00000000..cf744e3b --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php @@ -0,0 +1,53 @@ + 4){ //if package name has a subset get it + for ($ii = 1; $ii < sizeof($pkg_NameArray)-3; $ii++) { + $pkg_Name = $pkg_Name."-".$pkg_NameArray[$ii]; + } + } + + $pkg_version = $pkg_NameArray[sizeof($pkg_NameArray)-3]; // get package version + + $pkg_nver = $pkg_Name."-".str_replace(".", "_", $pkg_version); // add underscored version to package name + + $pkg = array(); + + $pkg["name"] = $pkgs_github[$i]["name"]; // add full package name + + $pkg["pkgname"] = $pkg_Name; // add package name only + + $pkg["pkgnver"] = $pkg_nver; // add package name with underscored version + + $pkg["size"] = $pkgs_github[$i]["size"]; // add package size + + $pkg["installed"] = in_array( pathinfo($pkgs_github[$i]["name"], PATHINFO_FILENAME), $pkgs_installed ) ? "yes" : "no"; // checks if package is installed + + $pkg["downloaded"] = in_array( $pkgs_github[$i]["name"], $pkgs_downloaded ) ? "yes" : "no"; // checks if package is downloaded + + $pkg["config"] = isset($pkg_cfg["$pkg_nver"]) ? $pkg_cfg["$pkg_nver"] : "no"; // checks config for install preference + + $pkgs_array[] = $pkg; +} + +echo json_encode($pkgs_array); +?> \ No newline at end of file diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageUpdate.php b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageUpdate.php new file mode 100644 index 00000000..220de3db --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageUpdate.php @@ -0,0 +1,38 @@ + diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js new file mode 100644 index 00000000..1dbff1b5 --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js @@ -0,0 +1,215 @@ +$(function(){ + //tablesorter options + $('#tblPackages').tablesorter({headers:{5:{sorter:false}}}); + + // "uninstall package" switch and cookie + $('#removepkg') + .switchButton({ + labels_placement: "right", + on_label: 'uninstall packages On', + off_label: 'uninstall packages Off', + checked: $.cookie('nerdpack_packages') == 'remove' + }) + .change(function () { + $.cookie('nerdpack_packages', $('#removepkg').prop('checked') ? 'remove' : 'donotremove', { expires: 3650 }); + }); + + // select all packages switch + $('#checkall') + .switchButton({ + labels_placement: "right", + on_label: 'select all', + off_label: ' select all', + checked: $.cookie('nerdpack_checkall') == 'yes' + }) + .change(function() { //on change + if(this.checked) { // check select status + $('.pkgcheckbox').each(function() { //loop through each checkbox + $(this).switchButton({checked: true}); + }); + $('.pkgvalue').each(function() { //loop through each value + $(this).val('yes'); + }); + }else{ + $('.pkgcheckbox').each(function() { //loop through each checkbox + $(this).switchButton({checked: false}); + }); + $('.pkgvalue').each(function() { //loop through each value + $(this).val('no'); + }); + } + }); + + // set cookie on apply button press + $('#btnApply').click(function(event) { + $.cookie('nerdpack_checkall', $('#checkall').prop('checked') ? 'yes' : 'no', { expires: 3650 }); + packageManager(); + }); + + packageQuery(); +}); + +function packageManager() { + $.ajax({ + type : "POST", + url : "/update.php", + data : $('#package_form').serializeArray(), + success: function() { + openBox('/plugins/NerdPack/scripts/packagemanager&arg1=webgui&arg2='+$.cookie('nerdpack_packages'),'Install Packages',490,430,true); + } + }); +}; + +//list all available packages in a table +function packageQuery() { + $.ajax({ + type: "GET", + dataType: "json", + url: "/plugins/NerdPack/include/PackageQuery.php", + success: function(data) { + if (data.length > 1){ + for( i in data ) { + $("#tblPackages tbody").append( + ""+ + ""+data[i].name+""+ //package name + ""+ //package status + ""+(data[i].size / 1000).toFixed(0)+""+ //package size + ""+data[i].downloaded+""+ //package installed + ""+data[i].installed+""+ //package installed + ""+ + ""+ + ""); + $('#'+data[i].pkgname) + .switchButton({ + labels_placement: 'right', + on_label: 'On', + off_label: 'Off', + checked: data[i].config == "yes" + }) + .change(function() { + var par = $(this).parent().parent(); + if(this.checked) + par.find('.pkgvalue').val("yes"); + else + par.find('.pkgvalue').val("no"); + $("#btnApply").prop("disabled", false); + checkDepends(); + }); + } + }else { + $("#tblPackages tbody").append( + ""+ + ""+ + ""); + + } + }, + complete : function () { + $("#tblPackages").trigger("update"); + packageCheck() + }, + error: function () { + } + }); +}; + +// check github for newer package and report status +function packageCheck() { + $.ajax({ + type: "GET", + url: "/boot/config/plugins/NerdPack/packages.json", + dataType: "json", + success: function(data) { + $('#tblPackages tbody tr').each(function(row, tr) { + var tblPackage = $(tr).children("td:nth-child(1)").html(); + var tblName = $(tr).children("td:nth-child(6)").find('.pkgcheckbox').attr("id"); + for( i in data ) { + var Package = data[i].name; + var pkgNameArray = Package.split('-'); + var pkgName = pkgNameArray[0]; + if (pkgNameArray.length > 4){ + for( var ii = 1; ii < pkgNameArray.length-3; ii++ ) { + pkgName = pkgName+"-"+pkgNameArray[ii]; + } + } + if ( tblName == pkgName){ + if (tblPackage == Package) + var Update = " up-to-date"; + else + var Update = " update ready"; + } + } + $(tr).children("td:nth-child(2)").html(Update); + }); + + }, + complete : function () { + $("#tblPackages").trigger("update"); + }, + error: function () { + } + }); +}; + +// update packages +function packageUpdate(pkgName, pkgOld, pkgNew, pkgSha) { + $.ajax({ + type: "POST", + dataType: "json", + url: "/plugins/NerdPack/include/PackageUpdate.php", + data: {pkgname: pkgName, pkgold: pkgOld, pkgnew: pkgNew, pkgsha: pkgSha}, + success: function(data) { + alert(data); + }, + complete : function () { + //location.reload(); + }, + error: function () { + } + }); +}; + +function downloadPackages() { + $.ajax({ + type: "POST", + url: "/plugins/NerdPack/include/PackageDownload.php", + dataType: "json", + success: function(data) { + for( i in data ) { + packageUpdate(null,null,data[i].name,data[i].sha); + } + }, + complete : function () { + $("#tblPackages").trigger("update"); + }, + error: function () { + } + }); +}; + + +function checkDepends() { + if ($('#screen').prop('checked') == true){ + $('#utempter').switchButton({checked: true}); + $('#utempter','.pkgvalue').val('yes'); + } + if ($('#iotop').prop('checked') == true){ + $('#python').switchButton({checked: true}); + $('#python','.pkgvalue').val('yes'); + } +}; + +// check github for newer package and report status +function getPackages() { + $.ajax({ + type: "GET", + url: "https://api.github.com/repos/eschultz/unraid6-nerdpack/contents/packages", + dataType: "json", + success: function(data) { + }, + complete : function () { + }, + error: function () { + } + }); +}; \ No newline at end of file diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager new file mode 100755 index 00000000..46c00cfa --- /dev/null +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager @@ -0,0 +1,111 @@ +#!/usr/bin/php -q + $pkg_pref) { //get preferences for each package + + $pkg_cmd = ''; + + $pkg_name = str_replace("_", ".", $pkg_name); // replace "_" with "." in package names + + $pkg_pattern = "/^".$pkg_name.".*/"; // search patter for packages + + $pkg_install_status = preg_grep($pkg_pattern, $pkgs_installed); // check install status + + if($pkg_pref == "yes" && !$pkg_install_status){ + + //if executing from the wegui check status and download if necessary + if ($argv[1] == "webgui"){ + + if(!preg_grep($pkg_pattern , $pkgs_downloaded)) { + + $pkg_online_status = preg_grep($pkg_pattern , $pkgs_github); + + $pkg_matches = array_filter($pkgs_github, function($a) use($pkg_pattern ) { + return preg_grep($pkg_pattern , $a); + }); + + $pkg_gitname = array_values($pkg_matches)[0]["name"]; + + $pkg_file = $pkg_path.$pkg_gitname; + + $pkg_url = array_values($pkg_matches)[0]["download_url"]; + + $pkg_sha = array_values($pkg_matches)[0]["sha"]; + + $pkg_size = array_values($pkg_matches)[0]["size"]; + + logger("Downloading $pkg_gitname package..."); + get_file_from_url($pkg_file, $pkg_url); + + /*$pkg_msg = "$pkg_name package download failed."; + if (file_put_contents($pkg_new, fopen($pkg_git.$pkg_name, 'r')));{ + $pkg_size = filesize($pkg_new); + $pkg_handle = fopen($pkg_new, "rb"); + $pkg_contents = fread($pkg_handle, $pkg_size); + fclose($pkg_handle); + $pkg_str = "blob ".$pkg_size."\0".$pkg_contents; + $pkg_sha = sha1($pkg_str); + if($pkg_sha == $_POST["pkgsha"]) { + $pkg_msg = "$pkg_name package downloaded."; + if (is_file($pkg_old)) + unlink($pkg_old); + if($pkg_pref == "yes") { + $pkg_msg = "$pkg_name package updated."; + } + }else { + if (is_file($pkg_new)) + unlink($pkg_new); + } + } + echo json_encode($pkg_msg); + */ + + } + } + + $pkg_msg = "Installing"; + $pkg_cmd = "upgradepkg --install-new "; + + }elseif($pkg_pref == "no" && $pkg_install_status && $argv[2] == "remove"){ + + $pkg_msg = "Removing"; + $pkg_cmd = "removepkg "; + + } + if(!empty($pkg_cmd)){ + logger("$pkg_msg $pkg_name package..."); + $pkg_cmd = $pkg_cmd.$pkg_path.$pkg_name."*"; + + exec($pkg_cmd, $output, $return_var); + + for ($i = 0; $i < sizeof($output); $i++) { + logger($output[$i]); + } + } +} + +logger("All packages processed"); +?> \ No newline at end of file