Commit 5721892d64e335fdfdb80eabea5ceedcc5170042
1 parent
5cf93464
Avancées
Showing
17 changed files
with
159 additions
and
115 deletions
Show diff stats
... | ... | @@ -27,18 +27,18 @@ case "$1" in |
27 | 27 | #Si on a apelé ./baleine.sh container create par exemple, on va apeller le script container.sh qui va traiter les |
28 | 28 | #opérations sur les containers, et $@ permet de lui passer tous les arguments qu'on a passé à baleine.sh |
29 | 29 | #autrement dit, ./baleine.sh container create apellera le script container.sh avec les arguments $1=container et $2=create |
30 | - bash container.sh "$@" | |
30 | + bash container.sh "${@:2}" | |
31 | 31 | ;; |
32 | 32 | "image") |
33 | 33 | bash image.sh "${@:2}" |
34 | 34 | ;; |
35 | 35 | "bridge") |
36 | - bash bridge.sh "$@" | |
36 | + bash bridge.sh "${@:2}" | |
37 | 37 | ;; |
38 | 38 | "help") |
39 | - bash help.sh "$@" | |
39 | + bash help.sh | |
40 | 40 | ;; |
41 | 41 | "test") |
42 | - bash test.sh "$@" | |
42 | + bash test.sh "${@:2}" | |
43 | 43 | ;; |
44 | 44 | esac |
45 | 45 | \ No newline at end of file | ... | ... |
bridge.sh
1 | 1 | #!/bin/bash |
2 | 2 | |
3 | -case $2 in | |
3 | +case $1 in | |
4 | 4 | |
5 | 5 | "create") |
6 | 6 | #Si on veut creer un bridge (qu'on a apellé le script ./balaine.sh bridge create) |
7 | - bash create_bridge.sh "$@" | |
7 | + bash create_bridge.sh "${@:2}" | |
8 | 8 | ;; |
9 | 9 | "list") |
10 | 10 | #Si on veut lister les bridges (qu'on a apellé le script ./balaine.sh bridge list) |
11 | - bash list_bridges.sh "$@" | |
11 | + bash list_bridges.sh "${@:2}" | |
12 | 12 | ;; |
13 | 13 | "remove") |
14 | - bash remove_bridge.sh "$@" | |
14 | + bash remove_bridge.sh "${@:2}" | |
15 | 15 | ;; |
16 | 16 | "up") |
17 | - bash up_bridge.sh "$@" | |
17 | + bash up_bridge.sh "${@:2}" | |
18 | 18 | ;; |
19 | 19 | "down") |
20 | - bash down_bridge.sh "$@" | |
20 | + bash down_bridge.sh "${@:2}" | |
21 | 21 | esac |
22 | 22 | \ No newline at end of file | ... | ... |
container.sh
1 | 1 | #!/bin/bash |
2 | 2 | |
3 | -case $2 in | |
3 | +case $1 in | |
4 | 4 | |
5 | 5 | "create") |
6 | 6 | #Si on veut creer un container (qu'on a apellé le script ./baleine.sh container create) |
7 | - bash create_container.sh "$@" | |
7 | + bash create_container.sh "${@:2}" | |
8 | 8 | ;; |
9 | 9 | "list") |
10 | 10 | #Si on veut lister les containers qui tournent (qu'on a apellé le script ./baleine.sh container list) |
11 | - bash list_container.sh "$@" | |
11 | + bash list_container.sh "${@:2}" | |
12 | 12 | ;; |
13 | 13 | "stop") |
14 | - bash stop_container.sh "$@" | |
14 | + bash stop_container.sh "${@:2}" | |
15 | 15 | ;; |
16 | 16 | "remove") |
17 | - bash remove_container.sh "$@" | |
17 | + bash remove_container.sh "${@:2}" | |
18 | 18 | ;; |
19 | 19 | "restart") |
20 | - bash restart_container.sh "$@" | |
20 | + bash restart_container.sh "${@:2}" | |
21 | 21 | ;; |
22 | 22 | "exec") |
23 | - bash exec_container.sh "$@" | |
23 | + bash exec_container.sh "${@:2}" | |
24 | 24 | ;; |
25 | 25 | |
26 | 26 | esac |
27 | 27 | \ No newline at end of file | ... | ... |
create_bridge.sh
1 | 1 | #!/bin/bash |
2 | -NOM_BRIDGE=$3; | |
3 | -ADDR_IPV4=$4; | |
4 | - | |
2 | +while getopts b:a: o; do | |
3 | + case $o in | |
4 | + (b) NOM_BRIDGE=$OPTARG;; | |
5 | + (a) ADDR_IPV4=$OPTARG;; | |
6 | + | |
7 | + esac | |
8 | +done | |
5 | 9 | |
6 | 10 | |
7 | 11 | #condition sur le nbre d'arguments |
... | ... | @@ -11,15 +15,20 @@ if [[ -z "$NOM_BRIDGE" ]]; then |
11 | 15 | fi |
12 | 16 | #création du bridge |
13 | 17 | ip link add $NOM_BRIDGE type bridge |
18 | + | |
19 | +#attribution d'une adresse ip au bridge | |
14 | 20 | ip a add dev $NOM_BRIDGE $ADDR_IPV4 |
21 | + | |
22 | +#demarrage du bridge | |
15 | 23 | ip link set $NOM_BRIDGE down |
16 | 24 | ip link set $NOM_BRIDGE up |
17 | -FILE= $NOM_BRIDGE.manifest | |
18 | -touch FILE # On crée un fichier contenant les infos du bridge | |
19 | -echo "$NOM_BRIDGE" >> FILE #nom du bridge | |
25 | + | |
26 | +MANIFEST=$NOM_BRIDGE.manifest | |
27 | +echo "nom_bridge:$NOM_BRIDGE" >> $MANIFEST #nom du bridge | |
20 | 28 | |
21 | 29 | #condition de bordure pour le dossier Bridges |
22 | 30 | if [[ ! -d "$PATH_MANIFEST/bridges" ]]; then |
23 | 31 | mkdir -p $PATH_MANIFEST/bridges #&& mv FILE $PATH_MANIFEST/bridges |
24 | 32 | fi |
25 | -mv FILE $PATH_MANIFEST/bridges | |
26 | 33 | \ No newline at end of file |
34 | + | |
35 | +mv $MANIFEST $PATH_MANIFEST/bridges | |
27 | 36 | \ No newline at end of file | ... | ... |
create_container.sh
1 | 1 | #!/bin/bash |
2 | -set -x | |
2 | + | |
3 | +set -x | |
3 | 4 | while getopts i:c:b:r:a:p: o; do |
4 | 5 | case $o in |
5 | 6 | (i) NOM_IMAGE=$OPTARG;; |
... | ... | @@ -8,43 +9,56 @@ while getopts i:c:b:r:a:p: o; do |
8 | 9 | (r) REPERTOIRE=$OPTARG;; |
9 | 10 | (a) ADDRS_IPV4=$OPTARG;; |
10 | 11 | (p) PROGRAM=$OPTARG;; |
11 | - | |
12 | 12 | esac |
13 | 13 | done |
14 | 14 | |
15 | +echo "Creation du container $NOM_CONTAINER basé sur l'image $NOM_IMAGE lancant le programme $PROGRAM connecté au(x) bridge(s) $BRIDGES avec les adresses $ADDRS_IPV4" | |
16 | +#/usr/local/apache2/bin | |
17 | + | |
15 | 18 | #Check existence image, bridge |
16 | -if [[ -z "$PATH_MANIFEST/images/$NOM_IMAGE.manifest" ]] || [ -z $NOM_IMAGE ]]; then | |
19 | +if [ -z "$PATH_MANIFEST/images/$NOM_IMAGE.manifest" ] || [ -z $NOM_IMAGE ]; then | |
17 | 20 | echo "Image non existante." |
18 | 21 | exit |
19 | 22 | fi |
20 | 23 | |
21 | -if [[ ! -z $NOM_BRIDGE ]] [[ -z "$PATH_MANIFEST/bridges/$NOM_BRIDGE.manifest" ]]; then | |
24 | +if [ ! -z $NOM_BRIDGE ] || [ -z "$PATH_MANIFEST/bridges/$NOM_BRIDGE.manifest" ]; then | |
22 | 25 | echo "Bridge non existant." |
23 | 26 | exit |
24 | 27 | fi |
25 | 28 | |
26 | 29 | #On veut récupérer le chemin de l'image |
27 | -PATH_IMAGE= ${grep chemin $PATH_MANIFEST/images/$NOM_IMAGE.manifest | cut -d':' -f2} | |
30 | +PATH_IMAGE="$(grep chemin $PATH_MANIFEST/images/$NOM_IMAGE.manifest | cut -d':' -f2)" | |
28 | 31 | |
32 | +echo "PATH_IMAGE: $PATH_IMAGE" | |
29 | 33 | #on fait une copie dans /var/baleine/images pour mount depuis le conteneur |
30 | 34 | if [[ ! -d "$PATH_BALEINE/containers/$NOM_CONTAINER" ]]; then |
31 | 35 | mkdir -p $PATH_BALEINE/containers/$NOM_CONTAINER |
32 | 36 | fi |
33 | 37 | |
34 | -cp $PATH_IMAGE $PATH_BALEINE/containers/$NOM_CONTAINER/$NOM_IMAGE | |
38 | + | |
39 | +#Copie de l'image physique dans le container | |
40 | +cp -r $PATH_IMAGE/$NOM_IMAGE $PATH_BALEINE/containers/$NOM_CONTAINER/$NOM_IMAGE | |
35 | 41 | |
36 | 42 | |
43 | +#création du du dossier de montage de l'image du container | |
44 | + | |
45 | +if [[ ! -d "/mnt/baleine/$NOM_CONTAINER" ]]; then | |
46 | + mkdir -p /mnt/baleine/$NOM_CONTAINER | |
47 | +fi | |
37 | 48 | |
38 | 49 | #on monte le système de fichiers |
39 | 50 | echo "Montage de l'image" |
40 | 51 | mount -t ext4 -o loop $PATH_BALEINE/containers/$NOM_CONTAINER/$NOM_IMAGE /mnt/baleine/$NOM_CONTAINER |
41 | 52 | |
42 | 53 | #On renseigne le fichier fstab du conteneur |
43 | -echo "proc /proc proc defaults 0 0" >> /mnt/$NOM_IMAGE/etc/fstab | |
44 | -echo "$PROGRAM" >> /mnt/$NOM_IMAGE/etc/rc.local | |
54 | +echo "proc /proc proc defaults 0 0" >> /mnt/baleine/$NOM_CONTAINER/etc/fstab | |
55 | +echo "$PROGRAM" >> /mnt/baleine/$NOM_CONTAINER/etc/rc.local | |
45 | 56 | |
46 | 57 | #On fait le unshare sur l'image passée en paramètre, |
47 | -nohup unshare -p -f -m -n -u chroot /mnt/baleine/$NOM_CONTAINER $PROGRAM -c "mount /proc" & | |
58 | +#nohup unshare -p -f -m -n -u chroot /mnt/baleine/$NOM_CONTAINER "/bin/bash" -c "mount /proc" & | |
59 | + | |
60 | + | |
61 | + | |
48 | 62 | PID=$! |
49 | 63 | echo "j'ai finis le unshare-nohup" |
50 | 64 | |
... | ... | @@ -57,7 +71,7 @@ date=${date} |
57 | 71 | |
58 | 72 | echo "nom_container:$NOM_CONTAINER" >> $FILE #nom de son image |
59 | 73 | echo "nom_image:$NOM_IMAGE" >> $FILE #nom de son image |
60 | -echo "pid:$PID" >> $FILE #Son PID | |
74 | +echo "pid:$PID" >> $FILE #Son PID | |
61 | 75 | echo "nom_bridge:$NOM_BRIDGE" >> $FILE #SON BRIDGE |
62 | 76 | echo "starting_time: $date" >> $FILE #starting time |
63 | 77 | |
... | ... | @@ -74,21 +88,24 @@ mv $NOM_CONTAINER.manifest $PATH_MANIFEST/containers/$NOM_CONTAINER.manifest |
74 | 88 | #AWK pour récupèrer le nombre d'addresses IPV4 données en arguments |
75 | 89 | #(https://unix.stackexchange.com/questions/144217/counting-comma-separated-characters-in-a-row) |
76 | 90 | |
77 | -NOMBRE_INTERFACES=echo $ADDRS_IPV4 | awk -F '[,]' '{print NF}' | |
91 | +NOMBRE_INTERFACES="$(echo $ADDRS_IPV4 | awk -F '[,]' '{print NF}')" | |
78 | 92 | |
79 | -NOMBRE_BRIDGES=echo $BRIDGES | awk -F '[,]' '{print NF}' | |
93 | +NOMBRE_BRIDGES="$(echo $BRIDGES | awk -F '[,]' '{print NF}')" | |
80 | 94 | |
81 | -if [ NOMBRE_INTERFACES -ne NOMBRE_BRIDGES ]; do | |
95 | +if [ $NOMBRE_INTERFACES -ne $NOMBRE_BRIDGES ]; then | |
82 | 96 | echo "Erreur: Il n'y a pas autant de bridges que d'interfaces réseaux" |
83 | 97 | exit 1 |
84 | -done | |
98 | +fi | |
85 | 99 | |
86 | 100 | for i in $(seq 1 $NOMBRE_INTERFACES); do |
87 | - ip link add $NOM_CONTAINER_$i type veth peer name eth$i | |
101 | + echo "Nom de l'interface : $NOM_CONTAINER$i" | |
102 | + ip link add $NOM_CONTAINER$i type veth peer name eth$i | |
88 | 103 | done |
89 | 104 | |
90 | 105 | echo "J'ai fini de créer les interfaces chef" |
91 | -NOMBRE_BRIDGES=echo $BRIDGES | awk -F '[,]' '{print NF}' | |
106 | + | |
107 | +#Compte le nombre de bridges présents | |
108 | +NOMBRE_BRIDGES=$(echo $BRIDGES | awk -F '[,]' '{print NF}') | |
92 | 109 | |
93 | 110 | IFS="," |
94 | 111 | |
... | ... | @@ -103,13 +120,21 @@ for a in $ADDRS_IPV4; do |
103 | 120 | ARRAY_IPV4+=(a) |
104 | 121 | done |
105 | 122 | |
106 | -for (( i=0 ; i < ${#ARRAY_BRIDGES[*]} ; i++ )); do | |
107 | - ip link set $NOM_CONTAINER_$i master ${ARRAY_BRIDGES[i]} | |
108 | -done | |
123 | +for (( i=0 ; i < ${#ARRAY_IPV4[*]} ; i++ )); do | |
124 | + #Creation de la veth | |
125 | + #ip link add dev $NOM_CONTAINER$i type veth peer name eth$i@$NOM_CONTAINER$i | |
126 | + ip link add dev vif1 type veth peer name eth0@vif1 | |
127 | + #Ajout d'une des extrémités de la veth dans le namespace du container | |
128 | + #ip link set eth$i@$NOM_CONTAINER$i netns proc/$PID/ns/net name eth$i | |
129 | + ip link set eth0@vif1 netns proc/$PID/ns/net name eth0 | |
130 | + #Attribution de l'adresse ip à l'interface du container | |
131 | + #ip netns exec proc/$PID/ns/net ip addr add ${ARRAY_IPV4[i]} dev eth$i | |
132 | + ip netns exec proc/$PID/ns/net ip addr add ${ARRAY_IPV4[i]} dev eth0 | |
133 | + ip netns exec proc/$PID/ns/net ip link set dev eth0 down | |
134 | + ip netns exec proc/$PID/ns/net ip link set dev eth0 up | |
109 | 135 | |
110 | -#création de son interface réseau | |
136 | +done | |
111 | 137 | |
112 | -ip link set $NOM_CONTAINER master $NOM_BRIDGE | |
113 | -ip link set $NOM_CONTAINER up | |
114 | -ip link set eth0@$NOM_CONTAINER netns /proc/$PID/ns/net name eth0 | |
115 | -ip netns exec /proc/$PID/ns/net ip addr add $ADDR_IPV4 dev eth0 | |
138 | +for (( i=0 ; i < ${#ARRAY_BRIDGES[*]} ; i++ )); do | |
139 | + ip link set $NOM_CONTAINER$i master ${ARRAY_BRIDGES[i]} | |
140 | +done | |
116 | 141 | \ No newline at end of file | ... | ... |
create_image.sh
1 | -#!/bin/bash | |
1 | + #!/bin/bash | |
2 | 2 | |
3 | 3 | |
4 | 4 | while getopts i:s:r: o; do |
... | ... | @@ -15,7 +15,7 @@ if [ "$SIZE" == "" ] || [ "$SIZE" -lt 0 ] || [ "$SIZE" -gt 10240 ]; then |
15 | 15 | SIZE=10240 |
16 | 16 | fi |
17 | 17 | |
18 | -echo "La size est de $SIZE" | |
18 | +echo "Le size est de $SIZE" | |
19 | 19 | mkdir -p $PATH_BALEINE/images |
20 | 20 | |
21 | 21 | if [[ -z $REPERTOIRE ]]; then |
... | ... | @@ -33,9 +33,7 @@ MANIFEST=$NOM_IMAGE.manifest |
33 | 33 | |
34 | 34 | dd if=/dev/zero of=$REPERTOIRE/$NOM_IMAGE bs=1024k count=$SIZE |
35 | 35 | |
36 | -touch $MANIFEST | |
37 | - | |
38 | -echo "nom image:$NOM_IMAGE" >> $MANIFEST | |
36 | +echo "nom_image:$NOM_IMAGE" >> $MANIFEST | |
39 | 37 | echo "taille:$SIZE">> $MANIFEST |
40 | 38 | echo "chemin:$REPERTOIRE">> $MANIFEST |
41 | 39 | |
... | ... | @@ -61,4 +59,8 @@ fi |
61 | 59 | |
62 | 60 | #Création de l'arborescence Debian avec debootstrap |
63 | 61 | echo "Je vais faire le debootstrap" |
64 | -debootstrap --include=apache2,vim,nano stable /mnt/baleine/$NOM_IMAGE | |
65 | 62 | \ No newline at end of file |
63 | +mkdir -p /mnt/baleine/$NOM_IMAGE | |
64 | +mount -t ext4 -o loop $REPERTOIRE/$NOM_IMAGE /mnt/baleine/$NOM_IMAGE | |
65 | +debootstrap --include=apache2,vim,nano stable /mnt/baleine/$NOM_IMAGE | |
66 | +umount /mnt/baleine/$NOM_IMAGE | |
67 | +rm -rf /mnt/baleine/$NOM_IMAGE | |
66 | 68 | \ No newline at end of file | ... | ... |
down_bridge.sh
1 | 1 | #!/bin/bash |
2 | -NOM_BRIDGE=$3; | |
2 | +while getopts b: o; do | |
3 | + case $o in | |
4 | + (b) NOM_BRIDGE=$OPTARG;; | |
5 | + esac | |
6 | +done | |
3 | 7 | #vérification que l'utilisateur donne bien un nom à l'image |
4 | 8 | if [[ -z "$NOM_BRIDGE" ]]; then |
5 | 9 | echo "Il faut donner le nom du bridge Relancez la commande avec les bons arguments." | ... | ... |
image.sh
... | ... | @@ -7,14 +7,14 @@ case $1 in |
7 | 7 | ;; |
8 | 8 | "list") |
9 | 9 | #Si on veut lister les images (qu'on a apellé le script ./balaine.sh image list) |
10 | - bash list_images.sh "$@" | |
10 | + bash list_images.sh "${@:2}" | |
11 | 11 | ;; |
12 | 12 | "import") |
13 | - bash import_container.sh "$@" | |
13 | + bash import_container.sh "${@:2}" | |
14 | 14 | ;; |
15 | 15 | "export") |
16 | - bash export_container.sh "$@" | |
16 | + bash export_container.sh "${@:2}" | |
17 | 17 | ;; |
18 | 18 | "remove") |
19 | - bash remove_image.sh "$@" | |
19 | + bash remove_image.sh "${@:2}" | |
20 | 20 | esac |
21 | 21 | \ No newline at end of file | ... | ... |
list_bridges.sh
1 | 1 | #!/bin/bash |
2 | -cd $PATH_MANIFEST/bridges | |
3 | - | |
4 | -for eachfile in ./*.manifest | |
2 | +for eachfile in $PATH_MANIFEST/bridges/*.manifest | |
5 | 3 | do |
6 | - echo $eachfile | |
7 | - val=$(cat "$eachfile") | |
8 | - echo $val | |
9 | -done | |
10 | 4 | \ No newline at end of file |
5 | + NOM_BRIDGE=$(grep nom_bridge $eachfile | cut -d ':' -f2) | |
6 | + echo "----------------------" | |
7 | + brctl show $NOM_BRIDGE | |
8 | + echo "----------------------" | |
9 | +done | ... | ... |
list_images.sh
1 | 1 | #!/bin/bash |
2 | 2 | |
3 | -cd $PATH_MANIFEST/images | |
4 | - | |
5 | -for eachfile in ./*.manifest | |
3 | +for eachfile in $PATH_MANIFEST/images/*.manifest | |
6 | 4 | do |
7 | - echo $eachfile | |
8 | - val=$(cat "$eachfile") | |
9 | - echo $val | |
5 | + NOM_IMAGE=$(grep nom_image $eachfile | cut -d ':' -f2) | |
6 | + TAILLE=$(grep taille $eachfile | cut -d ':' -f2) | |
7 | + CHEMIN=$(grep chemin $eachfile | cut -d ':' -f2) | |
8 | + echo "----------------------" | |
9 | + echo "Nom image: $NOM_IMAGE" | |
10 | + echo "Taille: $TAILLE" | |
11 | + echo "Chemin: $CHEMIN" | |
12 | + echo "----------------------" | |
10 | 13 | done | ... | ... |
remove_bridge.sh
1 | 1 | #!/bin/bash |
2 | -NOM_BRIDGE_TO_REMOVE=$3; | |
3 | - | |
2 | +NAME_BRIDGE_TO_REMOVE=$1; | |
4 | 3 | |
5 | 4 | #vérification que l'utilisateur donne bien un nom à l'image |
6 | -if [[ -z "$NOM_BRIDGE_TO_REMOVE" ]]; then | |
5 | +if [[ -z "$NAME_BRIDGE_TO_REMOVE" ]]; then | |
7 | 6 | echo "Il faut donner le nom du bridge à supprimer ! Relancez la commande avec les bons arguments." |
8 | 7 | exit |
9 | 8 | fi |
10 | -chmod -R 755 $PATH_MANIFEST | |
11 | -rm $PATH_MANIFEST/bridges/$NOM_BRIDGE_TO_REMOVE.* | |
12 | -ip link delete $NOM_BRIDGE_TO_REMOVE type bridge | |
13 | -#delbr | |
9 | + | |
10 | +rm $PATH_MANIFEST/bridges/$NAME_BRIDGE_TO_REMOVE.manifest | |
11 | +ip link set $NAME_BRIDGE_TO_REMOVE down | |
12 | +brctl delbr $NAME_BRIDGE_TO_REMOVE | |
14 | 13 | \ No newline at end of file | ... | ... |
remove_container.sh
1 | 1 | #!/bin/bash |
2 | -NOM_CONTAINER_TO_REMOVE=$3; | |
2 | +NAME_CONTAINER_TO_REMOVE=$1; | |
3 | 3 | |
4 | 4 | #vérification que l'utilisateur donne bien un nom à l'CONTAINER |
5 | -if [[ -z "$NOM_CONTAINER_TO_REMOVE" ]]; then | |
6 | - echo "Il faut donner le nom du conteneur! Relancez la commande avec les bons arguments." | |
5 | +if [[ -z "$NAME_CONTAINER_TO_REMOVE" ]]; then | |
6 | + echo "Il faut donner le NAME du conteneur! Relancez la commande avec les bons arguments." | |
7 | 7 | exit |
8 | 8 | fi |
9 | -chmod -R 755 $PATH_MANIFEST | |
10 | -rm $PATH_MANIFEST/containers/$NOM_CONTAINER_TO_REMOVE.manifest | |
11 | -rm $PATH_BALEINE/containers/$NOM_CONTAINER_TO_REMOVE | |
9 | +rm -rf $PATH_MANIFEST/containers/$NAME_CONTAINER_TO_REMOVE.manifest | |
10 | +rm -rf $PATH_BALEINE/containers/$NAME_CONTAINER_TO_REMOVE | |
12 | 11 | |
13 | -#il doit remove aussi l'image, les manifessts les bridges supprime la copie? | |
12 | +#umount /mnt/container | |
13 | +umount /mnt/baleine/$NAME_CONTAINER_TO_REMOVE | |
14 | +#supprime mnt/container | |
15 | +rm -rf /mnt/baleine/$NAME_CONTAINER_TO_REMOVE | |
16 | +#supprime l'image associé au container (manifest du container) | |
17 | +rm -rf /var/lib/baleine/containers/$NAME_CONTAINER_TO_REMOVE | ... | ... |
remove_image.sh
1 | 1 | #!/bin/bash |
2 | -NOM_IMAGE_TO_REMOVE=$3; | |
2 | +NAME_IMAGE_TO_REMOVE=$1; | |
3 | 3 | |
4 | 4 | #vérification que l'utilisateur donne bien un nom à l'image |
5 | -if [[ -z "$NOM_IMAGE_TO_REMOVE" ]]; then | |
5 | +if [[ -z "$NAME_IMAGE_TO_REMOVE" ]]; then | |
6 | 6 | echo "Il faut donner le nom de l'image ! Relancez la commande avec les bons arguments." |
7 | 7 | exit |
8 | 8 | fi |
9 | -chmod -R 755 $PATH_MANIFEST | |
10 | -rm $PATH_MANIFEST/images/$NOM_IMAGE_TO_REMOVE.manifest | |
11 | -rm $PATH_BALEINE/images/$NOM_IMAGE_TO_REMOVE | |
12 | 9 | \ No newline at end of file |
10 | +rm $PATH_MANIFEST/images/$NAME_IMAGE_TO_REMOVE.manifest | |
11 | +rm $PATH_BALEINE/images/$NAME_IMAGE_TO_REMOVE | |
12 | +#TODO : umount | |
13 | 13 | \ No newline at end of file | ... | ... |
restart_container.sh
1 | 1 | #!/bin/bash |
2 | -NOM_CONTAINER=$3; | |
3 | -NOM_IMAGE=$4; | |
4 | - | |
2 | +while getopts c:i: o; do | |
3 | + case $o in | |
4 | + (c) NOM_CONTAINER=$OPTARG;; | |
5 | + (i) NOM_IMAGE=$OPTARG;; | |
6 | + esac | |
7 | +done | |
5 | 8 | mount -t ext4 -o loop $PATH_BALEINE/containers/$NOM_CONTAINER/$NOM_IMAGE /mnt/baleine/$NOM_CONTAINER |
6 | 9 | |
7 | 10 | nohup unshare -p -f -m -n -u chroot /mnt/baleine/$NOM_CONTAINER $PROGRAM -c "mount /proc" & | ... | ... |
stop_container.sh
test.sh
1 | -#!/bin/bash | |
1 | +#bash baleine.sh bridge create mybridge 192.168.42.1 | |
2 | +#bash baleine.sh container create -i TEST -c mycontainer -b mybridge -a 192.168.42.2 -p /usr/sbin/apache2 | |
2 | 3 | |
3 | -BRIDGES="pont,petitpont" | |
4 | -ADDRS_IPV4="lala,lulu" | |
4 | +A="HELLO" | |
5 | +B=" WORLD" | |
5 | 6 | |
6 | -ARRAY_BRIDGES=() | |
7 | -ARRAY_IPV4=() | |
7 | +C="$A$B" | |
8 | 8 | |
9 | -IFS=',' | |
10 | -for b in $BRIDGES; do | |
11 | - ARRAY_BRIDGES+=($b) | |
12 | -done | |
13 | - | |
14 | -for a in $ADDRS_IPV4; do | |
15 | - ARRAY_IPV4+=($a) | |
16 | -done | |
17 | - | |
18 | - | |
19 | -for ((i = 0, j = 0 ; i < ${#ARRAY_BRIDGES[*]} && j < ${#ARRAY_BRIDGES[*]} ; i++, j++ )); do | |
20 | - echo "i= ${ARRAY_BRIDGES[i]}" | |
21 | - echo "j= ${ARRAY_IPV4[j]}" | |
22 | -done | |
23 | 9 | \ No newline at end of file |
10 | +echo $C | |
24 | 11 | \ No newline at end of file | ... | ... |
up_bridge.sh
1 | 1 | #!/bin/bash |
2 | -NOM_BRIDGE=$3; | |
2 | + | |
3 | +while getopts b: o; do | |
4 | + case $o in | |
5 | + (b) NOM_BRIDGE=$OPTARG;; | |
6 | + esac | |
7 | +done | |
3 | 8 | #vérification que l'utilisateur donne bien un nom à l'image |
4 | 9 | if [[ -z "$NOM_BRIDGE" ]]; then |
5 | 10 | echo "Il faut donner le nom du bridge Relancez la commande avec les bons arguments." | ... | ... |