initial commit of nerpack plugin
This commit is contained in:
parent
0412d0fc54
commit
2383b44961
146
plugins/NerdPack.plg
Normal file
146
plugins/NerdPack.plg
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?xml version='1.0' standalone='yes'?>
|
||||
|
||||
<!DOCTYPE PLUGIN [
|
||||
<!ENTITY name "NerdPack">
|
||||
<!ENTITY author "dmacias72">
|
||||
<!ENTITY version "2015.12.13">
|
||||
<!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 pkgs "/boot/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>
|
||||
###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
|
||||
</CHANGES>
|
||||
|
||||
<!--
|
||||
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>
|
||||
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 ""
|
||||
</INLINE>
|
||||
</FILE>
|
||||
|
||||
<!--
|
||||
The 'remove' script.
|
||||
-->
|
||||
<FILE Run="/bin/bash" Method="remove">
|
||||
<INLINE>
|
||||
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 ""
|
||||
</INLINE>
|
||||
</FILE>
|
||||
|
||||
</PLUGIN>
|
BIN
plugins/NerdPack.png
Normal file
BIN
plugins/NerdPack.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
1
source/NerdPack/install/doinst.sh
Normal file
1
source/NerdPack/install/doinst.sh
Normal file
|
@ -0,0 +1 @@
|
|||
#!/bin/sh
|
19
source/NerdPack/install/slack-desc
Normal file
19
source/NerdPack/install/slack-desc
Normal file
|
@ -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
|
37
source/NerdPack/pkg_build.sh
Executable file
37
source/NerdPack/pkg_build.sh
Executable file
|
@ -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
|
|
@ -0,0 +1,38 @@
|
|||
Icon="NerdPack.png"
|
||||
Menu="NetworkServices"
|
||||
Title="Nerd Pack"
|
||||
---
|
||||
<?php
|
||||
include("/urs/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php");
|
||||
|
||||
$pkg_repo = "https://api.github.com/repos/eschultz/unraid6-nerdpack/contents/packages";
|
||||
$repo_file= "/boot/config/plugins/NerdPack/packages.json";
|
||||
|
||||
get_content_from_github($pkg_repo, $repo_file){
|
||||
?>
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
|
||||
<form markdown="1" id="package_form" name="package_settings" method="POST" action="/update.php" target="progressFrame">
|
||||
<input type="hidden" name="#file" value="NerdPack/NerdPack.cfg" />
|
||||
<table style="margin-top:-22px;" class="tablesorter" id="tblPackages">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="tablesorter-header"> Name </th>
|
||||
<th class="tablesorter-header"> Version </th>
|
||||
<th class="tablesorter-header"> Size (kB) </th>
|
||||
<th class="tablesorter-header"> Downloaded </th>
|
||||
<th class="tablesorter-header"> Installed </th>
|
||||
<th><input id="removepkg" type="checkbox"><input id="checkall" type="checkbox"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
: <input id="btnApply" type="button" value="Apply"><input type="button" value="Done" onClick="done()">
|
||||
</form>
|
||||
|
||||
<script type="text/javascript" src="/plugins/NerdPack/javascript/jquery.NerdPack.js"></script>
|
||||
<script type="text/javascript" src="/webGui/javascript/jquery.switchbutton.js"></script>
|
|
@ -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
|
2
source/NerdPack/usr/local/emhttp/plugins/NerdPack/event/started
Executable file
2
source/NerdPack/usr/local/emhttp/plugins/NerdPack/event/started
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager
|
Binary file not shown.
After Width: | Height: | Size: 744 B |
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
function progressBar($download_size, $downloaded_size, $upload_size, $uploaded_size)
|
||||
{
|
||||
static $previousProgress = 0;
|
||||
|
||||
if ($download_size == 0)
|
||||
$progress = 0;
|
||||
else
|
||||
$progress = round($downloaded_size * 100 / $download_size);
|
||||
|
||||
if ( $progress > $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();
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
include("/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php");
|
||||
$pkg_path="/boot/config/plugins/NerdPack/packages/";
|
||||
$pkg_git = "https://raw.githubusercontent.com/eschultz/unraid6-nerdpack/master/packages/";
|
||||
$pkg_config = "/boot/config/plugins/NerdPack/NerdPack.cfg";
|
||||
$pkg_cfg = parse_ini_file($pkg_config); // get package configs
|
||||
//$pkg_pref = $pkg_cfg[$_POST["pkgname"]]; // get package preference
|
||||
$pkgs_file = file_get_contents("/boot/config/plugins/NerdPack/packages.json");
|
||||
$pkgs_github = json_decode($pkgs_file, true);
|
||||
for ($i = 0; $i < sizeof($pkgs_github); $i++) {
|
||||
// echo $pkgs_github[$i]["name"];
|
||||
// echo $pkgs_github[$i]["download_url"];
|
||||
}
|
||||
|
||||
$pkg_file = "/usr/local/emhttp/plugins/NerdPack/include/python-2.7.9-x86_64-1.txz";
|
||||
$pkg_url = "https://raw.githubusercontent.com/eschultz/unraid6-nerdpack/master/packages/python-2.7.9-x86_64-1.txz";
|
||||
urlConnect($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);
|
||||
//shell_exec("cd $pkg_path && wget -q $pkg_new");
|
||||
$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_cmd = "upgradepkg --install-new ";
|
||||
$pkg_cmd = $pkg_cmd.$pkg_new." | logger -tnerdpack";
|
||||
shell_exec($pkg_cmd);
|
||||
$pkg_msg = "$pkg_name package updated.";
|
||||
}
|
||||
}else {
|
||||
if (is_file($pkg_new))
|
||||
unlink($pkg_new);
|
||||
}
|
||||
}
|
||||
echo json_encode($pkg_msg);
|
||||
*/
|
||||
?>
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
$config_file = "/boot/config/plugins/NerdPack/NerdPack.cfg";
|
||||
|
||||
$pkg_path = "/boot/config/plugins/NerdPack/packages/"; // package path
|
||||
|
||||
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : array(); // get package configs
|
||||
|
||||
$pkgs_downloaded = array_diff( scandir($pkg_path, 1), array(".", "..") ); // get array of packages
|
||||
|
||||
$pkgs_installed = array_diff( scandir("/var/log/packages", 1), array(".", "..") ); // get array of all installed packages
|
||||
|
||||
$pkgs_file = file_get_contents("/boot/config/plugins/NerdPack/packages.json");
|
||||
|
||||
$pkgs_github = json_decode($pkgs_file, true);
|
||||
|
||||
$pkgs_array = array();
|
||||
|
||||
for ($i = 0; $i < sizeof($pkgs_github); $i++) {
|
||||
|
||||
$pkg_NameArray = explode("-", $pkgs_github[$i]["name"]); // split package name into array
|
||||
|
||||
$pkg_Name = $pkg_NameArray[0];
|
||||
if (sizeof($pkg_NameArray) > 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);
|
||||
?>
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
$pkg_path="/boot/config/plugins/NerdPack/packages/";
|
||||
$pkg_git = "https://raw.githubusercontent.com/eschultz/unraid6-nerdpack/master/packages/";
|
||||
|
||||
$pkg_name = $_POST["pkgnew"];
|
||||
$pkg_new = $pkg_path.$pkg_name;
|
||||
|
||||
$pkg_config = "/boot/config/plugins/NerdPack/NerdPack.cfg";
|
||||
$pkg_cfg = parse_ini_file($pkg_config); // get package configs
|
||||
$pkg_pref = $pkg_cfg[$_POST["pkgname"]]; // get package preference
|
||||
$pkg_old = $pkg_path.$_POST["pkgold"];
|
||||
|
||||
$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);
|
||||
//shell_exec("cd $pkg_path && wget -q $pkg_new");
|
||||
$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_cmd = "upgradepkg --install-new ";
|
||||
$pkg_cmd = $pkg_cmd.$pkg_new." | logger -tnerdpack";
|
||||
shell_exec($pkg_cmd);
|
||||
$pkg_msg = "$pkg_name package updated.";
|
||||
}
|
||||
}else {
|
||||
if (is_file($pkg_new))
|
||||
unlink($pkg_new);
|
||||
}
|
||||
}
|
||||
echo json_encode($pkg_msg);
|
||||
?>
|
|
@ -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(
|
||||
"<tr>"+
|
||||
"<td>"+data[i].name+"</td>"+ //package name
|
||||
"<td></td>"+ //package status
|
||||
"<td>"+(data[i].size / 1000).toFixed(0)+"</td>"+ //package size
|
||||
"<td>"+data[i].downloaded+"</td>"+ //package installed
|
||||
"<td>"+data[i].installed+"</td>"+ //package installed
|
||||
"<td><input class='pkgcheckbox' id='"+data[i].pkgname+"' type='checkbox'>"+
|
||||
"<input class='pkgvalue' type='hidden' id='"+data[i].pkgname+"_value' name='"+data[i].pkgnver+"' value='"+data[i].config+"'>"+
|
||||
"</td></tr>");
|
||||
$('#'+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(
|
||||
"<tr>"+
|
||||
"<td><input type='button' value='Download Packages' onclick='downloadPackages();'></td>"+
|
||||
"</tr>");
|
||||
|
||||
}
|
||||
},
|
||||
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 = "<span style=\"color:#44B012;white-space:nowrap;\"><i class=\"fa fa-check\"></i> up-to-date</span>";
|
||||
else
|
||||
var Update = "<span style=\"white-space:nowrap;\"><i class=\"fa fa-cloud-download\"></i><a href='#' onclick='packageUpdate(\""+tblName+"\",\""+tblPackage+"\",\""+Package+"\",\""+data[i].sha+"\");'> update ready<a></span>";
|
||||
}
|
||||
}
|
||||
$(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 () {
|
||||
}
|
||||
});
|
||||
};
|
111
source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager
Executable file
111
source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager
Executable file
|
@ -0,0 +1,111 @@
|
|||
#!/usr/bin/php -q
|
||||
<?php
|
||||
include("/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php");
|
||||
|
||||
function logger($message) {
|
||||
echo "$message\n";
|
||||
//shell_exec( "echo $message | logger -tnerdpack");
|
||||
}
|
||||
|
||||
$config_file = "/boot/config/plugins/NerdPack/NerdPack.cfg";
|
||||
|
||||
$pkg_path ="/boot/config/plugins/NerdPack/packages/";
|
||||
|
||||
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : array(); // get package configs
|
||||
|
||||
$pkgs_downloaded = array_diff( scandir($pkg_path, 1), array(".", "..") ); // get array of packages
|
||||
|
||||
$pkgs_installed = array_diff( scandir("/var/log/packages", 1), array(".", "..") );
|
||||
|
||||
$pkgs_json = "/boot/config/plugins/NerdPack/packages.json";
|
||||
$pkgs_file = (is_file($pkgs_json)) ? file_get_contents($pkgs_json) : array();
|
||||
|
||||
$pkgs_github = json_decode($pkgs_file, true);
|
||||
|
||||
logger("Processing Packages...");
|
||||
|
||||
foreach($pkg_cfg as $pkg_name => $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");
|
||||
?>
|
Loading…
Reference in New Issue
Block a user