[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/bin/bash 2 3 # $Id: se3_get_sysresccd.sh 7680 2013-02-22 18:06:38Z crob $ 4 # Auteur: Stephane Boireau 5 # Dernière modification: 10/11/2012 6 7 # Ajout en visudo: 8 # Cmnd_Alias SE3CLONAGE=/usr/share/se3/scripts/se3_tftp_boot_pxe.sh,/usr/share/se3/scripts/se3_get_sysresccd.sh 9 10 # Coquille vide pour le moment 11 # - telecharger SysRescCD depuis http://wawadeb.crdp.ac-caen.fr/iso/sysresccd/ 12 # Deux options: 13 # . on n'y met que les sysrcd.dat, sysrcd.md5, rescuecd et initram.igz pour alleger... mais il risque de manquer les noyaux alternatifs utiles pour certaines stations 14 # . on y met l'ISO et on fait le montage en loop et la recup des fichiers utiles une fois le telechargement effectue 15 # - Mettre en place les fichiers sysrcd.dat, sysrcd.md5, autorun2 et scripts.tar.gz dans /var/www/sysresccd 16 # - Mettre en place les fichiers noyau et initram dans /tftpboot/ 17 18 #echo "Script non encore fonctionnel... la mise en place est a faire a la mano." 19 #exit 20 . /usr/share/se3/includes/config.inc.sh -d 21 . /usr/share/se3/includes/functions.inc.sh 22 23 COLTITRE="\033[1;35m" # Rose 24 COLPARTIE="\033[1;34m" # Bleu 25 26 COLTXT="\033[0;37m" # Gris 27 COLCHOIX="\033[1;33m" # Jaune 28 COLDEFAUT="\033[0;33m" # Brun-jaune 29 COLSAISIE="\033[1;32m" # Vert 30 31 COLCMD="\033[1;37m" # Blanc 32 33 COLERREUR="\033[1;31m" # Rouge 34 COLINFO="\033[0;36m" # Cyan 35 36 # Parametres 37 timestamp=$(date +%s) 38 timedate=$(date "+%Y%m%d_%H%M%S") 39 40 src="http://wawadeb.crdp.ac-caen.fr/iso/sysresccd" 41 42 tmp="/var/se3/tmp_sysresccd_$timedate}" 43 mkdir -p "$tmp" 44 chmod 700 $tmp 45 46 # ======================================== 47 48 t=$(echo "$*" | grep "check_version") 49 if [ -n "$t" ]; then 50 cd $tmp 51 wget http://wawadeb.crdp.ac-caen.fr/iso/sysresccd/versions.txt > /dev/null 2>&1 52 if [ "$?" = 0 -a -e versions.txt ]; then 53 version_srcd_en_ligne=$(grep ";systemrescuecd.iso$" $tmp/versions.txt | cut -d";" -f1) 54 version_autorun2_en_ligne=$(grep ";autorun2$" $tmp/versions.txt | cut -d";" -f1) 55 version_scripts_en_ligne=$(grep ";scripts.tar.gz$" $tmp/versions.txt | cut -d";" -f1) 56 57 version_srcd_en_place="$srcd_version" 58 version_autorun2_en_place="$srcd_autorun2_vers" 59 version_scripts_en_place="$srcd_scripts_vers" 60 61 if [ "$version_srcd_en_ligne" = "$version_srcd_en_place" -a "$version_autorun2_en_ligne" = "$version_autorun2_en_place" -a "$version_scripts_en_ligne" = "$version_scripts_en_place" ]; then 62 echo "<p><span style='color:green'>Dispositif à jour</span></p>"; 63 else 64 echo "<p><span style='color:red'>Mise à jour disponible</span></p>"; 65 fi 66 67 echo "<table class='crob'> 68 <tr> 69 <th> </th> 70 <th>Sur votre SE3</th> 71 <th>En ligne</th> 72 </tr> 73 <tr> 74 <th>SystemRescueCD</th> 75 <td>$version_srcd_en_place</td> 76 <td>$version_srcd_en_ligne</td> 77 </tr> 78 <tr> 79 <th>Autorun</th> 80 <td>$version_autorun2_en_place</td> 81 <td>$version_autorun2_en_ligne</td> 82 </tr> 83 <tr> 84 <th>Scripts</th> 85 <td>$version_scripts_en_place</td> 86 <td>$version_scripts_en_ligne</td> 87 </tr> 88 </table>"; 89 90 else 91 echo "<p><span style='color:red'>ECHEC du telechargement du fichier des versions.</span></p>" 92 fi 93 94 exit 95 fi 96 97 # ======================================== 98 99 t=$(echo "$*" | grep "mode=html") 100 if [ -z "$t" ]; then 101 mode="cmdline" 102 else 103 mode="html" 104 fi 105 106 if [ "$mode" = "cmdline" ]; then 107 echo -e "$COLTXT" 108 else 109 echo "<pre>" 110 echo "<h3>" 111 fi 112 echo "Mise en place des fichiers utiles pour SystemRescueCD en boot PXE." 113 if [ "$mode" = "cmdline" ]; then 114 echo -e "$COLCMD" 115 else 116 echo "</h3>" 117 fi 118 119 # Emplacement des fichiers telecharges par SysRescCD lors du boot 120 depot_sysrcd="/var/www/sysresccd" 121 mkdir -p "$depot_sysrcd" 122 chmod 755 "$depot_sysrcd" 123 124 cpt=0 125 126 #=================================================================== 127 128 cd $tmp 129 wget $src/versions.txt 130 if [ "$?" != "0" ]; then 131 if [ "$mode" = "cmdline" ]; then 132 echo -e "$COLERREUR" 133 else 134 echo "<span style='color:red'>" 135 fi 136 echo "ERREUR lors du telechargement de $src/versions.txt" 137 echo "ABANDON." 138 if [ "$mode" = "cmdline" ]; then 139 echo -e "$COLTXT" 140 else 141 echo "</span>" 142 echo "</pre>" 143 fi 144 exit 145 else 146 if [ "$mode" = "cmdline" ]; then 147 echo -e "$COLINFO" 148 else 149 echo "<span style='color:green'>" 150 fi 151 echo "SUCCES du telechargement de $src/versions.txt" 152 if [ "$mode" = "cmdline" ]; then 153 echo -e "$COLTXT" 154 else 155 echo "</span>" 156 fi 157 cpt=$(($cpt+1)) 158 fi 159 version_srcd_en_place="$srcd_version" 160 version_srcd_en_ligne=$(grep ";systemrescuecd.iso$" $tmp/versions.txt | cut -d";" -f1) 161 162 #if [ -e "$depot_sysrcd/sysrcd.dat" -a -e "$depot_sysrcd/sysrcd.md5" -a -e "/tftpboot/rescuecd" -a -e "/tftpboot/rescue64" -a -e "/tftpboot/altker32" -a -e "/tftpboot/initram.igz" ]; then 163 if [ -e "$depot_sysrcd/sysrcd.dat" -a -e "$depot_sysrcd/sysrcd.md5" -a -e "/tftpboot/rescue32" -a -e "/tftpboot/rescue64" -a -e "/tftpboot/altker32" -a -e "/tftpboot/altker64" -a -e "/tftpboot/initram.igz" ]; then 164 # On controle la version SysRescCD 165 version_srcd_en_place="$srcd_version" 166 version_srcd_en_ligne=$(grep ";systemrescuecd.iso$" $tmp/versions.txt | cut -d";" -f1) 167 if [ "$version_srcd_en_place" = "$version_srcd_en_ligne" ]; then 168 if [ "$mode" = "cmdline" ]; then 169 echo -e "$COLINFO" 170 else 171 echo "<span style='color:green'>" 172 fi 173 echo "Les fichiers de l'ISO sont deja les plus recents; On ne re-telecharge pas l'ISO." 174 if [ "$mode" = "cmdline" ]; then 175 echo -e "$COLTXT" 176 else 177 echo "</span>" 178 fi 179 temoin_sysrcd="n" 180 else 181 # La version a change. 182 temoin_sysrcd="y" 183 fi 184 else 185 # Il manque au moins un fichier, on telecharge pour mettre a jour 186 temoin_sysrcd="y" 187 fi 188 189 if [ "$temoin_sysrcd" = "y" ]; then 190 wget $src/systemrescuecd.iso 191 if [ "$?" != "0" ]; then 192 if [ "$mode" = "cmdline" ]; then 193 echo -e "$COLERREUR" 194 else 195 echo "<span style='color:red'>" 196 fi 197 echo "ERREUR lors du telechargement de $src/systemrescuecd.iso" 198 echo "ABANDON." 199 if [ "$mode" = "cmdline" ]; then 200 echo -e "$COLTXT" 201 else 202 echo "</span>" 203 echo "</pre>" 204 fi 205 exit 206 else 207 if [ "$mode" = "cmdline" ]; then 208 echo -e "$COLINFO" 209 else 210 echo "<span style='color:green'>" 211 fi 212 echo "SUCCES du telechargement de $src/systemrescuecd.iso" 213 if [ "$mode" = "cmdline" ]; then 214 echo -e "$COLTXT" 215 else 216 echo "</span>" 217 fi 218 219 md5_telech=$(md5sum systemrescuecd.iso|cut -d" " -f1) 220 md5_en_ligne=$(grep ";systemrescuecd.iso$" $tmp/versions.txt | cut -d";" -f2) 221 if [ "$md5_telech" != "$md5_en_ligne" ]; then 222 if [ "$mode" = "cmdline" ]; then 223 echo -e "$COLERREUR" 224 else 225 echo "<span style='color:red'>" 226 fi 227 echo "ANOMALIE: La somme MD5 ne coincide pas: $md5_en_ligne en ligne et $md5_telech telecharge." 228 if [ "$mode" = "cmdline" ]; then 229 echo -e "$COLTXT" 230 else 231 echo "</span>" 232 echo "</pre>" 233 fi 234 # Pour ne pas remplacer les fichiers par la suite. 235 temoin_sysrcd="n" 236 else 237 SETMYSQL srcd_version "$version_srcd_en_ligne" "version actuelle de System Rescue CD" 7 238 # if [ -n "$version_srcd_en_place" ]; then 239 # echo "UPDATE params SET value='$version_srcd_en_ligne' WHERE name='srcd_version';" | mysql -N -h $dbhost -u $dbuser -p$dbpass $dbname 240 # else 241 # echo "INSERT INTO params SET value='$version_srcd_en_ligne', name='srcd_version';" | mysql -N -h $dbhost -u $dbuser -p$dbpass $dbname 242 # fi 243 fi 244 cpt=$(($cpt+1)) 245 fi 246 fi 247 248 #=================================================================== 249 250 # Pour parer des bugs suite a des suppressions de fichiers, on recupere la version meme si ce n'est pas utile 251 version_autorun2_en_place="$srcd_autorun2_vers" 252 version_autorun2_en_ligne=$(grep ";autorun2$" $tmp/versions.txt | cut -d";" -f1) 253 if [ -e "$depot_sysrcd/autorun2" ]; then 254 # On controle la version 255 if [ "$version_autorun2_en_place" = "$version_autorun2_en_ligne" ]; then 256 if [ "$mode" = "cmdline" ]; then 257 echo -e "$COLINFO" 258 else 259 echo "<span style='color:green'>" 260 fi 261 echo "Le fichier autorun2 est deja le plus recent; On ne re-telecharge pas." 262 if [ "$mode" = "cmdline" ]; then 263 echo -e "$COLTXT" 264 else 265 echo "</span>" 266 fi 267 temoin_autorun2="n" 268 else 269 # La version a change. 270 temoin_autorun2="y" 271 fi 272 else 273 # Le fichier est manquant, on telecharge pour mettre a jour 274 temoin_autorun2="y" 275 fi 276 277 cd "$depot_sysrcd" 278 if [ "$temoin_autorun2" = "y" ]; then 279 if [ -e autorun2 ]; then 280 if [ -n "$version_autorun2_en_place" ]; then 281 mv autorun2 autorun2.$version_autorun2_en_place 282 autorun2_old=autorun2.$version_autorun2_en_place 283 else 284 tmpdate=$(stat -c '%y' autorun2|cut -d" " -f1,2|sed -e "s/ /_/g") 285 mv autorun2 autorun2.old.$tmpdate 286 autorun2_old=autorun2.old.$tmpdate 287 fi 288 fi 289 290 wget $src/autorun2 291 if [ "$?" != "0" ]; then 292 if [ "$mode" = "cmdline" ]; then 293 echo -e "$COLERREUR" 294 else 295 echo "<span style='color:red'>" 296 fi 297 echo "ERREUR lors du telechargement de $src/autorun2" 298 echo "ABANDON." 299 if [ "$mode" = "cmdline" ]; then 300 echo -e "$COLTXT" 301 else 302 echo "</span>" 303 echo "</pre>" 304 fi 305 306 # On retablit l'autorun2 precedent 307 if [ -n "$autorun2_old" -a -e "$autorun2_old" ]; then 308 rm -f autorun2 309 mv $autorun2_old autorun2 310 fi 311 312 exit 313 else 314 if [ "$mode" = "cmdline" ]; then 315 echo -e "$COLINFO" 316 else 317 echo "<span style='color:green'>" 318 fi 319 echo "SUCCES du telechargement de $src/autorun2" 320 if [ "$mode" = "cmdline" ]; then 321 echo -e "$COLTXT" 322 else 323 echo "</span>" 324 fi 325 326 md5_telech=$(md5sum autorun2|cut -d" " -f1) 327 md5_en_ligne=$(grep ";autorun2$" $tmp/versions.txt | cut -d";" -f2) 328 if [ "$md5_telech" != "$md5_en_ligne" ]; then 329 if [ "$mode" = "cmdline" ]; then 330 echo -e "$COLERREUR" 331 else 332 echo "<span style='color:red'>" 333 fi 334 echo "ANOMALIE: La somme MD5 ne coincide pas: $md5_en_ligne en ligne et $md5_telech telecharge." 335 if [ "$mode" = "cmdline" ]; then 336 echo -e "$COLTXT" 337 else 338 echo "</span>" 339 echo "</pre>" 340 fi 341 342 # On retablit l'autorun2 precedent 343 if [ -n "$autorun2_old" -a -e "$autorun2_old" ]; then 344 rm -f autorun2 345 mv $autorun2_old autorun2 346 fi 347 348 else 349 SETMYSQL srcd_autorun2_vers "$version_autorun2_en_ligne" "version distante du script autorun" 7 350 # if [ -n "$version_autorun2_en_place" ]; then 351 # CHANGEMYSQL srcd_autorun2_vers "$version_autorun2_en_ligne" 352 # #echo "UPDATE params SET value='$version_autorun2_en_ligne' WHERE name='srcd_autorun2_vers';" | mysql -N -h $dbhost -u $dbuser -p$dbpass $dbname 353 # else 354 # 355 # #echo "INSERT INTO params SET value='$version_autorun2_en_ligne', name='srcd_autorun2_vers';" | mysql -N -h $dbhost -u $dbuser -p$dbpass $dbname 356 # fi 357 fi 358 cpt=$(($cpt+1)) 359 fi 360 fi 361 362 #=================================================================== 363 364 # Pour parer des bugs suite a des suppressions de fichiers, on recupere la version meme si ce n'est pas utile 365 version_scripts_en_place="$srcd_scripts_vers" 366 version_scripts_en_ligne=$(grep ";scripts.tar.gz$" $tmp/versions.txt | cut -d";" -f1) 367 if [ -e "$depot_sysrcd/scripts.tar.gz" ]; then 368 # On controle la version 369 if [ "$version_scripts_en_place" = "$version_scripts_en_ligne" ]; then 370 if [ "$mode" = "cmdline" ]; then 371 echo -e "$COLINFO" 372 else 373 echo "<span style='color:green'>" 374 fi 375 echo "Le fichier scripts.tar.gz est deja le plus recent; On ne re-telecharge pas." 376 if [ "$mode" = "cmdline" ]; then 377 echo -e "$COLTXT" 378 else 379 echo "</span>" 380 fi 381 temoin_scripts="n" 382 else 383 # La version a change. 384 temoin_scripts="y" 385 fi 386 else 387 # Le fichier est manquant, on telecharge pour mettre a jour 388 temoin_scripts="y" 389 fi 390 391 if [ "$temoin_scripts" = "y" ]; then 392 if [ -e scripts.tar.gz ]; then 393 if [ -n "$version_srcd_en_place" ]; then 394 mv scripts.tar.gz scripts.tar.gz.$version_scripts_en_place 395 scripts_old=scripts.tar.gz.$version_scripts_en_place 396 else 397 tmpdate=$(stat -c '%y' autorun2|cut -d" " -f1,2|sed -e "s/ /_/g") 398 mv scripts.tar.gz scripts.tar.gz.old.$tmpdate 399 scripts_old=scripts.tar.gz.old.$tmpdate 400 fi 401 fi 402 403 wget $src/scripts.tar.gz 404 if [ "$?" != "0" ]; then 405 if [ "$mode" = "cmdline" ]; then 406 echo -e "$COLERREUR" 407 else 408 echo "<span style='color:red'>" 409 fi 410 echo "ERREUR lors du telechargement de $src/scripts.tar.gz" 411 echo "ABANDON." 412 if [ "$mode" = "cmdline" ]; then 413 echo -e "$COLTXT" 414 else 415 echo "</span>" 416 echo "</pre>" 417 fi 418 419 # On retablit le scripts.tar.gz precedent 420 if [ -n "$scripts_old" -a -e "$scripts_old" ]; then 421 rm -f scripts.tar.gz 422 mv $scripts_old scripts.tar.gz 423 fi 424 425 exit 426 else 427 if [ "$mode" = "cmdline" ]; then 428 echo -e "$COLINFO" 429 else 430 echo "<span style='color:green'>" 431 fi 432 echo "SUCCES du telechargement de $src/scripts.tar.gz" 433 if [ "$mode" = "cmdline" ]; then 434 echo -e "$COLTXT" 435 else 436 echo "</span>" 437 fi 438 439 440 md5_telech=$(md5sum scripts.tar.gz|cut -d" " -f1) 441 md5_en_ligne=$(grep ";scripts.tar.gz$" $tmp/versions.txt | cut -d";" -f2) 442 if [ "$md5_telech" != "$md5_en_ligne" ]; then 443 if [ "$mode" = "cmdline" ]; then 444 echo -e "$COLERREUR" 445 else 446 echo "<span style='color:red'>" 447 fi 448 echo "ANOMALIE: La somme MD5 ne coincide pas: $md5_en_ligne en ligne et $md5_telech telecharge." 449 if [ "$mode" = "cmdline" ]; then 450 echo -e "$COLTXT" 451 else 452 echo "</span>" 453 echo "</pre>" 454 fi 455 456 # On retablit l'autorun2 precedent 457 if [ -n "$scripts_old" -a -e "$scripts_old" ]; then 458 rm -f scripts.tar.gz 459 mv $scripts_old scripts.tar.gz 460 fi 461 else 462 # la fcontion SETMYSQL fait un test si exist et fait un update si bersoin 463 SETMYSQL srcd_scripts_vers "$version_scripts_en_ligne" "version de scripts.tar.gz pour System Rescue CD" 7 464 # if [ -n "$version_scripts_en_place" ]; then 465 # echo "UPDATE params SET value='$version_scripts_en_ligne' WHERE name='srcd_scripts_vers';" | mysql -N -h $dbhost -u $dbuser -p$dbpass $dbname 466 # else 467 # echo "INSERT INTO params SET value='$version_scripts_en_ligne', name='srcd_scripts_vers';" | mysql -N -h $dbhost -u $dbuser -p$dbpass $dbname 468 # fi 469 fi 470 471 cpt=$(($cpt+1)) 472 fi 473 fi 474 475 if [ "$temoin_sysrcd" = "y" ]; then 476 if [ "$mode" = "cmdline" ]; then 477 echo -e "$COLTXT" 478 else 479 echo "<b>" 480 fi 481 echo "Montage de l'ISO en loop..." 482 if [ "$mode" = "cmdline" ]; then 483 echo -e "$COLCMD" 484 else 485 echo "</b>" 486 fi 487 mnt_loop="/mnt/loop_$timedate}" 488 mkdir -p $mnt_loop 489 chmod 700 $mnt_loop 490 mount -t iso9660 -o loop $tmp/systemrescuecd.iso $mnt_loop 491 mkdir -p /tftpboot 492 493 if [ "$mode" = "cmdline" ]; then 494 echo -e "$COLTXT" 495 else 496 echo "<b>" 497 fi 498 echo "Copie des fichiers de l'ISO vers leur emplacement..." 499 if [ "$mode" = "cmdline" ]; then 500 echo -e "$COLCMD" 501 else 502 echo "</b>" 503 fi 504 505 if [ -e $mnt_loop/isolinux/rescuecd ]; then 506 cp -fv $mnt_loop/isolinux/rescuecd /tftpboot/ 507 fi 508 if [ -e $mnt_loop/isolinux/rescue32 ]; then 509 cp -fv $mnt_loop/isolinux/rescue32 /tftpboot/ 510 fi 511 cp -fv $mnt_loop/isolinux/altker32 /tftpboot/ 512 cp -fv $mnt_loop/isolinux/rescue64 /tftpboot/ 513 cp -fv $mnt_loop/isolinux/altker64 /tftpboot/ 514 cp -fv $mnt_loop/isolinux/initram.igz /tftpboot/ 515 cp -fv $mnt_loop/sysrcd.dat $depot_sysrcd 516 cp -fv $mnt_loop/sysrcd.md5 $depot_sysrcd 517 518 cp -fv $mnt_loop/usb_inst.sh $depot_sysrcd 519 cp -fv $mnt_loop/usbstick.htm $depot_sysrcd 520 cp -fv $mnt_loop/version $depot_sysrcd 521 522 mkdir -p $depot_sysrcd/isolinux 523 cd $depot_sysrcd/isolinux 524 for i in rescue32 rescue64 altker32 initram.igz altker64 525 do 526 rm -f $i 527 ln -s /tftpboot/$i ./ 528 done 529 530 mkdir -p $depot_sysrcd/isolinux/maps 531 cp -fv $mnt_loop/isolinux/maps/fr.ktl $depot_sysrcd/isolinux/maps/ 532 533 mkdir -p $depot_sysrcd/usb_inst 534 cp -vf $mnt_loop/usb_inst/* $depot_sysrcd/usb_inst/ 535 536 mkdir -p $depot_sysrcd/sysresccd 537 cd $depot_sysrcd/sysresccd 538 if [ ! -e "memtest.bin" ]; then 539 ln -s /tftpboot/memtp ./memtest.bin 540 fi 541 542 if [ -e "/tftpboot/rescuecd" ]; then 543 if [ -e "/tftpboot/rescue32" ]; then 544 rm /tftpboot/rescuecd 545 cd /tftpboot 546 ln -s rescue32 rescuecd 547 cd / 548 else 549 mv /tftpboot/rescuecd /tftpboot/rescue32 550 cd /tftpboot 551 ln -s rescue32 rescuecd 552 cd / 553 fi 554 fi 555 556 # Nettoyage 557 if [ "$mode" = "cmdline" ]; then 558 echo -e "$COLTXT" 559 else 560 echo "<b>" 561 fi 562 echo "Demontage" 563 if [ "$mode" = "cmdline" ]; then 564 echo -e "$COLCMD" 565 else 566 echo "</b>" 567 fi 568 umount $mnt_loop 569 570 if [ "$mode" = "cmdline" ]; then 571 echo -e "$COLTXT" 572 else 573 echo "<b>" 574 fi 575 echo "Nettoyage" 576 if [ "$mode" = "cmdline" ]; then 577 echo -e "$COLCMD" 578 else 579 echo "</b>" 580 fi 581 rm -fr $mnt_loop 582 fi 583 rm -fr $tmp 584 585 if [ "$mode" = "cmdline" ]; then 586 echo -e "$COLTITRE" 587 else 588 echo "<b>" 589 fi 590 echo "Termine." 591 if [ "$mode" = "cmdline" ]; then 592 echo -e "$COLTXT" 593 else 594 echo "</b>" 595 echo "</pre>" 596 fi
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |