Changes to clonezilla/script by Donato Florio

parent 2c0f41af
#!/bin/bash
#
# Script for automated cloning and renaming of Fuss 9 client computers
# Script for automated cloning and renaming of Fuss 9/10 client computers
# using mac-address as unique identifier.
# Donato Florio 11 April 2019
#
......@@ -8,6 +8,8 @@
# Last modified 07 May 2019 --> added various stuff for experimental autojoin to a domain
# Last modified 21 June 2019 --> added various stuff for experimental join to a cluster
# Last modified 01 July 2019 --> added ssh to script and changed disk detection method
# Last modified 12-13 May 2020 --> automatic root partition selection + EFI stuff
# Last modified 19 May 2020 --> little modification of the "dialog" interface
#
# PRT 1 ---------------------------
......@@ -49,39 +51,50 @@ getDisk(){
# FINE g450
}
rootPartition=2
getRootPartitionFuss(){
for i in $(blkid | grep -v "squash" | nl | grep ext | awk '{print $2}' | tr -d ":")
do
mount $i /mnt
if [ -d "/mnt/etc/fuss-client" ];then
fussDir="$i"
fi
umount /mnt
done
echo "$(blkid | sort | grep -v "squash" | nl | grep ext | grep "$fussDir" | awk '{print $1}')"
}
getImages(){
for i in $(ls /home/partimag)
do
list="$(ls /home/partimag/$i/clonezilla-img 2>/dev/null | cut -d "/" -f 4) $list"
done
for j in $list
do
nrList="$j - $nrList"
done
echo $nrList
}
getDisk
rootDisk="/dev/$diskVar"
mountPoint="/mnt"
computerList="/home/partimag/computerList.txt"
macAddress=$(getNetStuff 2)
if [ "$1" = "check" ]; then
myLine=$(grep $macAddress $computerList | tail -1)
hostname=$(echo $myLine | awk '{print $1}')
img=$(echo $myLine | awk '{print $3}')
join=$(echo $myLine | awk '{print $4}')
cluster=$(echo $myLine | awk '{print $5}')
if ! dialog --title "FUSS FUCC" --yesno "Hostname: $hostname \nMAC: $macAddress \nImage: $img \nJoin: $join \nCluster: $cluster \nContinue?" 13 70; then
grep -v $macAddress $computerList > ${computerList}.new
cp ${computerList}.new ${computerList}
rm ${computerList}.new
fi
fi
if ! grep $macAddress $computerList; then
dialog --title "FUSS FUCC" --msgbox "Hi,\nunfortunatley, there is no valid configuration to setup this computer. Please go through the next few steps to configure how to install this PC.\nPlease make sure that the file /home/clonezilla/computerList.txt is owned and writable by clonezilla, otherwise we'll not be able to save the informations you're going to enter." 13 70
hostname=$(dialog --title "FUSS FUCC" --inputbox "Please, pick an HOSTNAME for this PC" --output-fd 1 10 70)
images=$(ls -1 /home/partimag|nl)
_img=$(dialog --title "FUSS FUCC" --output-fd 1 --menu "Choose an image to be installed" 15 50 4 $images)
img=$(ls -1 /home/partimag | sed -n "${_img}p")
dialog --title "FUSS FUCC" --msgbox "Set image $img" 13 70
img=$(dialog --title "FUSS FUCC" --output-fd 1 --menu "Choose an image to be installed" 15 50 4 $(getImages))
# dialog --title "FUSS FUCC" --msgbox "Set image $img" 13 70
if dialog --title "FUSS FUCC" --yesno "Join this client to the FUSS domain?" 13 70; then
join="join"
join="join"
cluster=$(dialog --title "FUSS FUCC" --inputbox "Please, pick a CLUSTER for this PC" --output-fd 1 10 70)
else
join="no"
fi
cluster=$(dialog --title "FUSS FUCC" --inputbox "Please, pick a CLUSTER for this PC" --output-fd 1 10 70)
if dialog --title "FUSS FUCC" --yesno "Hostname: $hostname \nMAC: $macAddress \nImage: $img \nJoin: $join \nCluster: $cluster \nContinue?" 13 70; then
echo $hostname $macAddress $img $join $cluster >> $computerList
dialog --title "FUSS FUCC" --msgbox "Configuration completed, now start cloning." 15 70
......@@ -96,16 +109,28 @@ imageName=$(cat $computerList | grep "$macAddress" | awk '{print $3}')
ocs-sr -b -g auto -e1 auto -e2 -r -j2 -scr -p true restoredisk $imageName $diskVar
rootPartition=$(getRootPartitionFuss)
# # PRT 2 ---------------------------
mount $rootDisk$rootPartition $mountPoint
# Check for EFI partition. If present mount it and install grub files ----------
efiPart=$(fdisk -l | grep EFI | awk '{print $1}')
if [ $efiPart ]; then
mkdir -p $mountPoint/boot/efi
mount $efiPart $mountPoint/boot/efi
grub-install --boot-directory=$mountPoint/boot --efi-directory=$mountPoint/boot/efi/
fi
# -----------------------------------------------------------------------------
currentName="$(cat $mountPoint/etc/hostname)"
newName="$(grep "$macAddress" $computerList | awk '{print $1}')"
echo "SETTING HOSTNAME"
for i in hostname hosts mailname
do
if [ -e $mountPoint/etc/$i ]; then
sed -ie "s/$currentName/$newName/g" $mountPoint/etc/$i
......@@ -126,26 +151,23 @@ joinVar="$(cat $computerList | grep "$macAddress" | awk '{print $4}')"
clusterVar="$(cat $computerList | grep "$macAddress" | awk '{print $5}')"
if [ "$joinVar" == "join" ];then
rsync -a /home/partimag/.ssh/ /mnt/root/.ssh/
cp /root/.ssh/known_hosts /mnt/root/.ssh/known_hosts
chown -R root:root /mnt/root/.ssh
cp /home/partimag/clientScripts/rc.local /mnt/etc/
chmod 770 /mnt/etc/rc.local
cp /home/partimag/clientScripts/clientScript /mnt/root/
rsync -a /home/partimag/.ssh/ $mountPoint/root/.ssh/
cp /root/.ssh/known_hosts $mountPoint/root/.ssh/known_hosts
cp /home/partimag/clientScripts/rc.local $mountPoint/etc/
chmod 770 $mountPoint/etc/rc.local
cp /home/partimag/clientScripts/clientScript $mountPoint/root/
if [ -e /home/partimag/clientScripts/new_root_pw ] ; then
cp /home/partimag/clientScripts/new_root_pw /mnt/root/
cp /home/partimag/clientScripts/new_root_pw $mountPoint/root/
fi
chmod 770 /mnt/root/clientScript
touch /mnt/root/reboot
chmod 770 $mountPoint/root/clientScript
touch $mountPoint/root/reboot
fi
if [ "$clusterVar" != "" ];then
clusterJoin="-g $clusterVar"
echo "$clusterJoin" > /mnt/root/cluster
echo "$clusterJoin" > $mountPoint/root/cluster
fi
# ### END of the preparation stuff
......
......@@ -2,6 +2,10 @@ fuss-fucc (0.5.5) UNRELEASED; urgency=medium
* Remove /srv/tftp/pxelinux.cfg/default (managed by fuss-server).
[Donato Florio]
* automatic root partition selection + EFI stuff
* little modification of the "dialog" interface
-- Elena Grandi <elena@truelite.it> Fri, 29 May 2020 12:07:28 +0200
fuss-fucc (0.5.4) unstable; urgency=medium
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment