2020-01-24 00:50:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-01-24 01:27:23 +00:00
|
|
|
if [ $EUID -ne 0 ]; then
|
|
|
|
echo "You must run this script as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-01-24 00:50:04 +00:00
|
|
|
DATE=$(date '+%Y%m%d')
|
|
|
|
TMP_DIR=$(mktemp -d)
|
2020-01-25 21:40:55 +00:00
|
|
|
CUR_HOSTNAME=$(hostname)
|
2020-01-24 00:50:04 +00:00
|
|
|
GIT_LOC="https://github.com/krislamo/bootstrap.git"
|
|
|
|
|
2020-01-24 01:27:23 +00:00
|
|
|
echo "Enter name server's new hostname:"
|
|
|
|
read NEW_HOSTNAME
|
|
|
|
|
2020-01-28 01:06:41 +00:00
|
|
|
echo "Enter a static IP address (e.g. 192.168.1.2/24):"
|
|
|
|
read STATIC_IP
|
|
|
|
|
2020-01-24 01:27:23 +00:00
|
|
|
cp /etc/apt/sources.list /etc/apt/sources.list.$DATE
|
|
|
|
sed -i '/deb cdrom/d' /etc/apt/sources.list
|
2020-01-24 00:50:04 +00:00
|
|
|
|
|
|
|
apt-get update -y
|
|
|
|
apt-get upgrade -y
|
|
|
|
apt-get install git -y
|
|
|
|
|
|
|
|
cd $TMP_DIR
|
|
|
|
git clone $GIT_LOC
|
|
|
|
cd bootstrap
|
2020-01-24 01:27:23 +00:00
|
|
|
|
|
|
|
mkdir -p /root/.ssh/
|
|
|
|
cp --update authorized_keys /root/.ssh/authorized_keys
|
|
|
|
apt-get install openssh-server -y
|
|
|
|
|
2020-01-28 01:06:41 +00:00
|
|
|
# If STATIC_IP var was set, backup interfaces and set static IP
|
|
|
|
if [ ! -z "$STATIC_IP" ]; then
|
|
|
|
cp /etc/network/interfaces /etc/network/interfaces.$DATE
|
|
|
|
sed -i "s/dhcp/static/g" /etc/network/interfaces
|
|
|
|
if ! grep -q "address" /etc/network/interfaces; then
|
|
|
|
echo " address $STATIC_IP" >> /etc/network/interfaces
|
|
|
|
echo " gateway 192.168.1.1" >> /etc/network/interfaces
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-01-24 01:27:23 +00:00
|
|
|
hostnamectl set-hostname $NEW_HOSTNAME
|
|
|
|
cp /etc/hosts /etc/hosts.$DATE
|
2020-01-25 21:40:55 +00:00
|
|
|
sed -i "s/$CUR_HOSTNAME/$NEW_HOSTNAME/g" /etc/hosts
|
2020-01-24 01:27:23 +00:00
|
|
|
read -p "Press [enter] to restart this machine"
|
|
|
|
/sbin/shutdown -r now
|