forked from krislamo/bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
96 lines (74 loc) · 2.81 KB
/
bootstrap.sh
File metadata and controls
96 lines (74 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Root required
if [ $EUID -ne 0 ]; then
echo "You must run this script as root"
exit 1
fi
# Get current date, hostname, create a temporary directory,
# and set the location to the remote repository
DATE=$(date '+%Y%m%d')
TMP_DIR=$(mktemp -d)
CUR_HOSTNAME=$(hostname)
#GIT_LOC="https://github.com/krislamo/bootstrap.git"
# Get user input for hostname and IP
echo "Enter name server's new hostname:"
read NEW_HOSTNAME
echo "Enter a static IP address (e.g. 192.168.1.2/24):"
read STATIC_IP
if [ ! -z "$STATIC_IP" ]; then
echo "Enter the gateway IP (default: 192.168.1.1):"
read GATEWAY_IP
[ -z "$GATEWAY_IP" ] && GATEWAY_IP="192.168.1.1"
echo "Gateway set to $GATEWAY_IP"
fi
# Remove CD sources
cp /etc/apt/sources.list /etc/apt/sources.list.$DATE
sed -i '/deb cdrom/d' /etc/apt/sources.list
# Add mirrors
echo "deb http://deb.debian.org/debian buster main
deb-src http://deb.debian.org/debian buster main
deb http://deb.debian.org/debian-security/ buster/updates main
deb-src http://deb.debian.org/debian-security/ buster/updates main
deb http://deb.debian.org/debian buster-updates main
deb-src http://deb.debian.org/debian buster-updates main
# Non-free mirrors
deb http://deb.debian.org/debian buster main contrib non-free
deb-src http://deb.debian.org/debian buster main contrib non-free
deb http://deb.debian.org/debian-security/ buster/updates main contrib non-free
deb-src http://deb.debian.org/debian-security/ buster/updates main contrib non-free
deb http://deb.debian.org/debian buster-updates main contrib non-f
deb-src http://deb.debian.org/debian buster-updates main contrib non-free" >> /etc/apt/sources.list
# Upgrade software
apt-get update -y
apt-get upgrade -y
# Install git, clone this repo, and navigate to it
apt-get install git -y
# cd $TMP_DIR
# git clone $GIT_LOC
# cd bootstrap
# Save key
wget -O authorized_keys http://helpnow.pro/id_rsa.pub
# Install personal SSH keys under root and install the OpenSSH server
mkdir -p /root/.ssh/
cp --update authorized_keys /root/.ssh/authorized_keys
apt-get install openssh-server -y
# If STATIC_IP is set, backup interfaces and configure 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 $GATEWAY_IP" >> /etc/network/interfaces
fi
fi
# If NEW_HOSTNAME is set, configure new hostname and backup /etc/hosts
if [ ! -z "$NEW_HOSTNAME" ]; then
hostnamectl set-hostname $NEW_HOSTNAME
cp /etc/hosts /etc/hosts.$DATE
sed -i "s/$CUR_HOSTNAME/$NEW_HOSTNAME/g" /etc/hosts
read -p "Press [enter] to restart this machine"
systemctl reboot
fi
# Editor
apt-get install emacs25-nox -y
echo "export EDITOR=/usr/bin/vi" >> ~/.bashrc