Blame view

create_image.sh 1.43 KB
5721892d   hmalti   Avancées
1
    #!/bin/bash
3e470988   hmalti   First commit
2
  
3e470988   hmalti   First commit
3
  
5161dfdb   hmalti   Améliorations scr...
4
5
6
7
8
9
10
11
12
13
14
15
  while getopts i:s:r: o; do
      case $o in
          (i) NOM_IMAGE=$OPTARG;;
          (s) SIZE=$OPTARG;;
          (r) REPERTOIRE=$OPTARG;;
          (p) PROXY=$OPTARG;;
      esac
  done
  
  #Block size vaut 1024 (allocution par 1 MB)
  if [ "$SIZE" == "" ] || [ "$SIZE" -lt 0 ] || [ "$SIZE" -gt 10240 ]; then
      SIZE=10240
3e470988   hmalti   First commit
16
17
  fi
  
5721892d   hmalti   Avancées
18
  echo "Le size est de $SIZE"
b1087939   hmalti   Ajout commandes
19
  mkdir -p $PATH_BALEINE/images
3e470988   hmalti   First commit
20
  
5161dfdb   hmalti   Améliorations scr...
21
22
  if [[ -z $REPERTOIRE ]]; then
      REPERTOIRE=$PATH_BALEINE/images
3e470988   hmalti   First commit
23
24
  fi
  
5161dfdb   hmalti   Améliorations scr...
25
26
27
  if [[ -z "$NOM_IMAGE" ]]; then
      echo "Il faut donner le nom de l'image ! Relancez la commande avec les bons arguments."
      exit
3e470988   hmalti   First commit
28
  fi
5161dfdb   hmalti   Améliorations scr...
29
  
3e470988   hmalti   First commit
30
  #Crée image
b1087939   hmalti   Ajout commandes
31
  
5161dfdb   hmalti   Améliorations scr...
32
  MANIFEST=$NOM_IMAGE.manifest
b1087939   hmalti   Ajout commandes
33
  
5161dfdb   hmalti   Améliorations scr...
34
  dd if=/dev/zero of=$REPERTOIRE/$NOM_IMAGE bs=1024k count=$SIZE
3e470988   hmalti   First commit
35
  
5721892d   hmalti   Avancées
36
  echo "nom_image:$NOM_IMAGE" >> $MANIFEST
5161dfdb   hmalti   Améliorations scr...
37
38
  echo "taille:$SIZE">> $MANIFEST
  echo "chemin:$REPERTOIRE">> $MANIFEST
3e470988   hmalti   First commit
39
40
  
  
3e470988   hmalti   First commit
41
  
5161dfdb   hmalti   Améliorations scr...
42
43
44
  if [[ ! -d "$PATH_MANIFEST/images" ]]; then
      mkdir -p $PATH_MANIFEST/images
  fi
3e470988   hmalti   First commit
45
  
5161dfdb   hmalti   Améliorations scr...
46
  mv $NOM_IMAGE.manifest $PATH_MANIFEST/images
3e470988   hmalti   First commit
47
  
5161dfdb   hmalti   Améliorations scr...
48
49
50
51
52
53
54
55
56
57
58
  
  if [[ -z "$FORMAT" ]]; then
      FORMAT=ext4
  fi
  
  mkfs.ext4 $REPERTOIRE/$NOM_IMAGE
  
  if [[ $PROXY != "" ]]; then
      echo "Export du proxy"
      export http_proxy=http://proxy.polytech-lille.fr:3128
  fi
3e470988   hmalti   First commit
59
60
61
  
  #Création de l'arborescence Debian avec debootstrap
  echo "Je vais faire le debootstrap"
5721892d   hmalti   Avancées
62
63
64
65
66
  mkdir -p /mnt/baleine/$NOM_IMAGE
  mount -t ext4 -o loop $REPERTOIRE/$NOM_IMAGE /mnt/baleine/$NOM_IMAGE 
  debootstrap --include=apache2,vim,nano  stable /mnt/baleine/$NOM_IMAGE
  umount /mnt/baleine/$NOM_IMAGE
  rm -rf /mnt/baleine/$NOM_IMAGE