-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset.sh
executable file
·107 lines (81 loc) · 2.05 KB
/
reset.sh
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
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
echo
echo
echo "Ubuntu Server Deployment System Reset Script"
echo
# Check that this distribution is Ubuntu
if uname -v | grep -qvi ubuntu
then
echo "This script is meant for Ubuntu distributions only."
exit 1
fi
# Check if root
if [[ $UID != 0 ]]
then
echo "You are not root. This script must be run with root permissions."
exit 1
fi
# Filepath
root=$(dirname $(readlink -f $0))
# Get settings
echo
echo -n "Please enter a hostname: "
read myhostname
echo -n "Please enter a domain: "
read mydomain
# Confirmation
echo
echo "Please confirm your entries:"
echo " Hostname: $myhostname"
echo " Domain: $mydomain"
echo -n "Are these correct [y/N]? "
read confirm
echo
if [[ ! "$confirm" =~ ^[yY]([eE][sS])?$ ]]
then
echo "Reset Cancelled."
exit 1
fi
# Generate /etc/hostname
echo "Generating /etc/hostname"
sudo echo $myhostname > /etc/hostname
# Generate /etc/hosts
# hosts.template
# {IP} {HOSTNAME} {DOMAIN} {HOSTNAME}
echo "Generating /etc/hosts"
sudo cat << EOF > /etc/hosts
127.0.0.1 localhost
127.0.0.1 $myhostname.$mydomain $myhostname
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
# Generate /etc/network/interfaces
# interfaces.template
# {IP} {NETMASK} {NETWORK} {BROADCAST} {GATEWAY} {NAMESERVERS} {DOMAIN}
echo "Generating /etc/network/interfaces"
sudo cat << EOF > /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
EOF
echo "Generating ~/.bash_login"
cat << EOF > ~/.bash_login
echo
echo "Updating deployment scripts ..."
echo
# find all .git directories and exec "git pull" on the parent.
find $root -type d -name .git -exec sh -c "cd \"{}\"/../ && pwd && git pull" \;
echo
echo "Running deployment scripts ..."
sudo $root/deploy.sh
EOF
echo
echo "System reset for deployment. Please poweroff."
echo