diff --git a/baleine.sh b/baleine.sh index 3ac5f62..6981026 100755 --- a/baleine.sh +++ b/baleine.sh @@ -30,7 +30,7 @@ case "$1" in bash container.sh "$@" ;; "image") - bash image.sh "$@" + bash image.sh "${@:2}" ;; "bridge") bash bridge.sh "$@" diff --git a/container.sh b/container.sh index d402bc0..a2ad275 100644 --- a/container.sh +++ b/container.sh @@ -18,6 +18,9 @@ case $2 in ;; "restart") bash restart_container.sh "$@" - ;; + ;; + "exec") + bash exec_container.sh "$@" + ;; esac \ No newline at end of file diff --git a/create_container.sh b/create_container.sh index 4ef9e79..e3636de 100644 --- a/create_container.sh +++ b/create_container.sh @@ -28,6 +28,10 @@ cp $PATH_IMAGE $PATH_BALEINE/containers/$NOM_CONTAINER/$NOM_IMAGE echo "je vais mount" mount -t ext4 -o loop $PATH_BALEINE/containers/$NOM_CONTAINER/$NOM_IMAGE /mnt/baleine/$NOM_CONTAINER +#On renseigne le fichier fstab du conteneur +echo "proc /proc proc defaults 0 0" >> /mnt/$NOM_IMAGE/etc/fstab +echo "$PROGRAM" >> /mnt/$NOM_IMAGE/etc/rc.local + nohup unshare -p -f -m -n -u chroot /mnt/baleine/$NOM_CONTAINER $PROGRAM -c "mount /proc" & PID=$! echo "j'ai finis le unshare-nohup" @@ -62,6 +66,8 @@ if [[ ! -d "$PATH_MANIFEST/containers" ]]; then fi mv $NOM_CONTAINER.manifest $PATH_MANIFEST/containers/$NOM_CONTAINER.manifest + + #TODO : son interface réseau (bridge) - taille mémoire / limite mémoire #création de son interface réseau diff --git a/create_image.sh b/create_image.sh index 93b6fdf..485a3cd 100644 --- a/create_image.sh +++ b/create_image.sh @@ -1,67 +1,64 @@ #!/bin/bash -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 +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 fi +echo "La size est de $SIZE" mkdir -p $PATH_BALEINE/images -#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" - REPERTOIRE=$PATH_BALEINE/images +if [[ -z $REPERTOIRE ]]; then + REPERTOIRE=$PATH_BALEINE/images 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 +if [[ -z "$NOM_IMAGE" ]]; then + echo "Il faut donner le nom de l'image ! Relancez la commande avec les bons arguments." + exit fi -# #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" + #Crée image -FILE=$NOM_IMAGE.manifest -echo "Je vais commencer à allouer !" -dd if=/dev/zero of=$REPERTOIRE/$NOM_IMAGE bs=1024k count=$SIZE -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 +MANIFEST=$NOM_IMAGE.manifest +dd if=/dev/zero of=$REPERTOIRE/$NOM_IMAGE bs=1024k count=$SIZE -if [[ ! -d "$PATH_MANIFEST/images" ]]; then - mkdir -p $PATH_MANIFEST/images #&& mv $NOM_IMAGE.$NUMBER.manifest $REPERTOIRE/images -fi -mv $NOM_IMAGE.manifest $PATH_MANIFEST/images +touch $MANIFEST +echo "nom image:$NOM_IMAGE" >> $MANIFEST +echo "taille:$SIZE">> $MANIFEST +echo "chemin:$REPERTOIRE">> $MANIFEST -#création du système de fichiers au format "ext4" -mkfs.ext4 $REPERTOIRE/images/$NOM_IMAGE +if [[ ! -d "$PATH_MANIFEST/images" ]]; then + mkdir -p $PATH_MANIFEST/images +fi +mv $NOM_IMAGE.manifest $PATH_MANIFEST/images -echo "je vais exporter le proxy" -export http_proxy=http://proxy.polytech-lille.fr:3128 + +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 #Création de l'arborescence Debian avec debootstrap echo "Je vais faire le debootstrap" -debootstrap --include=apache2,vim,nano stable /mnt/baleine/$NOM_IMAGE - -#On renseigne le fichier fstab du conteneur -echo "proc /proc proc defaults 0 0" >> /mnt/$NOM_IMAGE/etc/fstab \ No newline at end of file +debootstrap --include=apache2,vim,nano stable /mnt/baleine/$NOM_IMAGE \ No newline at end of file diff --git a/exec_container.sh b/exec_container.sh new file mode 100644 index 0000000..b4bedb3 --- /dev/null +++ b/exec_container.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +while getopts e: o; do + case $o in + (e) $NOM_CONTAINER=$OPTARG;; + esac +done +unshare -p -f -m -n -u chroot /mnt/baleine/$NOM_CONTAINER /bin/bash \ No newline at end of file diff --git a/image.sh b/image.sh index 6458af3..9e36f18 100644 --- a/image.sh +++ b/image.sh @@ -1,10 +1,9 @@ #!/bin/bash -case $2 in - +case $1 in "create") #Si on veut creer une image (qu'on a apellé le script ./balaine.sh image create) - bash create_image.sh "$@" + bash create_image.sh "${@:2}" ;; "list") #Si on veut lister les images (qu'on a apellé le script ./balaine.sh image list) diff --git a/test.sh b/test.sh index 5fa8488..cb44550 100644 --- a/test.sh +++ b/test.sh @@ -1,4 +1,12 @@ #!/bin/bash -source baleine.sh -echo "$PATH_MANIFEST" \ No newline at end of file +echo $@ +while getopts i:proxy: o "$@"; do + case $o in + (i) IMAGE=$OPTARG;; + (proxy) PROXY=$OPTARG;; + esac +done + +echo "Le proxy est $PROXY" +echo "L'image est $IMAGE" -- libgit2 0.21.2