diff --git a/CONTROL/control b/CONTROL/control
index b4abab40..e800bb4a 100644
--- a/CONTROL/control
+++ b/CONTROL/control
@@ -1,7 +1,7 @@
Package: webif
Priority: optional
Section: web
-Version: 1.2.8
+Version: 1.2.8-1
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.1.18),lighttpd(>=1.4.39-1),jim(>=0.76),jim-oo,jim-sqlite3(>=0.76),jim-cgi(>=0.7),jim-binary(>=0.76),service-control(>=2.1),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.1),hmt(>=2.0.9),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7)
diff --git a/webif/html/pkg/pkg.jim b/webif/html/pkg/pkg.jim
index 7c19b9d8..ba59c999 100755
--- a/webif/html/pkg/pkg.jim
+++ b/webif/html/pkg/pkg.jim
@@ -8,8 +8,9 @@ if {[[settings] pkgdev]} { set filter 0 } else { set filter 1 }
httpheader
-proc pkgrow {pkg} {
- set name [$pkg get name]
+set pkgdata [pkg getall]
+
+proc pkgrow {name pkg} {
altrow "pkg=\"$name\""
puts "
$name"
if {$::type eq "inst"} {
@@ -21,29 +22,30 @@ proc pkgrow {pkg} {
puts " "
if {$::type eq "avail"} {
- puts "[$pkg get latest] "
+ puts "$pkg(version) "
} else {
- puts "[$pkg get installed] "
+ puts "$pkg(installed) "
}
if {$::type eq "upgr"} {
- puts "[$pkg get latest] "
+ puts "$pkg(version) "
}
puts ""
+ set descr $pkg(description)
+ set changes ""
+ regexp {(.*) \[(.*)\]} $descr x descr changes
if {[dict exists $::pkgmeta $name]} {
- puts "$::pkgmeta($name)"
+ puts $::pkgmeta($name)
} else {
- puts "[$pkg get descr]"
+ puts $descr
}
if {$::type eq "upgr"} {
- $pkg loadraw
- set url [$pkg get url]
- set changes [$pkg get changes]
if {$changes ne ""} {
puts " - $changes "
}
- if {$url ne ""} {
+ if {[dict exists $pkg tags]} {
+ set url $pkg(tags)
puts "
@@ -53,17 +55,27 @@ proc pkgrow {pkg} {
}
puts " "
- if {![$pkg is installed]} {
+ if {$pkg(installed) eq "0"} {
set type Install
- } elseif {$::type eq "upgr" && [$pkg is upgradable]} {
- set type Upgrade
+ } elseif {$::type eq "upgr" && $pkg(installed) ne $pkg(version)} {
+ if {[pkg vercompare $pkg(version) $pkg(installed)] == 1} {
+ set type Upgrade
+ } else {
+ set type ""
+ }
} else {
set type Remove
}
- puts "$type "
+ puts ""
+ if {$type ne ""} {
+ puts "$type "
+ } else {
+ puts "Newer "
+ }
+ puts " "
puts ""
}
@@ -72,7 +84,29 @@ pkg loadmeta
set type [cgi_get type "avail"]
-set pkgs [pkg $type]
+set pkgs {}
+foreach {pkg data} $pkgdata {
+ switch $type {
+ avail {
+ if {$data(installed) eq "0"} {
+ lappend pkgs $pkg
+ }
+ }
+ inst {
+ if {$data(installed) ne "0"} {
+ lappend pkgs $pkg
+ }
+ }
+ upgr {
+ if {$data(installed) ne "0" && \
+ $data(installed) ne $data(version)} {
+ lappend pkgs $pkg
+ }
+ }
+ }
+}
+
+#set pkgs [pkg $type]
if {[llength $pkgs] > 0} {
puts "Package "
@@ -95,8 +129,9 @@ if {[llength $pkgs] > 0} {
foreach pkg $pkgs {
if {$type ne "upgr" && $filter && \
- ![dict exists $::pkgmeta $pkg]} { continue }
- pkgrow [pkg load $pkg]
+ ![dict exists $::pkgmeta $pkg]} continue
+ if {![dict exists $pkgdata $pkg]} continue
+ pkgrow $pkg $pkgdata($pkg)
}
puts "
"
if {$type ne "upgr" && $filter} {
diff --git a/webif/lib/pkg.class b/webif/lib/pkg.class
index 87bb3bca..eb520bd5 100755
--- a/webif/lib/pkg.class
+++ b/webif/lib/pkg.class
@@ -31,6 +31,59 @@ pkg method _load {nm} {
return $self
}
+proc {pkg getall} {{repo base}} {
+ set pkglist {}
+
+ # Fetch details of installed packages
+ foreach line [split [exec /bin/opkg list-installed] "\n"] {
+ lassign $line pkg x ver
+ #regexp {^([^ ]+) - ([^ ]+)$} $line pkg x ver
+ set installed($pkg) $ver
+ }
+
+ # Now build list of all packages
+
+ if {[catch { set fp [open "/mod/var/opkg/$repo" r] } msg]} {
+ error "Error opening repository, $msg"
+ }
+ set cur ""
+ set pkg {}
+ foreach line [split [$fp read] "\n"] {
+ if {![regexp {^([^:]+): (.*)$} $line x tag val]} {
+ if {[string equal -length 1 $line " "]} {
+ # Continuation
+ if {$lasttag ne ""} {
+ append pkg($lasttag) " \
+ [string trim $line]"
+ }
+ }
+ continue
+ }
+ set tag [string tolower $tag]
+ if {$tag eq "package"} {
+ if {$pkg ne ""} {
+ set pkglist($name) $pkg
+ }
+ set name $val
+ if {[dict exists $installed $val]} {
+ set pkg "installed $installed($val)"
+ } else {
+ set pkg {installed 0}
+ }
+ set lasttag ""
+ continue
+ }
+ set lasttag $tag
+ set pkg($tag) $val
+ }
+ $fp close
+ if {$pkg ne ""} {
+ set pkglist($name) $pkg
+ }
+
+ return $pkglist
+}
+
pkg method loadraw {} {
set tag ""
set txt ""
@@ -175,3 +228,18 @@ proc {pkg upgrade} {nm} {
exec /bin/opkg upgrade $nm
}
+proc {pkg vercompare} {v1 v2} {
+ if {$v1 eq $v2} { return 0 }
+
+ lassign [split $v1 -] v1 r1
+ lassign [split $v2 -] v2 r2
+
+ foreach a [split $v1 .] b [split $v2 .] {
+ if {$b eq "" || $a > $b} { return 1 }
+ if {$a eq "" || $a < $b} { return -1 }
+ }
+ if {$r2 eq "" || $r1 > $r2} { return 1 }
+ if {$r1 eq "" || $r2 > $r1} { return -1 }
+ return 0
+}
+
diff --git a/webif/lib/settings.class b/webif/lib/settings.class
index b1635ade..c56719ff 100644
--- a/webif/lib/settings.class
+++ b/webif/lib/settings.class
@@ -3,17 +3,17 @@ if {![exists -proc class]} { package require oo }
if {![exists -proc sqlite3.open]} { package require sqlite3 }
if {![file exists /mod/etc/webif.db]} {
- set settingsdb [sqlite3.open /mod/etc/webif.db]
+ set ::settingsdb [sqlite3.open /mod/etc/webif.db]
catch {
- $settingsdb query {
+ $::settingsdb query {
CREATE TABLE settings(name text, nval int, tval text);
}
- $settingsdb query {
+ $::settingsdb query {
CREATE UNIQUE INDEX key on settings(name);
}
}
} else {
- set settingsdb [sqlite3.open /mod/etc/webif.db]
+ set ::settingsdb [sqlite3.open /mod/etc/webif.db]
}
class settings {
diff --git a/webif/lib/test/pkgver b/webif/lib/test/pkgver
new file mode 100755
index 00000000..f6fd56e8
--- /dev/null
+++ b/webif/lib/test/pkgver
@@ -0,0 +1,26 @@
+#!/mod/bin/jimsh
+
+source /mod/webif/lib/setup
+require pkg.class
+
+set verlist {
+ 1.0.0 1.0.1 -1
+ 1.0.1 1.0.0 1
+ 1.0.2 1.0.2 0
+ 1.0 1.0.1 -1
+ 1.0.1 1.0 1
+ 1.0-1 1.0 1
+ 1.0 1.0-1 -1
+ 2 1.0.1 1
+}
+
+foreach {a b e} $verlist {
+ set ret [pkg vercompare $a $b]
+ if {$ret eq $e} {
+ puts " OK $a $b ($e)"
+ } else {
+ puts "BAD $a $b ($e)"
+ }
+}
+
+