2011-06-28 00:20:31 +00:00
|
|
|
|
2012-01-13 21:23:03 +00:00
|
|
|
if {![exists -proc class]} { package require oo }
|
2011-06-28 00:20:31 +00:00
|
|
|
|
|
|
|
class pkg {
|
|
|
|
name ""
|
2011-07-11 23:29:21 +00:00
|
|
|
latest ""
|
2011-06-28 00:20:31 +00:00
|
|
|
descr ""
|
2014-02-03 21:42:20 +00:00
|
|
|
changes ""
|
|
|
|
url ""
|
2011-06-28 00:20:31 +00:00
|
|
|
installed ""
|
2014-02-03 21:42:20 +00:00
|
|
|
raw {}
|
2011-06-28 00:20:31 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
set ::pkgmeta {}
|
2012-11-25 00:22:18 +00:00
|
|
|
set ::diagmeta {}
|
2011-07-11 23:29:21 +00:00
|
|
|
|
|
|
|
pkg method _load {nm} {
|
2011-06-28 00:20:31 +00:00
|
|
|
set name $nm
|
2012-01-06 23:39:15 +00:00
|
|
|
foreach line [split [exec /bin/opkg list $nm] "\n"] {
|
|
|
|
# betaftpd - 0.0.8pre17-1 - Description...
|
2014-02-03 21:42:20 +00:00
|
|
|
if {[string match { *} $line]} {
|
|
|
|
append descr $line
|
|
|
|
} else {
|
|
|
|
regexp {^[^ ]+ - ([^ ]+) - (.*)$} $line x latest descr
|
|
|
|
}
|
2012-01-06 23:39:15 +00:00
|
|
|
}
|
2014-02-03 21:42:20 +00:00
|
|
|
regexp {(.*) \[(.*)\]} $descr x descr changes
|
2011-07-11 23:29:21 +00:00
|
|
|
set info [exec /bin/opkg list-installed $nm]
|
2014-02-03 21:42:20 +00:00
|
|
|
regexp {^([^ ]+) - ([^ ]+)$} $info x x installed
|
2011-06-28 00:20:31 +00:00
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
return $self
|
|
|
|
}
|
|
|
|
|
2014-02-03 21:42:20 +00:00
|
|
|
pkg method loadraw {} {
|
|
|
|
set tag ""
|
|
|
|
set txt ""
|
|
|
|
set raw {}
|
|
|
|
|
|
|
|
foreach line [split [exec /bin/opkg info $name] "\n"] {
|
|
|
|
if {$tag ne "" && [string match { *} $line]} {
|
|
|
|
append raw($tag) $line
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
regexp {^([^:]+): (.*)$} $line x tag txt
|
|
|
|
if {![dict exists $raw $tag]} {
|
|
|
|
set tag [string tolower $tag]
|
|
|
|
set raw($tag) $txt
|
|
|
|
} else {
|
|
|
|
set tag ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[dict exists $raw tags]} { set url $raw(tags) }
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc {pkg load} {nm} {
|
|
|
|
return [[pkg] _load $nm]
|
2011-06-28 00:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 avail} {} {
|
2011-07-11 23:29:21 +00:00
|
|
|
set inst_pkgs [pkg inst]
|
2011-06-28 00:20:31 +00:00
|
|
|
set avail_pkgs {}
|
|
|
|
foreach pkg [split [exec /bin/opkg list] "\n"] {
|
2011-07-11 23:29:21 +00:00
|
|
|
if [regexp {^ } $pkg] { continue }
|
|
|
|
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
|
2014-02-03 21:42:20 +00:00
|
|
|
if {$name ni $inst_pkgs && $name ni $avail_pkgs} {
|
|
|
|
lappend avail_pkgs $name
|
|
|
|
}
|
2011-07-11 23:29:21 +00:00
|
|
|
#puts "New: $name<br>"
|
2011-06-28 00:20:31 +00:00
|
|
|
}
|
|
|
|
return $avail_pkgs
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc {pkg inst} {} {
|
2011-06-28 00:20:31 +00:00
|
|
|
# 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 }
|
2014-02-03 21:42:20 +00:00
|
|
|
if {$name ni $inst_pkgs} {
|
|
|
|
lappend inst_pkgs $name
|
|
|
|
}
|
2011-06-28 00:20:31 +00:00
|
|
|
#puts "Inst: $name<br>"
|
|
|
|
}
|
|
|
|
return $inst_pkgs
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc {pkg upgr} {} {
|
2011-06-28 00:20:31 +00:00
|
|
|
#webif - 0.5.3 - 0.5.7
|
|
|
|
set upgr_pkgs {}
|
|
|
|
foreach pkg [split [exec /bin/opkg list-upgradable] "\n"] {
|
2011-07-11 23:29:21 +00:00
|
|
|
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
|
|
|
|
lappend upgr_pkgs $name
|
|
|
|
#puts "Upgr: $name<br>"
|
2011-06-28 00:20:31 +00:00
|
|
|
}
|
|
|
|
return $upgr_pkgs
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc {pkg loadmeta} {} {
|
|
|
|
if {[llength $::pkgmeta]} { return }
|
|
|
|
if {![file exists "/mod/var/pkg.meta"]} {
|
2012-10-08 20:16:27 +00:00
|
|
|
catch {pkg fetchmeta}
|
2011-07-11 23:29:21 +00:00
|
|
|
} else {
|
|
|
|
set meta [open "/mod/var/pkg.meta" r]
|
|
|
|
set ::pkgmeta [read $meta]
|
|
|
|
$meta close
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-25 00:22:18 +00:00
|
|
|
proc {pkg loaddiagmeta} {} {
|
|
|
|
if {[llength $::diagmeta]} { return }
|
|
|
|
if {![file exists "/mod/var/diag.meta"]} {
|
|
|
|
catch {pkg fetchdiagmeta}
|
|
|
|
} else {
|
|
|
|
set meta [open "/mod/var/diag.meta" r]
|
|
|
|
set ::diagmeta [read $meta]
|
|
|
|
$meta close
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc {pkg fetchmeta} {} {
|
|
|
|
set f [socket stream hummypkg.org.uk:80]
|
2012-03-11 00:26:14 +00:00
|
|
|
$f puts -nonewline "GET /hdrfoxt2/pkg.meta HTTP/1.1\r\n"
|
2011-07-11 23:29:21 +00:00
|
|
|
$f puts -nonewline "Host: hummypkg.org.uk\r\n"
|
2014-01-18 00:26:33 +00:00
|
|
|
$f puts -nonewline "Connection: close\r\n"
|
2011-07-11 23:29:21 +00:00
|
|
|
$f puts -nonewline "\r\n"
|
|
|
|
|
|
|
|
set line [string trim [$f gets]]
|
|
|
|
while {[string length $line]} {
|
|
|
|
set line [string trim [$f gets]]
|
|
|
|
}
|
|
|
|
set ::pkgmeta [$f read]
|
|
|
|
$f close
|
|
|
|
|
|
|
|
set ff [open "/mod/var/pkg.meta" w]
|
|
|
|
puts $ff $::pkgmeta
|
|
|
|
$ff close
|
|
|
|
}
|
|
|
|
|
2012-11-25 00:22:18 +00:00
|
|
|
proc {pkg fetchdiagmeta} {} {
|
|
|
|
set f [socket stream hummypkg.org.uk:80]
|
|
|
|
$f puts -nonewline "GET /diag/diag.meta HTTP/1.1\r\n"
|
|
|
|
$f puts -nonewline "Host: hummypkg.org.uk\r\n"
|
2014-01-18 00:26:33 +00:00
|
|
|
$f puts -nonewline "Connection: close\r\n"
|
2012-11-25 00:22:18 +00:00
|
|
|
$f puts -nonewline "\r\n"
|
|
|
|
|
|
|
|
set line [string trim [$f gets]]
|
|
|
|
while {[string length $line]} {
|
|
|
|
set line [string trim [$f gets]]
|
|
|
|
}
|
|
|
|
set ::diagmeta [$f read]
|
|
|
|
$f close
|
|
|
|
|
|
|
|
set ff [open "/mod/var/diag.meta" w]
|
|
|
|
puts $ff $::diagmeta
|
|
|
|
$ff close
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:06:38 +00:00
|
|
|
proc {pkg update} {} {
|
|
|
|
exec /bin/opkg update
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {pkg upgrade} {nm} {
|
|
|
|
exec /bin/opkg upgrade $nm
|
|
|
|
}
|
|
|
|
|