Add comments and set the hostname when given input
This commit is contained in:
parent
341fe665b6
commit
a3fce7539e
25
bootstrap.sh
25
bootstrap.sh
@ -1,15 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Root required
|
||||||
if [ $EUID -ne 0 ]; then
|
if [ $EUID -ne 0 ]; then
|
||||||
echo "You must run this script as root"
|
echo "You must run this script as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Get current date, hostname, create a temporary directory,
|
||||||
|
# and set the location to the remote repository
|
||||||
DATE=$(date '+%Y%m%d')
|
DATE=$(date '+%Y%m%d')
|
||||||
TMP_DIR=$(mktemp -d)
|
TMP_DIR=$(mktemp -d)
|
||||||
CUR_HOSTNAME=$(hostname)
|
CUR_HOSTNAME=$(hostname)
|
||||||
GIT_LOC="https://github.com/krislamo/bootstrap.git"
|
GIT_LOC="https://github.com/krislamo/bootstrap.git"
|
||||||
|
|
||||||
|
# Get user input for hostname and IP
|
||||||
echo "Enter name server's new hostname:"
|
echo "Enter name server's new hostname:"
|
||||||
read NEW_HOSTNAME
|
read NEW_HOSTNAME
|
||||||
|
|
||||||
@ -24,22 +28,26 @@ if [ ! -z "$STATIC_IP" ]; then
|
|||||||
echo "Gateway set to $GATEWAY_IP"
|
echo "Gateway set to $GATEWAY_IP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Remove CD sources
|
||||||
cp /etc/apt/sources.list /etc/apt/sources.list.$DATE
|
cp /etc/apt/sources.list /etc/apt/sources.list.$DATE
|
||||||
sed -i '/deb cdrom/d' /etc/apt/sources.list
|
sed -i '/deb cdrom/d' /etc/apt/sources.list
|
||||||
|
|
||||||
|
# Upgrade software
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
apt-get upgrade -y
|
apt-get upgrade -y
|
||||||
apt-get install git -y
|
|
||||||
|
|
||||||
|
# Install git, clone this repo, and navigate to it
|
||||||
|
apt-get install git -y
|
||||||
cd $TMP_DIR
|
cd $TMP_DIR
|
||||||
git clone $GIT_LOC
|
git clone $GIT_LOC
|
||||||
cd bootstrap
|
cd bootstrap
|
||||||
|
|
||||||
|
# Install personal SSH keys under root and install the OpenSSH server
|
||||||
mkdir -p /root/.ssh/
|
mkdir -p /root/.ssh/
|
||||||
cp --update authorized_keys /root/.ssh/authorized_keys
|
cp --update authorized_keys /root/.ssh/authorized_keys
|
||||||
apt-get install openssh-server -y
|
apt-get install openssh-server -y
|
||||||
|
|
||||||
# If STATIC_IP var was set, backup interfaces and set static IP
|
# If STATIC_IP is set, backup interfaces and configure static IP
|
||||||
if [ ! -z "$STATIC_IP" ]; then
|
if [ ! -z "$STATIC_IP" ]; then
|
||||||
cp /etc/network/interfaces /etc/network/interfaces.$DATE
|
cp /etc/network/interfaces /etc/network/interfaces.$DATE
|
||||||
sed -i "s/dhcp/static/g" /etc/network/interfaces
|
sed -i "s/dhcp/static/g" /etc/network/interfaces
|
||||||
@ -49,8 +57,11 @@ if [ ! -z "$STATIC_IP" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
hostnamectl set-hostname $NEW_HOSTNAME
|
# If NEW_HOSTNAME is set, configure new hostname and backup /etc/hosts
|
||||||
cp /etc/hosts /etc/hosts.$DATE
|
if [ ! -z "$NEW_HOSTNAME" ]; then
|
||||||
sed -i "s/$CUR_HOSTNAME/$NEW_HOSTNAME/g" /etc/hosts
|
hostnamectl set-hostname $NEW_HOSTNAME
|
||||||
read -p "Press [enter] to restart this machine"
|
cp /etc/hosts /etc/hosts.$DATE
|
||||||
/sbin/shutdown -r now
|
sed -i "s/$CUR_HOSTNAME/$NEW_HOSTNAME/g" /etc/hosts
|
||||||
|
read -p "Press [enter] to restart this machine"
|
||||||
|
/sbin/shutdown -r now
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user