summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xnfs/autorun.sh30
-rw-r--r--nfs/scripts/funcs.sh52
-rw-r--r--nfs/scripts/image_capture.sh21
-rw-r--r--nfs/scripts/image_capture_I5456.sh19
-rw-r--r--nfs/scripts/image_deploy.sh4
5 files changed, 126 insertions, 0 deletions
diff --git a/nfs/autorun.sh b/nfs/autorun.sh
new file mode 100755
index 0000000..4d6461a
--- /dev/null
+++ b/nfs/autorun.sh
@@ -0,0 +1,30 @@
+#!/bin/busybox sh
+read -t10 -p 'Press Enter or wait 10 sec...' # Let the user read machine_info and other usefull informations on console (or skip with Enter)
+echo -e '\n\n\n\n\n' # Make some blank lines on console
+
+# Define some handy variables
+imagedir=/mnt/nfs/images
+scriptdir=/mnt/nfs/scripts/
+hostname=$(hostname)
+
+# Load helper functions
+source $scriptdir/funcs.sh # Load some autorun.sh specific helper functions
+source /etc/init.d/funcs # Reload init help functions
+
+# Check all prerequisites and exit if it fail
+hostname_test || exit 1
+firstdisk_test || exit 2
+
+# Run the main action script
+if nfswrite_test
+then # Start deploy script
+ source $scriptdir/image_deploy.sh
+
+else # Start capture script if all it needs is available
+ if scriptavailability_test image_capture_${hostname}.sh
+ then source $scriptdir/image_capture.sh
+ fi
+fi
+
+# Display ending message then reboot
+eficast_end
diff --git a/nfs/scripts/funcs.sh b/nfs/scripts/funcs.sh
new file mode 100644
index 0000000..5e27052
--- /dev/null
+++ b/nfs/scripts/funcs.sh
@@ -0,0 +1,52 @@
+# no args, print colored message, returns 0 if hostname seems valid, returns 1 if hostname is a default one
+hostname_test() {
+ case $hostname in
+ "(none)"|eficast|"") echo_color white red ">>> " "hostname is not customized : $hostname" ; return 1 ;;
+ *\&*) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *\(*) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *\{*) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *\;*) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *\<*) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *\`*) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *\ *) echo_color white red ">>> " "hostname should not contain special characters or should not be FQDN : $hostname" ; return 2 ;;
+ *) echo_color green black ">>> " "hostname is $hostname" ; return 0 ;;
+ esac
+}
+
+# no args, print colored message, returns 0 if NFS is read-only, returns 1 if NFS is read-write (needed for image capture)
+nfswrite_test() {
+ if ! touch /mnt/nfs/.writetest
+ then echo_color green black ">>> " "NFS is read-only"
+ return 0
+ else echo_color white blue ">>> " "NFS is read-write"
+ return 1
+ fi
+}
+
+# no args, print colored message, returns 0 if sda is present and is sata, returns >0 if it is not
+firstdisk_test() {
+ diskinfo=$(lsblk --list --output TRAN,MODEL --noheadings --nodeps /dev/sda)
+ case $diskinfo in
+ sata*) echo_color green black ">>> " "First disk is SATA and is available ($diskinfo)"
+ return 0
+ ;;
+ usb*) echo_color white red ">>> " "First disk is USB ($diskinfo)"
+ return 1
+ ;;
+ *) echo_color white red ">>> " "First disk is unknown ($diskinfo)"
+ return 2;
+ ;;
+ esac
+}
+
+# $1 : scriptname, print colored message, returns 0 script is available, returns 1 if not
+scriptavailability_test() {
+ script=$scriptdir/$1
+ if [ -r $script ]
+ then echo_color green black ">>> " "Script $script is available"
+ return 0
+ else echo_color white blue ">>> " "Script $script is missing or unreadable"
+ return 1
+ fi
+}
+
diff --git a/nfs/scripts/image_capture.sh b/nfs/scripts/image_capture.sh
new file mode 100644
index 0000000..53c75ad
--- /dev/null
+++ b/nfs/scripts/image_capture.sh
@@ -0,0 +1,21 @@
+#!/bin/busybox sh
+# 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"
+
+if [ -d "$outdir" ]
+then rm -r "$outdir"
+fi
+mkdir -p "$outdir"
+cd "$outdir"
+mkdir logs
+date >logs/date.log
+
+# Start the capture using the customized script (image_capture_<hostname>.sh)
+source $scriptdir/image_capture_${hostname}.sh
+
+date >>logs/date.log
+
diff --git a/nfs/scripts/image_capture_I5456.sh b/nfs/scripts/image_capture_I5456.sh
new file mode 100644
index 0000000..bc40a51
--- /dev/null
+++ b/nfs/scripts/image_capture_I5456.sh
@@ -0,0 +1,19 @@
+#!/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_deploy.sh b/nfs/scripts/image_deploy.sh
new file mode 100644
index 0000000..bdc5e9c
--- /dev/null
+++ b/nfs/scripts/image_deploy.sh
@@ -0,0 +1,4 @@
+#!/bin/busybox sh
+# Should only started from autorun.sh (define some helper functions and variables)
+
+echo_color white red ">>> " "Image deploy not yet ready"