2 # Functions for installing packages from Blastwave
4 $pkg_get = -x "/opt/csw/bin/pkgutil" ? "/opt/csw/bin/pkgutil" :
5 -x "/opt/csw/bin/pkg-get" ? "/opt/csw/bin/pkg-get" :
6 &has_command("pkgutil") ? &has_command("pkgutil") :
7 &has_command("pkg-get");
9 sub list_update_system_commands
14 # update_system_install([file])
15 # Install some package with pkg-get
16 sub update_system_install
18 local $update = $_[0] || $in{'update'};
19 local (@rv, @newpacks, %seen, $failed);
21 # Setup for non-interactive mode
22 ©_source_dest("/var/pkg-get/admin", "/var/pkg-get/admin-old");
23 ©_source_dest("/var/pkg-get/admin-fullauto", "/var/pkg-get/admin");
27 local ($failed, $retry, %already);
29 if ($already{$update}++) {
30 # Don't try the same update twice
33 local $flag = $pkg_get =~ /pkgutil$/ ? "-y" : "-f";
34 print "<b>",&text('csw_install',
35 "<tt>$pkg_get -i $flag $update</tt>"),"</b><p>\n";
39 &open_execute_command(PKGGET,
40 "$pkg_get -i $flag ".quotemeta($update), 2);
42 if (!/\s*\d+\%\s+\[/) {
43 # Output everything except download lines
44 print &html_escape($_);
46 if (/Installation of <(.*)> was successful/i) {
49 elsif (/Installation of <(.*)> failed/i) {
52 elsif (/dependancy\s+(\S+)\s+.*not up to date/i) {
53 # Needs a dependecy .. so we will need to re-run!
55 $update = join(" ", &unique(
56 $dep, split(/\s+/, $update)));
59 elsif (/you already have version/i) {
67 print "<b>$text{'csw_retry'}</b><p>\n";
71 # Cleanup fullout file
72 ©_source_dest("/var/pkg-get/admin-old", "/var/pkg-get/admin");
75 print "<b>$text{'csw_failed'}</b><p>\n";
78 elsif ($failed == 2) {
79 print "<b>$text{'csw_already'}</b><p>\n";
83 print "<b>$text{'csw_ok'}</b><p>\n";
85 # If nothing failed, assume that everything worked
86 @rv = split(/\s+/, $update);
92 # update_system_available()
93 # Returns a list of all available CSW packages
94 sub update_system_available
97 open(PKG, "$pkg_get -a |");
101 next if (/^\s*WARNING:/);
102 if (/^\s*(\S+)\s+(\S+)\s+(\d\S+)\s+([0-9\.]+)\s+(KB|MB|GB|B)/i) {
104 push(@rv, { 'name' => $1, 'version' => $3,
105 'select' => "$1-$3" });
107 elsif (/^\s*(\S+)\s+(\S+)/) {
109 push(@rv, { 'name' => $1, 'version' => $2,
110 'select' => "$1-$2" });
114 return sort { lc($a->{'name'}) cmp lc($b->{'name'}) } @rv;
117 # update_system_form()
118 # Shows a form for updating all packages on the system
119 sub update_system_form
121 print &ui_subheading($text{'csw_form'});
122 print &ui_form_start("csw_upgrade.cgi");
123 print &ui_submit($text{'csw_upgrade'});
124 print &ui_form_end();