Skip to content

Commit 2fe94e2

Browse files
committed
feat: version 1 released :)
1 parent 0062705 commit 2fe94e2

File tree

7 files changed

+63
-68
lines changed

7 files changed

+63
-68
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ Script to setup ec2 instances for `mdgspace`
1616
- Run `curl -o setup.sh https://raw.githubusercontent.com/mdgspace/server-setup/master/setup.sh`
1717
2. Run `chmod +x setup.sh` to make the script executable
1818
3. Run `./setup.sh` to setup the server
19+
4. Remove the script and logs after inspecting the setup
20+
5. Logout and login again to apply the changes

main.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ exec > >(tee -i "setup.log") 2>&1
55

66
source scripts/config.sh
77
source scripts/install.sh
8+
source scripts/shell.sh
89
source scripts/iam.sh
910
source scripts/webpage.sh
10-
source scripts/shell.sh
1111
source scripts/verify.sh
1212

1313
echo "Setup script executed successfully"

scripts/config.sh

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ webpage_path="/var/www/html/index.html"
33
webpage_url="https://raw.githubusercontent.com/mdgspace/server-setup/master/downloads/index.html"
44
banner_url="https://raw.githubusercontent.com/mdgspace/server-map/main/banner.sh"
55
system_wide_bashrc="/etc/bash.bashrc"
6+
system_skel_bashrc="/etc/skel/.bashrc"
67
aliases_path="/etc/.bash_aliases"
78
aliases_url="https://raw.githubusercontent.com/mdgspace/server-setup/master/downloads/aliases.sh"
89

scripts/iam.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ sudo usermod -aG docker developers
77

88
# Generate a new key pair
99
ssh-keygen -t rsa -b 2048 -f temp_rsa_key -N ""
10-
PUBLIC_KEY=$(cat temp_rsa_key.pub)
11-
PRIVATE_KEY=$(cat temp_rsa_key)
1210

13-
rm temp_rsa_key temp_rsa_key.pub
11+
echo "ssh info for developers (non root users):"
12+
echo "------Copy the following private key and save it in a secure place------"
13+
cat temp_rsa_key
14+
echo "----------------------------------------------------------------------"
15+
16+
PUBLIC_KEY=$(cat temp_rsa_key.pub)
1417

1518
sudo mkdir /home/developers/.ssh
1619
sudo chown developers:developers /home/developers/.ssh
1720
sudo chmod 700 /home/developers/.ssh
1821

19-
echo "ssh info for developers (non root users):"
20-
echo "------Copy the following private key and save it in a secure place------"
21-
echo $PRIVATE_KEY
22-
echo "----------------------------------------------------------------------"
23-
2422
sudo sh -c "echo $PUBLIC_KEY >> /home/developers/.ssh/authorized_keys"
2523
sudo chown developers:developers /home/developers/.ssh/authorized_keys
2624
sudo chmod 600 /home/developers/.ssh/authorized_keys
25+
26+
rm temp_rsa_key temp_rsa_key.pub

scripts/shell.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ sudo sh -c "echo 'export server_name=$server_name' >> '$system_wide_bashrc'"
77

88
# Beautify the bash prompt
99
ps1_var="PS1='\[\e[92m\]\u@${server_name}\[\e[0m\]:\[\e[91m\]\w\\$\[\e[0m\] '"
10-
sudo sh -c "echo '$ps1_var' >> '$system_wide_bashrc'"
10+
sudo sh -c "echo '' >> '$system_skel_bashrc'"
11+
sudo sh -c "echo '# Custom configuration' >> '$system_skel_bashrc'"
12+
sudo sh -c "echo \"$ps1_var\" >> '$system_skel_bashrc'"
13+
14+
echo "" >> "$HOME/.bashrc"
15+
echo "# Custom configuration" >> "$HOME/.bashrc"
16+
echo "$ps1_var" >> "$HOME/.bashrc"
1117

1218
# Banner (server-map)
1319
response=$(curl -s $banner_url)
@@ -20,4 +26,5 @@ sudo sh -c "echo '$modified_response' >> '$system_wide_bashrc'"
2026

2127
# Aliases
2228
sudo curl -o "$aliases_path" "$aliases_url"
23-
sudo sh -c "echo '. $aliases_path' >> '$system_wide_bashrc'"
29+
sudo chmod a+r "$aliases_path"
30+
sudo sh -c "echo '. \"$aliases_path\"' >> '$system_wide_bashrc'"

scripts/verify.sh

-9
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,3 @@ fi
2929
if ! id -u developers &>/dev/null; then
3030
echo "non root user 'developers' is not created"
3131
fi
32-
33-
if [ ! -f /home/developers/.ssh/authorized_keys ]; then
34-
echo "SSH key for developers is not created"
35-
fi
36-
37-
# Verify Configuration
38-
if [ ! -f /var/www/html/index.html ]; then
39-
echo "webpage is not created"
40-
fi

setup.sh

+42-48
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ webpage_path="/var/www/html/index.html"
99
webpage_url="https://raw.githubusercontent.com/mdgspace/server-setup/master/downloads/index.html"
1010
banner_url="https://raw.githubusercontent.com/mdgspace/server-map/main/banner.sh"
1111
system_wide_bashrc="/etc/bash.bashrc"
12+
system_skel_bashrc="/etc/skel/.bashrc"
1213
aliases_path="/etc/.bash_aliases"
1314
aliases_url="https://raw.githubusercontent.com/mdgspace/server-setup/master/downloads/aliases.sh"
1415

@@ -72,6 +73,39 @@ sudo snap install --classic certbot
7273
sudo ln -s /snap/bin/certbot /usr/bin/certbot
7374
# endregion scripts/install.sh
7475

76+
# region scripts/shell.sh
77+
sudo chmod a+r "$system_wide_bashrc"
78+
79+
sudo sh -c "echo '' >> '$system_wide_bashrc'"
80+
sudo sh -c "echo '# Custom configuration' >> '$system_wide_bashrc'"
81+
82+
sudo sh -c "echo 'export server_name=$server_name' >> '$system_wide_bashrc'"
83+
84+
# Beautify the bash prompt
85+
ps1_var="PS1='\[\e[92m\]\u@${server_name}\[\e[0m\]:\[\e[91m\]\w\\$\[\e[0m\] '"
86+
sudo sh -c "echo '' >> '$system_skel_bashrc'"
87+
sudo sh -c "echo '# Custom configuration' >> '$system_skel_bashrc'"
88+
sudo sh -c "echo \"$ps1_var\" >> '$system_skel_bashrc'"
89+
90+
echo "" >> "$HOME/.bashrc"
91+
echo "# Custom configuration" >> "$HOME/.bashrc"
92+
echo "$ps1_var" >> "$HOME/.bashrc"
93+
94+
# Banner (server-map)
95+
response=$(curl -s $banner_url)
96+
97+
# Delete first line ("$server_name" variable)
98+
modified_response=$(echo "$response" | sed "1d")
99+
100+
sudo sh -c "echo '# Banner' >> '$system_wide_bashrc'"
101+
sudo sh -c "echo '$modified_response' >> '$system_wide_bashrc'"
102+
103+
# Aliases
104+
sudo curl -o "$aliases_path" "$aliases_url"
105+
sudo chmod a+r "$aliases_path"
106+
sudo sh -c "echo '. \"$aliases_path\"' >> '$system_wide_bashrc'"
107+
# endregion scripts/shell.sh
108+
75109
# region scripts/iam.sh
76110
sudo usermod -aG docker $USER
77111

@@ -82,23 +116,23 @@ sudo usermod -aG docker developers
82116

83117
# Generate a new key pair
84118
ssh-keygen -t rsa -b 2048 -f temp_rsa_key -N ""
85-
PUBLIC_KEY=$(cat temp_rsa_key.pub)
86-
PRIVATE_KEY=$(cat temp_rsa_key)
87119

88-
rm temp_rsa_key temp_rsa_key.pub
120+
echo "ssh info for developers (non root users):"
121+
echo "------Copy the following private key and save it in a secure place------"
122+
cat temp_rsa_key
123+
echo "----------------------------------------------------------------------"
124+
125+
PUBLIC_KEY=$(cat temp_rsa_key.pub)
89126

90127
sudo mkdir /home/developers/.ssh
91128
sudo chown developers:developers /home/developers/.ssh
92129
sudo chmod 700 /home/developers/.ssh
93130

94-
echo "ssh info for developers (non root users):"
95-
echo "------Copy the following private key and save it in a secure place------"
96-
echo $PRIVATE_KEY
97-
echo "----------------------------------------------------------------------"
98-
99131
sudo sh -c "echo $PUBLIC_KEY >> /home/developers/.ssh/authorized_keys"
100132
sudo chown developers:developers /home/developers/.ssh/authorized_keys
101133
sudo chmod 600 /home/developers/.ssh/authorized_keys
134+
135+
rm temp_rsa_key temp_rsa_key.pub
102136
# endregion scripts/iam.sh
103137

104138
# region scripts/webpage.sh
@@ -112,37 +146,6 @@ sudo sh -c "echo '$modified_html_content' > $webpage_path"
112146
echo "Webpage created at $webpage_path"
113147
# endregion scripts/webpage.sh
114148

115-
# region scripts/shell.sh
116-
sudo chmod a+r "$system_wide_bashrc"
117-
118-
sudo sh -c "echo '' >> '$system_wide_bashrc'"
119-
sudo sh -c "echo '# Custom configuration' >> '$system_wide_bashrc'"
120-
121-
sudo sh -c "echo 'export server_name=$server_name' >> '$system_wide_bashrc'"
122-
123-
# Beautify the bash prompt
124-
ps1_var="PS1='\[\e[92m\]\u@${server_name}\[\e[0m\]:\[\e[91m\]\w\\$\[\e[0m\] '"
125-
sudo sh -c "echo '$ps1_var' >> '$system_wide_bashrc'"
126-
127-
# Banner (server-map)
128-
response=$(curl -s $banner_url)
129-
130-
# Delete first line ("$server_name" variable)
131-
modified_response=$(echo "$response" | sed "1d")
132-
133-
sudo sh -c "echo '# Banner' >> '$system_wide_bashrc'"
134-
sudo sh -c "echo '$modified_response' >> '$system_wide_bashrc'"
135-
136-
# Aliases
137-
sudo curl -o "$aliases_path" "$aliases_url"
138-
139-
if [ -f ~/.bash_aliases ]; then
140-
. ~/.bash_aliases
141-
fi
142-
143-
sudo sh -c "echo '. $aliases_path' >> '$system_wide_bashrc'"
144-
# endregion scripts/shell.sh
145-
146149
# region scripts/verify.sh
147150
# Verify Installation
148151

@@ -175,15 +178,6 @@ fi
175178
if ! id -u developers &>/dev/null; then
176179
echo "non root user 'developers' is not created"
177180
fi
178-
179-
if [ ! -f /home/developers/.ssh/authorized_keys ]; then
180-
echo "SSH key for developers is not created"
181-
fi
182-
183-
# Verify Configuration
184-
if [ ! -f /var/www/html/index.html ]; then
185-
echo "webpage is not created"
186-
fi
187181
# endregion scripts/verify.sh
188182

189183

0 commit comments

Comments
 (0)