summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmake-boot-image.sh6
-rwxr-xr-xnfs/nfs-autorun.sh4
-rw-r--r--nfs/scripts/image_capture.sh9
-rw-r--r--nfs/scripts/image_capture_I4920.sh15
-rw-r--r--nfs/scripts/image_capture_I5456.sh19
-rw-r--r--nfs/scripts/image_capture_I5734.sh22
-rw-r--r--nfs/scripts/image_capture_I6510.sh28
-rw-r--r--nfs/scripts/image_deploy.sh34
-rw-r--r--nfs/scripts/image_deploy_I4920.sh19
-rw-r--r--nfs/scripts/image_deploy_I5456.sh21
-rw-r--r--nfs/scripts/image_deploy_I5734.sh39
-rw-r--r--nfs/scripts/image_deploy_dual-I5734-I6510.sh72
-rw-r--r--nfs/scripts/masterlist-autogenerated.conf10
13 files changed, 199 insertions, 99 deletions
diff --git a/make-boot-image.sh b/make-boot-image.sh
index 840cce7..943f10a 100755
--- a/make-boot-image.sh
+++ b/make-boot-image.sh
@@ -1,6 +1,6 @@
#!/bin/bash -xe
PS4='+ ($LINENO) ' # To ease debugging
-VERSION="1.2-emac-rc1"
+VERSION="1.2-emac-rc2"
# Config #
##########
@@ -148,7 +148,7 @@ then check_free_space $ROOT_MIN_AVAIL_MIO /
# Optionnally qemu to run the result for santity checking
[ "x$DEVEL_MODE" = "xy" ] && $ROOTCMD apt-get install qemu-system-x86
# Dependencies to put into the initrd
- # util-linux : fdisk, sfdisk, lsblk, setterm
+ # util-linux : blkdiscard, fdisk, sfdisk, lsblk, setterm
# net-tools : mii-tool
# ncurses-bin : tput
$ROOTCMD apt-get install dmidecode pciutils usbutils lshw sysstat iftop strace rsync \
@@ -378,7 +378,7 @@ then (
# Network tools
mkchroot "$WORKDIR/initrd" mii-tool ethtool
# Disk tools
- mkchroot "$WORKDIR/initrd" fdisk gdisk sfdisk sgdisk
+ mkchroot "$WORKDIR/initrd" blkdiscard fdisk gdisk sfdisk sgdisk
# Cloning tools
mkchroot "$WORKDIR/initrd" /usr/sbin/partclone* efibootmgr pigz scp rsync
# Some dyn-loaded libraries (ldd will not display them)
diff --git a/nfs/nfs-autorun.sh b/nfs/nfs-autorun.sh
index 04cdf0e..130e58a 100755
--- a/nfs/nfs-autorun.sh
+++ b/nfs/nfs-autorun.sh
@@ -18,11 +18,11 @@ firstdiskp=$(firstdiskp "$firstdisk")
# Run the main action script
if nfswrite_test
then # Start deploy script after letting a chance to cancel it
- message deploy ; pause10s; sfx_starting
+ message deploy; message ${firstdisk#/dev/}; pause10s; sfx_starting
source $scriptdir/image_deploy.sh
else scriptavailability_test image_capture_${hostname}.sh || exit 3
# Start capture script if all it needs is available
- message capture ; pause10s; sfx_starting
+ message capture ; message ${firstdisk#/dev/}; pause10s; sfx_starting
source $scriptdir/image_capture.sh
fi
diff --git a/nfs/scripts/image_capture.sh b/nfs/scripts/image_capture.sh
index 7c23c30..ae72320 100644
--- a/nfs/scripts/image_capture.sh
+++ b/nfs/scripts/image_capture.sh
@@ -2,9 +2,9 @@
# Should only started from autorun.sh, it defines some helper functions and variables)
# Prepare capture
-year=$(date +%Y)
-monthday=$(date +%m-%d)
-outdir="$imagedir/$year/$hostname/$monthday"
+last=$(date +%Y%m%d)
+lastfile="$imagedir/$hostname/last"
+outdir="$imagedir/$hostname/$last"
if [ -d "$outdir" ]
then rm -r "$outdir"
@@ -20,7 +20,10 @@ env
setterm -bold off
echo_color green black "$scriptdir/image_capture_${hostname}.sh script will run on tty1 now"
pause10s
+
+# Do the work then mark image in "last" after completion
source $scriptdir/image_capture_${hostname}.sh
+echo $last > $lastfile
date >>logs/date.log
diff --git a/nfs/scripts/image_capture_I4920.sh b/nfs/scripts/image_capture_I4920.sh
deleted file mode 100644
index 8f70b26..0000000
--- a/nfs/scripts/image_capture_I4920.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/busybox sh
-# Should only started from image_capture.sh, it defines some helper functions and variables)
-# echo_color() <text-color> <background-color> [prefix text] <message>
-# $outdir is the also the current working dir, garanted to be empty and writable
-# Many cloning/partitioning tools are available for use, see make-boot-image.sh
-
-echo_color white blue ">>> " "Capturing /dev/sda boot sectors"
-dd if=/dev/sda count=2048 2>logs/sda-dd.log | pigz --fast > sda-dd.gz 2>logs/sda-pigz.log
-
-echo_color white blue ">>> " "Capturing /dev/sda1 NTFS BOOT"
-partclone.ntfs --clone -s /dev/sda1 -L logs/sda1-partclone.log --no_check | pigz --fast >sda1-partclone.gz 2>logs/sda1-pigz.log
-
-echo_color white blue ">>> " "Capturing /dev/sda2 NTFS WINDOWS"
-partclone.ntfs --clone -s /dev/sda2 -L logs/sda2-partclone.log --no_check | pigz --fast >sda2-partclone.gz 2>logs/sda2-pigz.log
-
diff --git a/nfs/scripts/image_capture_I5456.sh b/nfs/scripts/image_capture_I5456.sh
deleted file mode 100644
index 9895edd..0000000
--- a/nfs/scripts/image_capture_I5456.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/busybox sh
-# Should only started from image_capture.sh, it defines some helper functions and variables)
-# echo_color() <text-color> <background-color> [prefix text] <message>
-# $outdir is the also the current working dir, garanted to be empty and writable
-# Many cloning/partitioning tools are available for use, see make-boot-image.sh
-
-echo_color white blue ">>> Capturing /dev/sda boot sectors"
-dd if=/dev/sda count=2048 2>logs/sda-dd.log | pigz --fast > sda-dd.gz 2>logs/sda-pigz.log
-
-echo_color white blue ">>> Capturing /dev/sda1 NTFS BOOT"
-partclone.ntfs --clone -s /dev/sda1 -L logs/sda1-partclone.log --no_check | pigz --fast >sda1-partclone.gz 2>logs/sda1-pigz.log
-
-echo_color white blue ">>> Capturing /dev/sda2 NTFS WINDOWS"
-partclone.ntfs --clone -s /dev/sda2 -L logs/sda2-partclone.log --no_check | pigz --fast >sda2-partclone.gz 2>logs/sda2-pigz.log
-
-echo_color white blue ">>> Capturing /dev/sda3 EXT4 LINUX"
-partclone.ext4 --clone -s /dev/sda3 -L logs/sda3-partclone.log --no_check | pigz --fast >sda3-partclone.gz 2>logs/sda3-pigz.log
-
-
diff --git a/nfs/scripts/image_capture_I5734.sh b/nfs/scripts/image_capture_I5734.sh
new file mode 100644
index 0000000..02411f1
--- /dev/null
+++ b/nfs/scripts/image_capture_I5734.sh
@@ -0,0 +1,22 @@
+#!/bin/busybox sh
+# Should only started from image_capture.sh, it defines some helper functions and variables)
+# echo_color() <text-color> <background-color> <message>
+# $outdir is the also the current working dir, garanted to be empty and writable
+# Many cloning/partitioning tools are available for use, see make-boot-image.sh
+
+echo_color white blue ">>> Capturing ${firstdisk} boot sectors"
+dd if=${firstdisk} count=2048 2>logs/sda-dd.log | pigz --fast > sda-dd.gz 2>logs/sda-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}1 NTFS WinRecovery"
+partclone.ntfs --clone -s ${firstdiskp}1 -L logs/sda1-partclone.log --no_check | pigz --fast >sda1-partclone.gz 2>logs/sda1-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}2 FAT32 EFI"
+partclone.vfat --clone -s ${firstdiskp}2 -L logs/sda2-partclone.log --no_check | pigz --fast >sda2-partclone.gz 2>logs/sda2-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}3 RAW M$ Reserved"
+dd if=${firstdiskp}3 2>logs/sda3-dd.log | pigz --fast >sda3-dd.gz 2>logs/sda3-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}4 NTFS Win10"
+partclone.ntfs --clone -s ${firstdiskp}4 -L logs/sda4-partclone.log --no_check | pigz --fast >sda4-partclone.gz 2>logs/sda4-pigz.log
+
+echo_color white blue ">>> End of capture"
diff --git a/nfs/scripts/image_capture_I6510.sh b/nfs/scripts/image_capture_I6510.sh
new file mode 100644
index 0000000..7a0fd4a
--- /dev/null
+++ b/nfs/scripts/image_capture_I6510.sh
@@ -0,0 +1,28 @@
+#!/bin/busybox sh
+# Should only started from image_capture.sh, it defines some helper functions and variables)
+# echo_color() <text-color> <background-color> <message>
+# $outdir is the also the current working dir, garanted to be empty and writable
+# Many cloning/partitioning tools are available for use, see make-boot-image.sh
+
+echo_color white blue ">>> Capturing ${firstdisk} boot sectors"
+dd if=${firstdisk} count=2048 2>logs/sda-dd.log | pigz --fast > sda-dd.gz 2>logs/sda-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}1 NTFS WinRecovery"
+partclone.ntfs --clone -s ${firstdiskp}1 -L logs/sda1-partclone.log --no_check | pigz --fast >sda1-partclone.gz 2>logs/sda1-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}2 FAT32 EFI"
+partclone.vfat --clone -s ${firstdiskp}2 -L logs/sda2-partclone.log --no_check | pigz --fast >sda2-partclone.gz 2>logs/sda2-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}3 RAW M$ Reserved"
+dd if=${firstdiskp}3 2>logs/sda3-dd.log | pigz --fast >sda3-dd.gz 2>logs/sda3-pigz.log
+
+#echo_color white blue ">>> Capturing ${firstdiskp}4 NTFS Win10"
+#partclone.ntfs --clone -s ${firstdiskp}4 -L logs/sda4-partclone.log --no_check | pigz --fast >sda4-partclone.gz 2>logs/sda4-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}5 EXT4 LINUX"
+partclone.ext4 --clone -s ${firstdiskp}5 -L logs/sda5-partclone.log --no_check | pigz --fast >sda5-partclone.gz 2>logs/sda5-pigz.log
+
+echo_color white blue ">>> Capturing ${firstdiskp}6 Swap"
+dd if=${firstdiskp}6 2>logs/sda6-dd.log | pigz --fast >sda6-dd.gz 2>logs/sda6-pigz.log
+
+echo_color white blue ">>> End of capture"
diff --git a/nfs/scripts/image_deploy.sh b/nfs/scripts/image_deploy.sh
index 69c5cf6..6041b30 100644
--- a/nfs/scripts/image_deploy.sh
+++ b/nfs/scripts/image_deploy.sh
@@ -1,31 +1,22 @@
#!/bin/busybox sh
# Should only started from autorun.sh (define some helper functions and variables)
-# Prepare deploy
-year=$(date +%Y)
-monthday=$(date +%m-%d)
-
-# define what master image should be used for the current client machine
-#TODO : have a better place for that (CMDB...)
-case "$hostname" in
- I5480) mastername=I5456 ;;
- I5454) mastername=I5456 ;;
- *) echo_color white red ">>> " "No master for $hostname (see image_deploy.sh)" ; exit 1 ;;
-esac
+# Load config to resolve $hostname to $mastername
+source $scriptdir/masterlist-autogenerated.conf
# Check and print if the deploy script is defined for the current master machine
scriptavailability_test image_deploy_${mastername}.sh || exit $?
# Determine which image take
-#TODO : have a better place for that (CMDB...)
-ls -ld "$imagedir/$year/$mastername/"
-
-indir=$(find "$imagedir/$year/$mastername/" -maxdepth 1 -type d -regex '.*/\d\d-\d\d' | sort -rn | head -n1)
+last=$(cat "$imagedir/$mastername/last")
# Put a bad value to help the user to see where the image should be available
-indir=${indir:-$imagedir/$year/$mastername/XX-XX}
+last=${last:-XXXXXXXX}
+indir="$imagedir/$mastername/$last/"
# Check and print if the select image is available
-diravailability_test $indir || exit $?
+if [ "x$last" != "xdummy" ]
+then diravailability_test $indir || exit $?
+fi
# Print all variables and start the deploy using the customized script (image_deploy_<hostname>.sh)
setterm -bold on
@@ -34,5 +25,14 @@ setterm -bold off
echo_color green black "$scriptdir/image_deploy_${mastername}.sh script will run on tty1 now"
pause10s
+# Plan a success action after script execution
+echo reboot > /run/eficast_end
+
+# Run the final deploy script
source $scriptdir/image_deploy_${mastername}.sh
+res=$?
+
+# Pause at the end to have chance to read error messages
+pause10s
+exit $res
diff --git a/nfs/scripts/image_deploy_I4920.sh b/nfs/scripts/image_deploy_I4920.sh
deleted file mode 100644
index 1cd3220..0000000
--- a/nfs/scripts/image_deploy_I4920.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/busybox sh
-# Should only started from image_capture.sh, it defines some helper functions and variables)
-# echo_color() <text-color> <background-color> [prefix text] <message>
-# $outdir is the also the current working dir, garanted to be empty and writable
-# Many cloning/partitioning tools are available for use, see make-boot-image.sh
-
-echo_color white blue ">>> " "Restoring /dev/sda boot sectors"
-pigz -dc "$indir/sda-dd.gz" | dd of=/dev/sda count=2048
-
-echo_color white blue ">>> " "Detecting new partitions"
-echo -e "w\nq\n" | fdisk /dev/sda
-
-echo_color white blue ">>> " "Restoring /dev/sda1 NTFS BOOT"
-pigz -dc "$indir/sda1-partclone.gz" | partclone.restore -o /dev/sda1
-
-echo_color white blue ">>> " "Restoring /dev/sda2 NTFS WINDOWS"
-pigz -dc "$indir/sda2-partclone.gz" | partclone.restore -o /dev/sda2
-
-
diff --git a/nfs/scripts/image_deploy_I5456.sh b/nfs/scripts/image_deploy_I5456.sh
deleted file mode 100644
index d0c8916..0000000
--- a/nfs/scripts/image_deploy_I5456.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/busybox sh
-# Should only started from image_capture.sh, it defines some helper functions and variables)
-# echo_color() <text-color> <background-color> [prefix text] <message>
-# $outdir is the also the current working dir, garanted to be empty and writable
-# Many cloning/partitioning tools are available for use, see make-boot-image.sh
-
-echo_color white blue ">>> Restoring /dev/sda boot sectors"
-pigz -dc "$indir/sda-dd.gz" | dd of=/dev/sda count=2048
-
-echo_color white blue ">>> Detecting new partitions"
-echo -e "w\nq\n" | fdisk /dev/sda
-
-echo_color white blue ">>> Restoring /dev/sda1 NTFS BOOT"
-pigz -dc "$indir/sda1-partclone.gz" | partclone.restore -o /dev/sda1
-
-echo_color white blue ">>> Restoring /dev/sda2 NTFS WINDOWS"
-pigz -dc "$indir/sda2-partclone.gz" | partclone.restore -o /dev/sda2
-
-echo_color white blue ">>> Restoring /dev/sda3 EXT4 LINUX"
-pigz -dc "$indir/sda3-partclone.gz" | partclone.restore -o /dev/sda3
-
diff --git a/nfs/scripts/image_deploy_I5734.sh b/nfs/scripts/image_deploy_I5734.sh
new file mode 100644
index 0000000..74ba9ca
--- /dev/null
+++ b/nfs/scripts/image_deploy_I5734.sh
@@ -0,0 +1,39 @@
+#!/bin/busybox sh
+# Should only started from image_capture.sh, it defines some helper functions and variables)
+# echo_color() <text-color> <background-color> <message>
+# $outdir is the also the current working dir, garanted to be empty and writable
+# Many cloning/partitioning tools are available for use, see make-boot-image.sh
+
+last=$(cat "$imagedir/I5734/last")
+last=${last:-XXXXXXXX}
+indir="$imagedir/I5734/$last/"
+
+echo_color white blue ">>> Discarding whole ${firstdisk}"
+blkdiscard -v ${firstdisk}
+
+echo_color white blue ">>> Restoring ${firstdisk} boot sectors"
+pigz -dc "$indir/sda-dd.gz" | dd of=${firstdisk} count=2048
+
+echo_color white blue ">>> Detecting new partitions"
+echo -e "r\ne\ny\nw\ny" | gdisk ${firstdisk}
+
+echo_color white blue ">>> Restoring ${firstdiskp}1 NTFS WinRecovery"
+pigz -dc "$indir/sda1-partclone.gz" | partclone.restore -o ${firstdiskp}1
+
+echo_color white blue ">>> Restoring ${firstdiskp}2 FAT32 EFI"
+pigz -dc "$indir/sda2-partclone.gz" | partclone.restore -o ${firstdiskp}2
+
+echo_color white blue ">>> Restoring ${firstdiskp}3 RAW M$ Reserved"
+pigz -dc "$indir/sda3-dd.gz" | dd of=${firstdiskp}3
+
+echo_color white blue ">>> Restoring ${firstdiskp}4 NTFS Win10"
+pigz -dc "$indir/sda4-partclone.gz" | partclone.restore -o ${firstdiskp}4
+
+echo_color white blue ">>> Customizing WINDOWS"
+mkdir -p /mnt/win
+mount.ntfs ${firstdiskp}4 /mnt/win
+hostname > /mnt/win/EMAC/newhostname.txt
+echo "yes" > /mnt/win/EMAC/freshlycloned.txt
+echo $last_win > /mnt/win/EMAC/masterver.txt
+umount /mnt/win
+
diff --git a/nfs/scripts/image_deploy_dual-I5734-I6510.sh b/nfs/scripts/image_deploy_dual-I5734-I6510.sh
new file mode 100644
index 0000000..0c5b2f9
--- /dev/null
+++ b/nfs/scripts/image_deploy_dual-I5734-I6510.sh
@@ -0,0 +1,72 @@
+#!/bin/busybox sh
+# Should only started from image_capture.sh, it defines some helper functions and variables)
+# echo_color() <text-color> <background-color> <message>
+# $outdir is the also the current working dir, garanted to be empty and writable
+# Many cloning/partitioning tools are available for use, see make-boot-image.sh
+
+last_win=$(cat "$imagedir/I5734/last") # FIXME ceci est provisoire et prends le windows périmé du master linux. Doit etre I5734 à terme
+last_win=${last_win:-XXXXXXXX}
+indir_win="$imagedir/I5734/$last_win/"
+
+last=$(cat "$imagedir/I6510/last")
+last=${last:-XXXXXXXX}
+indir="$imagedir/I6510/$last/"
+
+echo_color white blue ">>> DUALBOOT indir_win='$indir_win'"
+echo_color white blue ">>> DUALBOOT indir='$indir'"
+
+echo_color white blue ">>> Discarding whole ${firstdisk}"
+blkdiscard -v ${firstdisk}
+
+echo_color white blue ">>> Restoring ${firstdisk} boot sectors"
+pigz -dc "$indir/sda-dd.gz" | dd of=${firstdisk} count=2048
+
+echo_color white blue ">>> Detecting new partitions"
+echo -e "r\ne\ny\nw\ny" | gdisk ${firstdisk}
+
+echo_color white blue ">>> Restoring ${firstdiskp}1 NTFS WinRecovery"
+pigz -dc "$indir/sda1-partclone.gz" | partclone.restore -o ${firstdiskp}1
+
+echo_color white blue ">>> Restoring ${firstdiskp}2 FAT32 EFI"
+pigz -dc "$indir/sda2-partclone.gz" | partclone.restore -o ${firstdiskp}2
+
+echo_color white blue ">>> Restoring ${firstdiskp}3 RAW M$ Reserved"
+pigz -dc "$indir_win/sda3-dd.gz" | dd of=${firstdiskp}3
+
+echo_color white blue ">>> Restoring ${firstdiskp}4 NTFS Win10"
+pigz -dc "$indir_win/sda4-partclone.gz" | partclone.restore -o ${firstdiskp}4
+
+echo_color white blue ">>> Restoring ${firstdiskp}5 EXT4 LINUX"
+pigz -dc "$indir/sda5-partclone.gz" | partclone.restore -o ${firstdiskp}5
+
+echo_color white blue ">>> Restoring ${firstdiskp}6 Swap"
+pigz -dc "$indir/sda6-dd.gz" | dd of=${firstdiskp}6
+
+echo_color white blue ">>> Customizing WINDOWS"
+mkdir -p /mnt/win
+mount.ntfs ${firstdiskp}4 /mnt/win
+hostname > /mnt/win/EMAC/newhostname.txt
+echo "yes" > /mnt/win/EMAC/freshlycloned.txt
+echo $last_win > /mnt/win/EMAC/masterver.txt
+umount /mnt/win
+
+echo_color white blue ">>> Customizing LINUX"
+mkdir -p /mnt/lin
+mount ${firstdiskp}5 /mnt/lin
+#mount.ntfs ${firstdisk}1 /mnt/lin/boot
+#mount -t proc proc /mnt/lin/proc
+#mount -t sysfs sysfs /mnt/lin/sys
+#mount --bind /dev /mnt/lin/dev
+#chroot /mnt/lin update-grub
+#umount /mnt/lin/dev /mnt/lin/sys /mnt/lin/proc /mnt/lin/boot
+hostname > /mnt/lin/etc/hostname
+echo $last > /mnt/lin/masterver.txt
+sed --in-place "s/I6510/$(hostname)/g" /mnt/lin/etc/hosts
+umount /mnt/lin
+
+echo_color white blue ">>> Setting next boot to Windows"
+mkdir -p /mnt/boot
+mount ${firstdiskp}2 /mnt/boot
+cp /mnt/boot/grub/grubenv.freshlycloned /mnt/boot/grub/grubenv
+umount /mnt/boot
+
diff --git a/nfs/scripts/masterlist-autogenerated.conf b/nfs/scripts/masterlist-autogenerated.conf
new file mode 100644
index 0000000..ac1d378
--- /dev/null
+++ b/nfs/scripts/masterlist-autogenerated.conf
@@ -0,0 +1,10 @@
+# DO NOT EDIT
+# Generated from /root/maintenance/si_sallestp/gen-configs/gen-masterlist-sallestp on 2020-07-02 17:38:55+02:00
+type echo_color >/dev/null || echo_color() { echo $*; }
+case "$hostname" in
+ I5456) mastername=dual-I5734-I6510;; # atelier
+ I6002) mastername=dual-I5734-I6510;; # atelier
+ # Ne pas mettre d'action sur le cas "*)" car ça veut dire que l'outil de clonage va éclater le disque de n'importe quelle machine inconnue sans confirmation avec une image probablement inappropriée
+ *) echo_color white red ">>> No master for $hostname (see image_deploy.sh)" ; exit 1 ;;
+esac
+# DO NOT EDIT