Magellan Linux

Contents of /alx-src/branches/alx-web-060/mageupgrade.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2488 - (show annotations) (download)
Thu Jun 30 11:01:23 2011 UTC (12 years, 10 months ago) by niro
File size: 4717 byte(s)
-support clients before alx-0.6.0 too
1 <?
2
3 include('include/dbconn.php');
4 include('include/basesql.php');
5 include('include/common-functions.php');
6
7 echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>';
8
9 ?>
10
11 <style type="text/css">
12 div.left { margin-left:20%; }
13 </style>
14
15 <?
16
17 function update_client_settings()
18 {
19 global $client;
20
21 // set verbose off
22 ssh_editvar('VERBOSE', 'off', '/etc/mage.rc');
23
24 // update rsync server location
25 $rsync = sqlfirst('select client_locations.rsync from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'rsync');
26 ssh_editvar('MAGE_RSYNC', $rsync, '/etc/alxconfig-ng/config.rc');
27 ssh_editvar('RSYNC', $rsync, '/etc/mage.rc');
28
29 // update repository server location
30 $repository = sqlfirst('select client_locations.repository from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'repository');
31 ssh_editvar('MAGE_MIRRORS', $repository, '/etc/alxconfig-ng/config.rc');
32 ssh_editvar('MIRRORS', $repository, '/etc/mage.rc');
33
34 // update samba update host
35 $updateserver = sqlfirst('select client_locations.updateserver from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'updateserver');
36 ssh_editvar('SMB_UPDATE_HOST', $updateserver, '/etc/alxconfig-ng/config.rc');
37
38 // update samba update user
39 $smbusername = sqlfirst('select client_locations.username from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'username');
40 ssh_editvar('SMB_UPDATE_USER', $smbusername, '/etc/alxconfig-ng/config.rc');
41
42 // update samba update password
43 $smbpassword = sqlfirst('select client_locations.password from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'password');
44 ssh_editvar('SMB_UPDATE_PASS', $smbpassword, '/etc/alxconfig-ng/config.rc');
45 }
46
47 // get alx version info
48 $alxinfo = sqlfirst('SELECT * FROM client_version WHERE serial='.$client);
49 $alxos = $alxinfo[os];
50 $alxutils = $alxinfo[utils];
51
52 // always update the client settings first
53 update_client_settings();
54
55 if($op=="calc")
56 {
57 echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...<br>');
58
59 if($alxos >= '0.6.0') {
60 $out = sshdo('NOCOLORS=true /sbin/mage uppretend | egrep "\[.*\]" | sed "s:\[.*\]\ \(.*\):\1:" | sed "s:/:,:" | sed "s:\(.*\)-:\1,:" | sed "s:\(.*\)-:\1,:"', $ip);
61 }
62 else {
63 $out = sshdo('NOCOLORS=true /sbin/mageupgrade --calc-bash', $ip);
64 }
65 echo '<pre>';
66 echo '<table border="0">';
67 if (array_key_exists("0", $out))
68 {
69 foreach( $out as $i)
70 {
71 // element 0 is always 0
72 if ($i=="0") continue;
73
74 $item=explode(",",$i);
75 $pcat=$item[0];
76 $pname=$item[1];
77 $pver=$item[2];
78 $pbuild=$item[3];
79
80 echo '<tr><td>';
81 echo '<font color=green>'.$pcat.'/'.$pname.'</font>';
82 echo '<td>';
83 echo '<font color=blue> => [ '.$pver.'-'.$pbuild.' ] </font>';
84 echo '</td>';
85 echo '</td></tr>';
86 }
87 }
88 else echo 'No updates for client '.$client.' available.';
89 echo '</table>';
90 echo '</pre>';
91 }
92 elseif($op=="update")
93 {
94 echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>');
95 echo '<br>';
96 echo '<pre><div align=left class=left>';
97
98 sshdo('NOCOLORS=true /sbin/mage update', $ip);
99
100 echo '</div></pre>';
101 echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>';
102 }
103 elseif($op=="upgrade")
104 {
105 echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>');
106 echo '<br>';
107 echo '<pre><div align=left class=left>';
108
109 # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first
110 $err = sshdo('[ -x /usr/sbin/update-alx ]', $ip);
111 if($err[0]!=0)
112 {
113 echo '"update-alx" missing on client "'.$client.'". Updating mage and alxconfig-ng first ...<br>';
114 sshdo('NOCOLORS=true mage install mage', $ip);
115 sshdo('NOCOLORS=true mage install alxconfig-ng', $ip);
116 }
117 $err = sshdo('NOCOLORS=true /usr/sbin/update-alx', $ip);
118 if ($err[0]!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>';
119 else echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>';
120 echo '</div></pre>';
121 }
122 else echo 'unkown operation';
123 echo '</td></tr></table>';
124
125 ?>

Properties

Name Value
svn:executable *