Annotation of /alx-src/branches/alx-web-060/mageupgrade.php
Parent Directory | Revision Log
Revision 2020 -
(hide annotations)
(download)
Mon May 9 21:06:14 2011 UTC (13 years, 4 months ago) by niro
File size: 7339 byte(s)
Mon May 9 21:06:14 2011 UTC (13 years, 4 months ago) by niro
File size: 7339 byte(s)
-more mage-0.4 compat fixes
1 | niro | 1610 | <? |
2 | include('include/dbconn.php'); | ||
3 | include('include/basesql.php'); | ||
4 | |||
5 | echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>'; | ||
6 | ?> | ||
7 | <style type="text/css"> | ||
8 | div.left { margin-left:20%; } | ||
9 | </style> | ||
10 | <? | ||
11 | function editvar($var, $value, $file) | ||
12 | { | ||
13 | global $ip; | ||
14 | global $sshcmd; | ||
15 | |||
16 | // sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^\(VAR=\).*|\1\"VALUE\"| FILE' | ||
17 | $str = $sshcmd.' '.$ip.' \'sed -i -e "s|^\\('.$var.'=\\).*|\\1\\"'.$value.'\\"|" '.$file.'\''; | ||
18 | //echo $str.'<br>'; | ||
19 | system($str); | ||
20 | } | ||
21 | |||
22 | $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.''); | ||
23 | while ($row = mysql_fetch_row ($pubkey)) | ||
24 | { | ||
25 | # schreiben der .ssh/known_hosts file mit dem public rsa key des client, | ||
26 | # um die "yes" abfrage zu vermeiden | ||
27 | $hostfile = fopen ($home."/.ssh/known_hosts","w"); | ||
28 | fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1); | ||
29 | fclose($hostfile); | ||
30 | |||
31 | # reboot des clients | ||
32 | passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1',$retval); | ||
33 | if($retval==0) | ||
34 | { | ||
35 | if($op=="calc") | ||
36 | { | ||
37 | echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...<br>'); | ||
38 | niro | 2020 | exec($sshcmd.' '.$ip.' NOCOLORS=true /sbin/mage uppretend | egrep "\[.*\]" | sed "s:\[.*\]\ \(.*\):\1:" | sed "s:/:,:" | sed "s:\(.*\)-:\1,:" | sed "s:\(.*\)-:\1,:"',$out,$err); |
39 | niro | 1610 | echo '<pre>'; |
40 | echo '<table border="0">'; | ||
41 | if (array_key_exists("0", $out)) | ||
42 | { | ||
43 | foreach( $out as $i) | ||
44 | { | ||
45 | niro | 2020 | if(strstr($i,"Magellan") |
46 | { | ||
47 | continue; | ||
48 | } | ||
49 | if(strstr($i,"dependencies") | ||
50 | { | ||
51 | continue; | ||
52 | } | ||
53 | niro | 1610 | $item=explode(",",$i); |
54 | $pcat=$item[0]; | ||
55 | $pname=$item[1]; | ||
56 | niro | 2020 | $pver=$item[2]; |
57 | $pbuild=$item[3]; | ||
58 | niro | 1610 | |
59 | echo '<tr><td>'; | ||
60 | echo '<font color=green>'.$pcat.'/'.$pname.'</font>'; | ||
61 | echo '<td>'; | ||
62 | niro | 2020 | echo '<font color=blue> => [ '.$pver.'-'.$pbuild.' ] </font>'; |
63 | niro | 1610 | echo '</td>'; |
64 | echo '</td></tr>'; | ||
65 | } | ||
66 | } | ||
67 | else echo 'No updates for client '.$client.' available.'; | ||
68 | echo '</table>'; | ||
69 | echo '</pre>'; | ||
70 | } | ||
71 | elseif($op=="update") | ||
72 | { | ||
73 | echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>'); | ||
74 | echo '<br>'; | ||
75 | echo '<pre><div align=left class=left>'; | ||
76 | editvar("VERBOSE","off","/etc/mage.rc"); | ||
77 | |||
78 | // update rsync server location | ||
79 | niro | 2020 | $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, 'client_locations.rsync'); |
80 | niro | 1610 | editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc"); |
81 | editvar("RSYNC",$rsync,"/etc/mage.rc"); | ||
82 | |||
83 | niro | 1629 | // update repository server location |
84 | $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'); | ||
85 | editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc"); | ||
86 | editvar("MIRRORS",$repository,"/etc/mage.rc"); | ||
87 | |||
88 | // update samba update host | ||
89 | $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'); | ||
90 | editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc"); | ||
91 | |||
92 | // update samba update user | ||
93 | $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'); | ||
94 | editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc"); | ||
95 | |||
96 | // update samba update password | ||
97 | $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'); | ||
98 | editvar("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc"); | ||
99 | niro | 2020 | system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage update"'); |
100 | niro | 1629 | |
101 | niro | 1610 | echo '</div></pre>'; |
102 | echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>'; | ||
103 | } | ||
104 | elseif($op=="upgrade") | ||
105 | { | ||
106 | echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>'); | ||
107 | echo '<br>'; | ||
108 | echo '<pre><div align=left class=left>'; | ||
109 | editvar("VERBOSE","off","/etc/mage.rc"); | ||
110 | |||
111 | // update rsync server location | ||
112 | $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'); | ||
113 | editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc"); | ||
114 | editvar("RSYNC",$rsync,"/etc/mage.rc"); | ||
115 | |||
116 | // update repository server location | ||
117 | $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'); | ||
118 | editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc"); | ||
119 | editvar("MIRRORS",$repository,"/etc/mage.rc"); | ||
120 | |||
121 | // update samba update host | ||
122 | $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'); | ||
123 | editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc"); | ||
124 | |||
125 | // update samba update user | ||
126 | $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'); | ||
127 | editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc"); | ||
128 | |||
129 | // update samba update password | ||
130 | $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'); | ||
131 | editvar("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc"); | ||
132 | |||
133 | |||
134 | # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first | ||
135 | niro | 2020 | exec($sshcmd.' '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err); |
136 | niro | 1610 | if($err!=0) |
137 | { | ||
138 | niro | 2019 | echo '"update-alx" missing on client "'.$client.'". Updating mage and alxconfig-ng first ...<br>'; |
139 | system($sshcmd.' '.$ip.' "NOCOLORS=true mage install mage"'); | ||
140 | system($sshcmd.' '.$ip.' "NOCOLORS=true mage install alxconfig-ng"'); | ||
141 | niro | 1610 | } |
142 | niro | 2020 | exec($sshcmd.' '.$ip.' "NOCOLORS=true /usr/sbin/update-alx && exit 0 || exit 1"',$outarr,$err); |
143 | niro | 1610 | echo '</div></pre>'; |
144 | if ($err!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>'; | ||
145 | else echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>'; | ||
146 | } | ||
147 | else echo 'unkown operation'; | ||
148 | } | ||
149 | |||
150 | else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>'); | ||
151 | } | ||
152 | echo '</td></tr></table>'; | ||
153 | ?> |
Properties
Name | Value |
---|---|
svn:executable | * |