Skip to content

Commit 136a191

Browse files
authoredSep 16, 2024
Update setup.sh
1 parent 3eca9f3 commit 136a191

File tree

1 file changed

+11
-63
lines changed

1 file changed

+11
-63
lines changed
 

‎setup.sh

+11-63
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ fi
1010
apt update && apt upgrade -y
1111

1212
# Define the scripts directory
13-
scripts_dir="./.scripts"
13+
SCRIPT_DIR="./.scripts"
1414

15-
# Array of scripts to be executed
16-
scripts=(
17-
"set_hostname_timezone.sh"
18-
"setup_user.sh"
19-
"setup_ufw.sh"
20-
)
15+
# Ensure the script directory exists
16+
if [ ! -d "$SCRIPT_DIR" ]; then
17+
echo "Script directory $SCRIPT_DIR does not exist." 1>&2
18+
exit 1
19+
fi
2120

2221
# Set environment variable to verify script origin
2322
export RUN_BY_SETUP=true
@@ -46,17 +45,12 @@ export USERNAME=$username
4645
export PASSWORD=$password
4746

4847
# Execute each setup script
49-
for script in "${scripts[@]}"; do
50-
script_path="$scripts_dir/$script"
51-
52-
if [ -f "$script_path" ]; then
53-
echo "Running $script_path..."
54-
if ! bash "$script_path"; then
55-
echo "Error occurred while running $script_path. Exiting."
56-
exit 1
57-
fi
48+
for script in "$SCRIPT_DIR"/*.sh; do
49+
if [ -x "$script" ]; then
50+
echo "Running $script..."
51+
"$script" || { echo "Error running $script" 1>&2; exit 1; }
5852
else
59-
echo "$script_path does not exist. Skipping."
53+
echo "Skipping $script (not executable)" 1>&2
6054
fi
6155
done
6256

@@ -66,49 +60,3 @@ echo "All setup tasks completed."
6660
# Refresh the environment with the new hostname
6761
echo "Refreshing environment..."
6862
exec bash -l
69-
70-
##################################################################
71-
##################################################################
72-
##################################################################
73-
##################################################################
74-
##################################################################
75-
##################################################################
76-
77-
# Install required packages
78-
apt install -y apt-transport-https ca-certificates curl software-properties-common
79-
80-
# Add Docker's official GPG key
81-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
82-
83-
# Set up the Docker stable repository
84-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
85-
86-
# Update package index
87-
apt update
88-
89-
# Install Docker Engine, CLI, and Docker Compose plugin
90-
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
91-
92-
# Prompt for the username to add to the docker group
93-
read -p "Enter username to add to docker group: " username
94-
95-
# Add the user to the docker group
96-
usermod -aG docker "$username"
97-
98-
# Enable and start Docker service
99-
systemctl enable docker
100-
systemctl start docker
101-
102-
echo "Docker and Docker Compose installed and configured. User $username added to the docker group."
103-
104-
############################
105-
############################
106-
############################
107-
108-
# Refresh the environment with the new hostname and timezone
109-
exec bash -l
110-
111-
# Display Fail2Ban status
112-
fail2ban-client status
113-
114-
echo "Fail2Ban installed and configured. Service is running."

0 commit comments

Comments
 (0)
Please sign in to comment.