[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-clonage/sources/scripts/ -> se3_get_slitaz.sh (source)

   1  #!/bin/bash
   2  
   3  # $Id: se3_get_slitaz.sh 6661 2011-11-30 18:20:55Z crob $
   4  # Auteur: Stephane Boireau
   5  # Derniere modification: 30/11/2011
   6  
   7  # - telecharger SliTaz depuis http://wawadeb.crdp.ac-caen.fr/iso/slitaz/
   8  
   9  . /usr/share/se3/includes/config.inc.sh -d
  10  . /usr/share/se3/includes/functions.inc.sh
  11  
  12  COLTITRE="\033[1;35m"   # Rose
  13  COLPARTIE="\033[1;34m"  # Bleu
  14  
  15  COLTXT="\033[0;37m"     # Gris
  16  COLCHOIX="\033[1;33m"   # Jaune
  17  COLDEFAUT="\033[0;33m"  # Brun-jaune
  18  COLSAISIE="\033[1;32m"  # Vert
  19  
  20  COLCMD="\033[1;37m"     # Blanc
  21  
  22  COLERREUR="\033[1;31m"  # Rouge
  23  COLINFO="\033[0;36m"    # Cyan
  24  
  25  # Parametres
  26  timestamp=$(date +%s)
  27  timedate=$(date "+%Y%m%d_%H%M%S")
  28  
  29  src="http://wawadeb.crdp.ac-caen.fr/iso/slitaz"
  30  
  31  tmp="/var/se3/tmp_slitaz_$timedate}"
  32  mkdir -p "$tmp"
  33  chmod 700 $tmp
  34  
  35  # ========================================
  36  
  37  # Valeurs des versions en place recuperees de se3db.params:
  38  version_noyo_slitaz_en_place="$slitaz_noyo_version"
  39  version_rootfs_slitaz_en_place="$slitaz_roofs_version"
  40  
  41  # ========================================
  42  
  43  t=$(echo "$*" | grep "check_version")
  44  if [ -n "$t" ]; then
  45      cd $tmp
  46      wget $src/versions.txt > /dev/null 2>&1
  47      if [ "$?" = 0 -a -e versions.txt ]; then
  48          version_noyo_slitaz_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f1)
  49          version_rootfs_slitaz_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f1)
  50  
  51          # Pour le premier lancement: mise en place du nouveau dispositif
  52          if [ -z "$version_noyo_slitaz_en_place" ]; then
  53              md5_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f2)
  54              if [ -e "/tftpboot/bzImage" ]; then
  55                  md5_en_place=$(md5sum /tftpboot/bzImage|cut -d" " -f1)
  56                  if [ "$md5_en_place" = "$md5_en_ligne" ]; then
  57                      slitaz_noyo_version=$version_noyo_slitaz_en_ligne
  58                      SETMYSQL slitaz_noyo_version "$slitaz_noyo_version" "version actuelle du noyau SliTaz" 7
  59                      version_noyo_slitaz_en_place=$version_noyo_slitaz_en_ligne
  60                  fi
  61              fi
  62  
  63          fi
  64  
  65          if [ -z "$version_rootfs_slitaz_en_place" ]; then
  66              md5_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f2)
  67              if [ -e "/tftpboot/rootfs.gz" ]; then
  68                  md5_en_place=$(md5sum /tftpboot/rootfs.gz|cut -d" " -f1)
  69                  if [ "$md5_en_place" = "$md5_en_ligne" ]; then
  70                      slitaz_roofs_version=$version_rootfs_slitaz_en_ligne
  71                      SETMYSQL slitaz_roofs_version "$slitaz_roofs_version" "version actuelle du rootfs SliTaz" 7
  72                      version_rootfs_slitaz_en_place=$version_rootfs_slitaz_en_ligne
  73                  fi
  74              fi
  75  
  76          fi
  77  
  78  
  79          temoin_erreur="n"
  80          temoin_fichier_manquant="n"
  81          if [ ! -e "/tftpboot/bzImage" ]; then
  82              temoin_fichier_manquant="y"
  83              version_noyo_slitaz_en_place="<span style='color:red'>Absent</span>"
  84          else
  85              md5_en_place=$(md5sum /tftpboot/bzImage|cut -d" " -f1)
  86              md5_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f2)
  87      
  88              if [ "$md5_en_ligne" != "$md5_en_place" ]; then
  89                  version_noyo_slitaz_en_place="<span style='color:red'>Somme MD5 incorrecte</span>"
  90                  temoin_erreur="y"
  91              fi
  92          fi
  93  
  94          if [ ! -e "/tftpboot/rootfs.gz" ]; then
  95              temoin_fichier_manquant="y"
  96              version_rootfs_slitaz_en_place="<span style='color:red'>Absent</span>"
  97          else
  98              md5_en_place=$(md5sum /tftpboot/rootfs.gz|cut -d" " -f1)
  99              md5_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f2)
 100      
 101              if [ "$md5_en_ligne" != "$md5_en_place" ]; then
 102                  version_rootfs_slitaz_en_place="<span style='color:red'>Somme MD5 incorrecte</span>"
 103                  temoin_erreur="y"
 104              fi
 105          fi
 106  
 107          if [ "$temoin_erreur" != "y" -a "$temoin_fichier_manquant" != "y" -a "$version_noyo_slitaz_en_ligne" = "$version_noyo_slitaz_en_place" -a "$version_rootfs_slitaz_en_ligne" = "$version_rootfs_slitaz_en_place" ]; then
 108              echo "<p><span style='color:green'>Dispositif &agrave; jour</span></p>";
 109          else
 110              echo "<p><span style='color:red'>Mise &agrave; jour disponible</span></p>";
 111          fi
 112  
 113          echo "<table class='crob'>
 114  <tr>
 115      <th>&nbsp;</th>
 116      <th>Sur votre SE3</th>
 117      <th>En ligne</th>
 118  </tr>
 119  <tr>
 120      <th>Noyau SliTaz</th>
 121      <td>$version_noyo_slitaz_en_place</td>
 122      <td>$version_noyo_slitaz_en_ligne</td>
 123  </tr>
 124  <tr>
 125      <th>rootfs SliTaz</th>
 126      <td>$version_rootfs_slitaz_en_place</td>
 127      <td>$version_rootfs_slitaz_en_ligne</td>
 128  </tr>
 129  </table>";
 130  
 131      else
 132          echo "<p><span style='color:red'>ECHEC du telechargement du fichier des versions.</span></p>"
 133      fi
 134  
 135      exit
 136  fi
 137  
 138  # ========================================
 139  
 140  t=$(echo "$*" | grep "mode=html")
 141  if [ -z "$t" ]; then
 142      mode="cmdline"
 143  else
 144      mode="html"
 145  fi
 146  
 147  if [ "$mode" = "cmdline" ]; then
 148      echo -e "$COLTXT"
 149  else
 150      echo "<pre>"
 151      echo "<h3>"
 152  fi
 153  echo "Mise en place des fichiers utiles pour SliTaz en boot PXE."
 154  if [ "$mode" = "cmdline" ]; then
 155      echo -e "$COLCMD"
 156  else
 157      echo "</h3>"
 158  fi
 159  
 160  # Telecharger
 161  cd $tmp
 162  wget $src/versions.txt
 163  if [ "$?" != "0" ]; then
 164      if [ "$mode" = "cmdline" ]; then
 165          echo -e "$COLERREUR"
 166      else
 167          echo "<span style='color:red'>"
 168      fi
 169      echo "ERREUR lors du telechargement de $src/versions.txt"
 170      echo "ABANDON."
 171      if [ "$mode" = "cmdline" ]; then
 172          echo -e "$COLTXT"
 173      else
 174          echo "</span>"
 175          echo "</pre>"
 176      fi
 177      exit
 178  else
 179      if [ "$mode" = "cmdline" ]; then
 180          echo -e "$COLINFO"
 181      else
 182          echo "<span style='color:green'>"
 183      fi
 184      echo "SUCCES du telechargement de $src/versions.txt"
 185      if [ "$mode" = "cmdline" ]; then
 186          echo -e "$COLTXT"
 187      else
 188          echo "</span>"
 189      fi
 190  fi
 191  
 192  version_noyo_slitaz_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f1)
 193  version_rootfs_slitaz_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f1)
 194  
 195  # On controle si des fichiers SliTaz sont deja en place
 196  if [ -e "/tftpboot/bzImage" -a -e "/tftpboot/rootfs.gz" ]; then
 197  
 198      # Pour le premier lancement: mise en place du nouveau dispositif
 199      if [ -z "$version_noyo_slitaz_en_place" ]; then
 200          md5_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f2)
 201          if [ -e "/tftpboot/bzImage" ]; then
 202              md5_en_place=$(md5sum /tftpboot/bzImage|cut -d" " -f1)
 203              if [ "$md5_en_place" = "$md5_en_ligne" ]; then
 204                  slitaz_noyo_version=$version_noyo_slitaz_en_ligne
 205                  SETMYSQL slitaz_noyo_version "$slitaz_noyo_version" "version actuelle du noyau SliTaz" 7
 206                  version_noyo_slitaz_en_place=$version_noyo_slitaz_en_ligne
 207              fi
 208          fi
 209  
 210      fi
 211  
 212      if [ -z "$version_rootfs_slitaz_en_place" ]; then
 213          md5_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f2)
 214          if [ -e "/tftpboot/rootfs.gz" ]; then
 215              md5_en_place=$(md5sum /tftpboot/rootfs.gz|cut -d" " -f1)
 216              if [ "$md5_en_place" = "$md5_en_ligne" ]; then
 217                  slitaz_roofs_version=$version_rootfs_slitaz_en_ligne
 218                  SETMYSQL slitaz_roofs_version "$slitaz_roofs_version" "version actuelle du rootfs SliTaz" 7
 219                  version_rootfs_slitaz_en_place=$version_rootfs_slitaz_en_ligne
 220              fi
 221          fi
 222  
 223      fi
 224  
 225  
 226      if [ -e "/tftpboot/bzImage" ]; then
 227          md5_en_place=$(md5sum /tftpboot/bzImage|cut -d" " -f1)
 228          md5_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f2)
 229  
 230          if [ "$md5_en_ligne" != "$md5_en_place" ]; then
 231              version_noyo_slitaz_en_place=""
 232          fi
 233      fi
 234  
 235      if [ -e "/tftpboot/rootfs.gz" ]; then
 236          md5_en_place=$(md5sum /tftpboot/rootfs.gz|cut -d" " -f1)
 237          md5_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f2)
 238  
 239          if [ "$md5_en_ligne" != "$md5_en_place" ]; then
 240              version_rootfs_slitaz_en_place=""
 241          fi
 242      fi
 243  
 244  
 245      # On controle la version des fichiers
 246      if [ "$version_noyo_slitaz_en_ligne" = "$version_noyo_slitaz_en_place" -a "$version_rootfs_slitaz_en_ligne" = "$version_rootfs_slitaz_en_place" ]; then
 247  
 248          if [ "$mode" = "cmdline" ]; then
 249              echo -e "$COLINFO"
 250          else
 251              echo "<span style='color:green'>"
 252          fi
 253          echo "Les fichiers de bzImage et rootfs.gz de SliTaz sont deja les plus recents; On ne les re-telecharge pas."
 254          if [ "$mode" = "cmdline" ]; then
 255              echo -e "$COLTXT"
 256          else
 257              echo "</span>"
 258          fi
 259          temoin_telech_requis="n"
 260      else
 261          # La version a change.
 262          temoin_telech_requis="y"
 263      fi
 264  else
 265      # Il manque au moins un fichier, on telecharge pour mettre a jour
 266      temoin_telech_requis="y"
 267  fi
 268  
 269  if [ "$temoin_telech_requis" = "y" ]; then
 270  
 271      md5_en_place=""
 272      md5_en_ligne=""
 273      if [ -e "/tftpboot/bzImage" ]; then
 274          md5_en_place=$(md5sum /tftpboot/bzImage|cut -d" " -f1)
 275          md5_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f2)
 276      fi
 277  
 278      if [ ! -e "/tftpboot/bzImage" -o "$md5_en_ligne" != "$md5_en_place" -o "$version_noyo_slitaz_en_ligne" != "$version_noyo_slitaz_en_place" ]; then
 279          wget $src/bzImage
 280          if [ "$?" != "0" ]; then
 281              if [ "$mode" = "cmdline" ]; then
 282                  echo -e "$COLERREUR"
 283              else
 284                  echo "<span style='color:red'>"
 285              fi
 286              echo "ERREUR lors du telechargement de $src/bzImage"
 287              echo "ABANDON."
 288              if [ "$mode" = "cmdline" ]; then
 289                  echo -e "$COLTXT"
 290              else
 291                  echo "</span>"
 292                  echo "</pre>"
 293              fi
 294              exit
 295          else
 296              if [ "$mode" = "cmdline" ]; then
 297                  echo -e "$COLINFO"
 298              else
 299                  echo "<span style='color:green'>"
 300              fi
 301              echo "SUCCES du telechargement de $src/bzImage"
 302              if [ "$mode" = "cmdline" ]; then
 303                  echo -e "$COLTXT"
 304              else
 305                  echo "</span>"
 306              fi
 307      
 308              md5_telech=$(md5sum bzImage|cut -d" " -f1)
 309              md5_en_ligne=$(grep ";bzImage$" $tmp/versions.txt | cut -d";" -f2)
 310              if [ "$md5_telech" != "$md5_en_ligne" ]; then
 311                  if [ "$mode" = "cmdline" ]; then
 312                      echo -e "$COLERREUR"
 313                  else
 314                      echo "<span style='color:red'>"
 315                  fi
 316                  echo "ANOMALIE: La somme MD5 ne coincide pas: $md5_en_ligne en ligne et $md5_telech telecharge."
 317                  if [ "$mode" = "cmdline" ]; then
 318                      echo -e "$COLTXT"
 319                  else
 320                      echo "</span>"
 321                      echo "</pre>"
 322                  fi
 323                  exit
 324              fi
 325          fi
 326  
 327          liste_fichiers_a_copier="$liste_fichiers_a_copier bzImage"
 328      fi
 329  
 330  
 331      md5_en_place=""
 332      md5_en_ligne=""
 333      if [ -e "/tftpboot/rootfs.gz" ]; then
 334          md5_en_place=$(md5sum /tftpboot/rootfs.gz|cut -d" " -f1)
 335          md5_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f2)
 336      fi
 337  
 338      if [ ! -e "/tftpboot/rootfs.gz" -o "$md5_en_ligne" != "$md5_en_place" -o "$version_rootfs_slitaz_en_ligne" != "$version_rootfs_slitaz_en_place" ]; then
 339  
 340          wget $src/rootfs.gz
 341          if [ "$?" != "0" ]; then
 342              if [ "$mode" = "cmdline" ]; then
 343                  echo -e "$COLERREUR"
 344              else
 345                  echo "<span style='color:red'>"
 346              fi
 347              echo "ERREUR lors du telechargement de $src/rootfs.gz"
 348              echo "ABANDON."
 349              if [ "$mode" = "cmdline" ]; then
 350                  echo -e "$COLTXT"
 351              else
 352                  echo "</span>"
 353                  echo "</pre>"
 354              fi
 355              exit
 356          else
 357              if [ "$mode" = "cmdline" ]; then
 358                  echo -e "$COLINFO"
 359              else
 360                  echo "<span style='color:green'>"
 361              fi
 362              echo "SUCCES du telechargement de $src/rootfs.gz"
 363              if [ "$mode" = "cmdline" ]; then
 364                  echo -e "$COLTXT"
 365              else
 366                  echo "</span>"
 367              fi
 368  
 369              md5_telech=$(md5sum rootfs.gz|cut -d" " -f1)
 370              md5_en_ligne=$(grep ";rootfs.gz$" $tmp/versions.txt | cut -d";" -f2)
 371              if [ "$md5_telech" != "$md5_en_ligne" ]; then
 372                  if [ "$mode" = "cmdline" ]; then
 373                      echo -e "$COLERREUR"
 374                  else
 375                      echo "<span style='color:red'>"
 376                  fi
 377                  echo "ANOMALIE: La somme MD5 ne coincide pas: $md5_en_ligne en ligne et $md5_telech telecharge."
 378                  if [ "$mode" = "cmdline" ]; then
 379                      echo -e "$COLTXT"
 380                  else
 381                      echo "</span>"
 382                      echo "</pre>"
 383                  fi
 384                  exit
 385              fi
 386          fi
 387          liste_fichiers_a_copier="$liste_fichiers_a_copier rootfs.gz"
 388      fi
 389  
 390  
 391      if [ "$mode" = "cmdline" ]; then
 392          echo -e "$COLTXT"
 393      else
 394          echo "<b>"
 395      fi
 396      echo "Copie des fichiers vers leur emplacement..."
 397      if [ "$mode" = "cmdline" ]; then
 398          echo -e "$COLCMD"
 399      else
 400          echo "</b>"
 401      fi
 402      cp -fv $liste_fichiers_a_copier /tftpboot/
 403  
 404      if [ "$?" != "0"  ]; then
 405          if [ "$mode" = "cmdline" ]; then
 406              echo -e "$COLERREUR"
 407          else
 408              echo "<span style='color:red'>"
 409          fi
 410  
 411          echo "ERREUR lors de la copie"
 412  
 413          if [ "$mode" = "cmdline" ]; then
 414              echo -e "$COLTXT"
 415          else
 416              echo "</span>"
 417              echo "</pre>"
 418          fi
 419      else
 420          SETMYSQL slitaz_noyo_version "$version_noyo_slitaz_en_ligne" "version actuelle du noyau SliTaz" 7
 421          SETMYSQL slitaz_roofs_version "$version_rootfs_slitaz_en_ligne" "version actuelle du rootfs SliTaz" 7
 422      fi
 423  fi
 424  
 425  rm -fr $tmp
 426  
 427  if [ "$mode" = "cmdline" ]; then
 428      echo -e "$COLTITRE"
 429  else
 430      echo "<b>"
 431  fi
 432  echo "Termine."
 433  if [ "$mode" = "cmdline" ]; then
 434      echo -e "$COLTXT"
 435  else
 436      echo "</b>"
 437      echo "</pre>"
 438  fi


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1