forked from hummypkg/webif
working on package system
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@209 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
parent
d068d93073
commit
050cb611bf
25
var/mongoose/cgi-bin/browse/new.jim
Executable file
25
var/mongoose/cgi-bin/browse/new.jim
Executable file
@ -0,0 +1,25 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
package require cgi
|
||||
|
||||
puts "Content-Type: application/json"
|
||||
puts ""
|
||||
|
||||
cgi_input
|
||||
#cgi_dump
|
||||
|
||||
set _cgi(dir) "/media/My Video"
|
||||
|
||||
set dir [dict get $_cgi dir]
|
||||
# Strip double slashes
|
||||
regsub -all -- {\/+} "$dir/*" "/" dir
|
||||
|
||||
puts "{"
|
||||
foreach subdir [glob -nocomplain "$dir"] {
|
||||
set new 0
|
||||
foreach hmt [glob -nocomplain "$subdir/*.hmt"] {
|
||||
puts "HMT: $hmt"
|
||||
}
|
||||
}
|
||||
puts "}"
|
||||
|
18
var/mongoose/cgi-bin/opkg.jim
Executable file
18
var/mongoose/cgi-bin/opkg.jim
Executable file
@ -0,0 +1,18 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
package require cgi
|
||||
|
||||
puts "Content-Type: text/html"
|
||||
puts ""
|
||||
|
||||
cgi_input
|
||||
#cgi_dump
|
||||
|
||||
#set _cgi(cmd) {remove binutils}
|
||||
|
||||
if {![dict exists $_cgi cmd]} { set _cgi(cmd) status }
|
||||
|
||||
set cmd [dict get $_cgi cmd]
|
||||
|
||||
puts [exec /mod/var/mongoose/lib/opkg {*}$cmd]
|
||||
|
47
var/mongoose/html/js/packages.js
Executable file
47
var/mongoose/html/js/packages.js
Executable file
@ -0,0 +1,47 @@
|
||||
|
||||
function reset_results()
|
||||
{
|
||||
$('#dresults').empty().val('Running package command, please wait...');
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('button').button();
|
||||
|
||||
var $dialog = $('#dialogue').dialog({
|
||||
title: "Package Management Results",
|
||||
modal: false, autoOpen: false,
|
||||
height: 500, width: 700,
|
||||
show: 'scale', hide: 'fade',
|
||||
draggable: true, resizable: true,
|
||||
buttons: { "Close":
|
||||
function() {$(this).dialog('close');}},
|
||||
close: function(e,u) { reset_results(); }
|
||||
});
|
||||
reset_results();
|
||||
|
||||
var opkg = '/cgi-bin/opkg.jim?cmd=';
|
||||
|
||||
$('#opkgupdate').click(function() {
|
||||
$('#result_txt').load(opkg + 'update');
|
||||
$('#results').show('slow');
|
||||
});
|
||||
|
||||
$('button.remove').click(function() {
|
||||
$('#dresults').load(opkg +
|
||||
encodeURIComponent('remove ' + $(this).attr('id')));
|
||||
$dialog.dialog('open');
|
||||
});
|
||||
|
||||
$('button.install').click(function() {
|
||||
$('#dresults').load(opkg +
|
||||
encodeURIComponent('install ' + $(this).attr('id')));
|
||||
$dialog.dialog('open');
|
||||
});
|
||||
|
||||
$('button.upgrade').click(function() {
|
||||
$('#dresults').load(opkg +
|
||||
encodeURIComponent('upgrade ' + $(this).attr('id')));
|
||||
$dialog.dialog('open');
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
<!--#include virtual="/lib/header.shtml" -->
|
||||
|
||||
<h1>Package Management</h1>
|
||||
<h1 class=vam>Package Management
|
||||
<button class=vam id=opkgupdate>Update package list from Internet</button>
|
||||
</h1>
|
||||
<div id=results class=shadowbox style="width: 90%; display: none; margin: 1 0 1em 0">
|
||||
<div>
|
||||
<pre id=result_txt>
|
||||
@ -9,6 +11,8 @@ Results...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id=dialogue style="display: none"><pre id=dresults></pre></div>
|
||||
|
||||
<!--#exec cmd="/mod/var/mongoose/include/packages.jim" -->
|
||||
|
||||
<!--#include virtual="/lib/footer.shtml" -->
|
||||
|
@ -1,52 +1,55 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
# Build a list of available packages
|
||||
source /mod/var/mongoose/lib/pkg.class
|
||||
|
||||
puts {
|
||||
|
||||
<style type=text/css>
|
||||
.ui-button, .ui-button-text { padding: 0; font-size: 12px; }
|
||||
</style>
|
||||
|
||||
<script type=text/javascript src=/js/packages.js></script>
|
||||
|
||||
<table class=borders>
|
||||
<tr>
|
||||
<th>Package</th>
|
||||
<th>Installed</th>
|
||||
<th>Avail</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
|
||||
set avail_pkgs {}
|
||||
foreach pkg [split [exec /bin/opkg list] "\n"] {
|
||||
if [regexp {^ } $pkg] {
|
||||
append descr $pkg
|
||||
} else {
|
||||
if {[regexp {^([^ ]+) - ([^ ]+) - (.*)$} \
|
||||
$pkg full name ver descr] == 0} { continue }
|
||||
}
|
||||
set avail_pkgs($name) [concat $ver "$descr"]
|
||||
#puts "Set: $name = ($ver, $descr)<br>"
|
||||
}
|
||||
|
||||
# Build a list of installed packages - just the names
|
||||
set inst_pkgs {}
|
||||
foreach pkg [split [exec /bin/opkg list-installed] "\n"] {
|
||||
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
|
||||
lappend inst_pkgs $name
|
||||
#puts "Inst: $name<br>"
|
||||
}
|
||||
set avail [pkg avail]
|
||||
foreach name [lsort [array names avail]] {
|
||||
set pkg [pkg load $name $avail($name)]
|
||||
|
||||
puts "<table class=borders>"
|
||||
puts "<tr>"
|
||||
puts "<th>Installed</th>"
|
||||
puts "<th>Name</th>"
|
||||
puts "<th>Version</th>"
|
||||
puts "<th>Description</th>"
|
||||
puts "</tr>"
|
||||
|
||||
foreach name [lsort [array names avail_pkgs]] {
|
||||
set value $avail_pkgs($name)
|
||||
set ver [lindex $value 0]
|
||||
set descr [lrange $value 1 [llength $value]]
|
||||
|
||||
puts "<tr>"
|
||||
puts "<td>"
|
||||
if {[lsearch $inst_pkgs $name] > -1} {
|
||||
puts "<img src=/img/on.png>"
|
||||
if {![$pkg is installed]} {
|
||||
puts "<tr>"
|
||||
} elseif {[$pkg is upgradable]} {
|
||||
puts "<tr class=yellowshade>"
|
||||
} else {
|
||||
puts "<img src=/img/off.png>"
|
||||
puts "<tr class=greenshade>"
|
||||
}
|
||||
|
||||
puts "</td>"
|
||||
puts "<td>$name</td>"
|
||||
puts "<td>$ver</td>"
|
||||
puts "<td>$descr</td>"
|
||||
puts "
|
||||
<td>$name</td>
|
||||
<td>[$pkg get installed]</td>
|
||||
<td>[$pkg get latest]</td>
|
||||
<td>[$pkg get descr]</td>
|
||||
"
|
||||
|
||||
if {![$pkg is installed]} {
|
||||
set type Install
|
||||
} elseif {[$pkg is upgradable]} {
|
||||
set type Upgrade
|
||||
} else {
|
||||
set type Remove
|
||||
}
|
||||
|
||||
puts "<td align=center><button id=\"$name\"
|
||||
class=[string tolower $type]>$type</button></td>"
|
||||
|
||||
puts "</tr>"
|
||||
}
|
||||
|
||||
|
6
var/mongoose/lib/opkg
Executable file
6
var/mongoose/lib/opkg
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# stderr is always unbuffered so use that...
|
||||
/bin/opkg "$@" 1>&2
|
||||
exit 0
|
||||
|
84
var/mongoose/lib/pkg.class
Executable file
84
var/mongoose/lib/pkg.class
Executable file
@ -0,0 +1,84 @@
|
||||
|
||||
if {[expr ! [exists -proc class ]]} { package require oo }
|
||||
|
||||
class pkg {
|
||||
name ""
|
||||
descr ""
|
||||
installed ""
|
||||
latest ""
|
||||
install_time 0
|
||||
}
|
||||
|
||||
pkg method _load {nm info} {
|
||||
set name $nm
|
||||
set latest [lindex $info 0]
|
||||
set descr [lrange $info 1 end]
|
||||
|
||||
foreach line [split [exec /bin/opkg status $name] "\n"] {
|
||||
if {[string match {Version: *} $line]} {
|
||||
set installed [string range $line 9 end]
|
||||
}
|
||||
if {[string match {Installed-Time: } $line]} {
|
||||
set install_time [string range $line 16 end]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pkg method is {what} {
|
||||
switch $what {
|
||||
installed {
|
||||
if {$installed eq ""} { return 0 }
|
||||
return 1
|
||||
}
|
||||
upgradable {
|
||||
if {$installed eq $latest} { return 0 }
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
proc {pkg load} {nm info} {
|
||||
set e [pkg]
|
||||
$e _load $nm $info
|
||||
return $e
|
||||
}
|
||||
|
||||
proc {pkg avail} {} {
|
||||
set avail_pkgs {}
|
||||
foreach pkg [split [exec /bin/opkg list] "\n"] {
|
||||
if [regexp {^ } $pkg] {
|
||||
append descr $pkg
|
||||
} else {
|
||||
if {[regexp {^([^ ]+) - ([^ ]+) - (.*)$} \
|
||||
$pkg full name ver descr] == 0} { continue }
|
||||
}
|
||||
set avail_pkgs($name) [concat $ver "$descr"]
|
||||
#puts "Set: $name = ($ver, $descr)<br>"
|
||||
}
|
||||
return $avail_pkgs
|
||||
}
|
||||
|
||||
proc {pkg installed} {} {
|
||||
# Build a list of installed packages - just the names
|
||||
set inst_pkgs {}
|
||||
foreach pkg [split [exec /bin/opkg list-installed] "\n"] {
|
||||
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
|
||||
lappend inst_pkgs $name
|
||||
#puts "Inst: $name<br>"
|
||||
}
|
||||
return $inst_pkgs
|
||||
}
|
||||
|
||||
proc {pkg upgradable} {} {
|
||||
#webif - 0.5.3 - 0.5.7
|
||||
set upgr_pkgs {}
|
||||
foreach pkg [split [exec /bin/opkg list-upgradable] "\n"] {
|
||||
if {[regexp {^([^ ]+) - ([^ ]+) - (.*)$} $pkg \
|
||||
dummy name oldver newver] == 0} { continue }
|
||||
set upgr_pkgs($name) [concat $oldver $newver]
|
||||
#puts "Set: $name = ($oldver, $newver)<br>"
|
||||
}
|
||||
return $upgr_pkgs
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user