Project

General

Profile

Download (2.6 KB) Statistics
| Branch: | Tag: | Revision:

fuss-fucc / script @ e2ac9a14

1
#!/bin/bash
2
#
3
# Script for automated cloning and renaming of Fuss 9 client computers
4
# using mac-address as unique identifier.
5
# Donato Florio 11 April 2019
6
#
7
# Last modified 02 May 2019 --> added modification to support cloning on nvme* devices (HP G450)
8
# Last modified 07 May 2019 --> added various stuff for experimental autojoin
9
# 
10
# PRT 1 ---------------------------
11

    
12

    
13
# La funzione getNetStuff serve per recuperare il nome della NIC in uso sul sistema attuale. 
14
getNetStuff(){
15
    if [ $1 -eq 1 ];then
16
	ls /sys/class/net/ -1 | grep -v lo | grep -v wlan
17
    else
18
	cat /sys/class/net/$(getNetStuff 1)/address
19
    fi
20
}
21

    
22
getDisk(){
23
    diskCount="$(ls /sys/block -1 | grep -Ev '(loop|sr|dvd|cd)' | wc -l)"
24
    
25
    if [ $diskCount -gt 1 ];then
26
	echo "ATTENZIONE! Questo computer sembra provvisto di più di un disco!"
27
	echo ""
28
	echo "La procedura automatica non prevede l'installazione su sistemi"
29
	echo "multidisco. Contattare il tecnico informatico."
30
	echo ""
31
	echo "Per sicurezza il computer verrà spento tra 10 secondi."
32
	sleep 10
33
	shutdown -h now
34
    else
35
	diskVar="$(ls /sys/block -1 | grep -Ev '(loop|sr|dvd|cd)')"
36
    fi
37
    
38
    # SSD portatili HP g450 
39
    if [ $diskVar == "nvme0n1" ];then
40
	rootPartition="p$rootPartition"
41
    fi
42
    # FINE g450
43
}
44

    
45
rootPartition=2
46
getDisk
47
rootDisk="/dev/$diskVar"
48
mountPoint="/mnt"
49
computerList="/home/partimag/ListaPc.txt"
50
macAddress=$(getNetStuff 2)
51
imageName=$(cat $computerList | grep "$macAddress" | awk '{print $3}')
52

    
53
ocs-sr -b -g auto -e1 auto -e2 -r -j2 -scr -p true restoredisk $imageName $diskVar
54

    
55
# # PRT 2 ---------------------------
56
mount $rootDisk$rootPartition $mountPoint
57

    
58
currentName="$(cat $mountPoint/etc/hostname)"
59
newName="$(grep "$macAddress" $computerList | awk '{print $1}')"
60

    
61
echo "SETTING HOSTNAME" 
62

    
63
for i in hostname hosts mailname
64
	 
65
do
66
    if [ -e $mountPoint/etc/$i ]; then
67
	sed -ie "s/$currentName/$newName/g" $mountPoint/etc/$i
68
    else
69
	echo "The file $i is not present on this system"
70
    fi    
71
done
72

    
73

    
74

    
75
# ###  Here I insert the part for the joining preparation of the machine
76

    
77
# Veriy whether the machine has to be joined to the domain or not.
78
# If so the .ssh keys are needed and also a script ..... 
79

    
80
joinVar="$(cat $computerList | grep "$macAddress" | awk '{print $4}')" 
81

    
82
if [ "$joinVar" == "join" ];then
83
    rsync -a /home/partimag/.ssh/ /mnt/root/.ssh/
84
    cp /root/.ssh/known_hosts /mnt/root/.ssh/known_hosts
85
    cp /home/partimag/clientScripts/rc.local /mnt/etc/
86
    chmod 770 /mnt/etc/rc.local
87
    cp /home/partimag/clientScripts/clientScript /mnt/root/
88
    chmod 770 /mnt/root/clientScript
89
    touch /mnt/root/reboot
90
fi
91
# ### END of the preparation stuff
92

    
93

    
94
reboot
95

    
96

    
(5-5/5)