Project

General

Profile

Segnalazione #36 ยป change_hostname.txt

Michael Guggenberg, 05/22/2017 12:26 PM

 
1
apt-get update && apt-get -y install squashfs-tools
2

    
3
cp /srv/tftp/clonezilla/live/filesystem.squashfs /tmp
4
cd /tmp
5
unsquashfs filesystem.squashfs
6

    
7
cat <<'EOF' >> squashfs-root/usr/local/bin/pre_run
8
#!/bin/bash
9

    
10
echo "Inserire la partizione root (/dev/sdx1)"
11
read ROOT_PARTITION
12
echo $ROOT_PARTITION > /tmp/ROOT_PARTITION
13
echo "Inserire il nuovo nome host: "
14
read NEWHOST
15
echo $NEWHOST > /tmp/NEWHOST
16
EOF
17

    
18
chmod 755 squashfs-root/usr/local/bin/pre_run
19

    
20
cat <<'EOF' >> squashfs-root/usr/local/bin/post_run
21
#!/bin/bash
22

    
23
ROOT_PARTITION=$(</tmp/ROOT_PARTITION)
24
sudo mount $ROOT_PARTITION /mnt
25
HOSTN=$(</mnt/etc/hostname)
26
echo "Existing hostname is $HOSTN"
27
NEWHOST=$(</tmp/NEWHOST)
28
sudo sed -i "s/$HOSTN/$NEWHOST/g" /mnt/etc/hosts
29
sudo sed -i "s/$HOSTN/$NEWHOST/g" /mnt/etc/hostname
30
sudo echo "Nuovo nome host: $NEWHOST"
31
read -s -n 1 -p "Riavvia"
32
sudo reboot
33
EOF
34

    
35
chmod 755 squashfs-root/usr/local/bin/post_run
36

    
37
mksquashfs squashfs-root filesystem.squashfs.new -b 1024k -comp xz -Xbcj x86 -e boot
38
cp filesystem.squashfs.new /srv/tftp/clonezilla/live/filesystem.squashfs
39
rm -rf filesystem.squashfs filesystem.squashfs squashfs-root/ -rf 
40

    
41
sed -i '/APPEND/s/$/ ocs_prerun=\"\/usr\/local\/bin\/pre_run\" ocs_postrun=\"\/usr\/local\/bin\/post_run\"/' /srv/tftp/pxelinux.cfg/default
42
systemctl restart tftpd-hpa
43

    
44

    
45

    
46

    
47

    
    (1-1/1)