-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
65 lines (51 loc) · 1.46 KB
/
setup.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
#!/usr/bin/env bash
# Check if the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit 1
fi
# Update and upgrade system
apt update && apt upgrade -y
# Define the scripts directory
SCRIPT_DIR="./.scripts"
# Ensure the script directory exists
if [ ! -d "$SCRIPT_DIR" ]; then
echo "Script directory $SCRIPT_DIR does not exist." 1>&2
exit 1
fi
# Make all scripts in the .scripts directory executable
chmod +x "$SCRIPT_DIR"/*.sh
# Set environment variable to verify script origin
export RUN_BY_SETUP=true
# Prompt for new hostname
read -p "New Hostname: " hostname
# Prompt for new username
read -p "Enter new username: " username
# Prompt for password securely
read -s -p "Enter password for new user: " password
echo
read -s -p "Confirm password: " password_confirm
echo
# Check if passwords match
if [ "$password" != "$password_confirm" ]; then
echo "Passwords do not match. Exiting."
exit 1
fi
# Set environment variables for hostname, user & password
export HOSTNAME=$hostname
export USERNAME=$username
export PASSWORD=$password
# Execute each setup script
for script in "$SCRIPT_DIR"/*.sh; do
if [ -x "$script" ]; then
echo "Running $script..."
"$script" || { echo "Error running $script" 1>&2; exit 1; }
else
echo "Skipping $script (not executable)" 1>&2
fi
done
# Inform user of completion
echo "All setup tasks completed."
# Refresh the environment with the new hostname
echo "Refreshing environment..."
exec bash -l