Blame view

create_image.sh 2.33 KB
3e470988   hmalti   First commit
1
  #!/bin/bash
3e470988   hmalti   First commit
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  
  NOM_IMAGE=$3; # L'utilisateur devra spécifier le nom de l'image
  SIZE=$4; #L'utilisateur devra spécifier la taille du disque qu'il souhaite allouer 
  REPERTOIRE=$5; #L'utilisateur devra spécifier le chemin ou il mettra l'image
  
  #ici block size vaut 1024 (on alloue par 1 méga) 
  # La commande resseblera à : ./baleine.sh image create nom 5120 
  
  
  #condition de bordure pour SIZE
  if [ "$SIZE" -lt 0 ] || [ "$SIZE" -gt 10240 ] || [ -z $SIZE ]; then #vérifie que l'argument size est bien donné, qu'il n'est pas supérieur ou inférieur à 0 / 10240
      echo "Mauvaise valeur, on met par défaut 10 Giga ! "
      $SIZE=10240
  fi
  
b1087939   hmalti   Ajout commandes
17
  mkdir -p $PATH_BALEINE/images
3e470988   hmalti   First commit
18
19
20
21
  
  #condition pour le répertoire
  if [[ -z $REPERTOIRE ]]; then #si l'utilisateur oublie de donner le path on utilise celui-ci par défaut 
    echo "Il n'y pas eu d'argements donnés pour répertoire, je fais moi même le chemin" 
b1087939   hmalti   Ajout commandes
22
    REPERTOIRE=$PATH_BALEINE/images
3e470988   hmalti   First commit
23
24
25
26
27
28
29
  fi
  
  #vérification que l'utilisateur donne bien un nom à l'image
  if [[ -z "$NOM_IMAGE" ]]; then 
    echo "Il faut donner le nom de l'image ! Relancez la commande avec les bons arguments."
    exit
  fi
b1087939   hmalti   Ajout commandes
30
31
32
33
34
35
  # #génération de nombres aléatoires afin de créer à chaque fois un fichier avec un nombre unique (éviter qu'un soit écraser)
  # NUMBER=$(cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | sed -e 's/^0*//' | head --bytes 3)
  # if [ "$NUMBER" == "" ]; then
  #   NUMBER=0
  # fi
  echo "Le repertoire est $REPERTOIRE"
3e470988   hmalti   First commit
36
  #Crée image
b1087939   hmalti   Ajout commandes
37
  FILE=$NOM_IMAGE.manifest
3e470988   hmalti   First commit
38
39
  echo "Je vais commencer à allouer !"
  dd if=/dev/zero of=$REPERTOIRE/$NOM_IMAGE bs=1024k count=$SIZE 
b1087939   hmalti   Ajout commandes
40
41
42
43
44
45
  touch  FILE
  echo "nom image:$NOM_IMAGE" >> FILE #nom de l'image
  echo "taille:$SIZE">> FILE #taille de l'image
  echo "chemin:$REPERTOIRE">> FILE #son chemin
  
  
3e470988   hmalti   First commit
46
  
b1087939   hmalti   Ajout commandes
47
48
  if [[ ! -d "$PATH_MANIFEST/images" ]]; then 
    mkdir -p $PATH_MANIFEST/images  #&& mv $NOM_IMAGE.$NUMBER.manifest $REPERTOIRE/images
3e470988   hmalti   First commit
49
  fi
b1087939   hmalti   Ajout commandes
50
  mv $NOM_IMAGE.manifest $PATH_MANIFEST/images
3e470988   hmalti   First commit
51
52
53
54
  
  
  
  #création du système de fichiers au format "ext4"
b1087939   hmalti   Ajout commandes
55
  mkfs.ext4 $REPERTOIRE/images/$NOM_IMAGE
3e470988   hmalti   First commit
56
57
58
59
60
61
62
63
  
  
  
  echo "je vais exporter le proxy"
  export http_proxy=http://proxy.polytech-lille.fr:3128
  
  #Création de l'arborescence Debian avec debootstrap
  echo "Je vais faire le debootstrap"
b1087939   hmalti   Ajout commandes
64
  debootstrap --include=apache2,vim,nano  stable /mnt/baleine/$NOM_IMAGE
3e470988   hmalti   First commit
65
66
67
  
  #On renseigne le fichier fstab du conteneur
  echo "proc /proc proc defaults 0 0" >> /mnt/$NOM_IMAGE/etc/fstab