Browse Source

first commit

master
Christoph Haug 7 months ago
commit
0775265386
  1. 80
      sysprep.sh

80
sysprep.sh

@ -0,0 +1,80 @@
#!/bin/sh
if ! [ $(id -u) = 0 ]; then
sudo $0 $@
exit
fi
# Echo usage if something isn't right.
usage() {
echo "Usage: $0 [-h <hostname>] [-i <X.X.X.X>]" 1>&2; exit 1;
}
while getopts ":i:h:" o; do
case "${o}" in
h)
HOSTNAME=${OPTARG}
;;
i)
IP=${OPTARG}
;;
:)
echo "ERROR: Option -$OPTARG requires an argument"
usage
;;
\?)
echo "ERROR: Invalid option -$OPTARG"
usage
;;
esac
done
if [ ! -z "$HOSTNAME" ]
then
echo "###################################################################"
echo "# Rename hostname in /etc/hostname #"
echo "###################################################################"
echo ""
oldHostname=$(cat /etc/hostname)
awk '{print "- Old hostname "$1}' /etc/hostname
echo "- change Hostname to ${HOSTNAME}"
echo $HOSTNAME > /etc/hostname
sed -i "s/${oldHostname}/${HOSTNAME}/g" /etc/fstab
echo ""
echo "###################################################################"
echo "# Rename lvm volumes #"
echo "###################################################################"
echo ""
vg=`lvdisplay -C|awk '$1=="root" {print $2}'`
echo "- old lv name ${vg}"
newvg=$(echo $HOSTNAME| sed -e "s/-//g")
echo "- new lv name ${newvg}-vg"
vgrename ${vg} ${newvg}-vg
vgWithoutSuffix=$(echo $vg| sed -e "s/-.*//g")
sed -i "s/${vgWithoutSuffix}/${newvg}/g" /etc/fstab
sed -i "s/${vgWithoutSuffix}/${newvg}/g" /etc/initramfs-tools/conf.d/resume
sed -i "s/${vgWithoutSuffix}/${newvg}/g" /boot/grub/grub.cfg
update-initramfs -u -k all
echo ""
fi
if [ ! -z "$IP" ]
then
echo "###################################################################"
echo "# Change IP address #"
echo "###################################################################"
echo ""
OLDIP=$(ip addr | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
echo "- old IP ${OLDIP}"
echo "- change IP to ${IP}"
sed -i "s/${OLDIP}/${IP}/g" /etc/network/interfaces
echo ""
fi
dpkg-reconfigure openssh-server
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! Sysprep completed rebooting !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
reboot
Loading…
Cancel
Save