-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_main.sh
121 lines (103 loc) · 3.62 KB
/
install_main.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Welcome message
echo "Welcome to SZILARDSHOMELAB!"
echo "Starting the script..."
# Log file
LOG_FILE="/opt/logs/clone_repo.log"
# Ensure the logs directory exists
mkdir -p /opt/logs
# Remove the target directory if it exists
TARGET_DIR="/opt/szilardshomelab"
if [ -d "$TARGET_DIR" ]; then
sudo rm -rf "$TARGET_DIR"
if [ $? -eq 0 ]; then
echo "Existing $TARGET_DIR removed successfully." | tee -a "$LOG_FILE"
echo "$(date): Existing $TARGET_DIR removed successfully." >> "$LOG_FILE"
else
echo "Failed to remove existing $TARGET_DIR." | tee -a "$LOG_FILE"
echo "$(date): Failed to remove existing $TARGET_DIR." >> "$LOG_FILE"
exit 1
fi
fi
# Target directory
REPO_URL="https://github.com/szilardshomelab/installer.git"
BRANCH="main"
# Start logging
echo "$(date): Script started." >> "$LOG_FILE"
echo "$(date): Welcome to SZILARDSHOMELAB!" >> "$LOG_FILE"
# Ensure Git is installed
if ! command -v git &> /dev/null; then
echo "Git is not installed. Installing Git..." | tee -a "$LOG_FILE"
sudo apt-get update >> "$LOG_FILE" 2>&1
sudo apt-get install git -y >> "$LOG_FILE" 2>&1
fi
# Clone the Git repo
echo "Cloning the repository..." | tee -a "$LOG_FILE"
git clone --branch "$BRANCH" "$REPO_URL" "$TARGET_DIR" >> "$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
echo "Repository cloned successfully." | tee -a "$LOG_FILE"
echo "$(date): Repository cloned successfully." >> "$LOG_FILE"
else
echo "Failed to clone the repository." | tee -a "$LOG_FILE"
echo "$(date): Failed to clone the repository." >> "$LOG_FILE"
exit 1
fi
# Set execution permissions for all .sh files in the target directory
echo "Setting execution permissions for all .sh files..." | tee -a "$LOG_FILE"
find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \; >> "$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
echo "Execution permissions set successfully." | tee -a "$LOG_FILE"
echo "$(date): Execution permissions set successfully." >> "$LOG_FILE"
else
echo "Failed to set execution permissions." | tee -a "$LOG_FILE"
echo "$(date): Failed to set execution permissions." >> "$LOG_FILE"
exit 1
fi
# Set ownership and permissions for the directories
directories=(
"/opt/appdata"
"/opt/szilardshomelab"
"/opt/logs"
)
# Change ownership to ubuntu
for dir in "${directories[@]}"; do
if [ -d "$dir" ]; then
sudo chown -R ubuntu:ubuntu "$dir"
echo "Changed ownership of $dir to ubuntu:ubuntu" | tee -a "$LOG_FILE"
else
echo "$dir does not exist." | tee -a "$LOG_FILE"
fi
done
# Set full permissions (read, write, execute for owner, group, and others)
for dir in "${directories[@]}"; do
if [ -d "$dir" ]; then
sudo chmod -R 777 "$dir"
echo "Set full permissions for $dir" | tee -a "$LOG_FILE"
else
echo "$dir does not exist." | tee -a "$LOG_FILE"
fi
done
# Ensure /opt/appdata/traefik directory exists
TRAFFIC_DIR="/opt/appdata/traefik"
if [ -d "$TRAFFIC_DIR" ]; then
# Set permissions for acme.json file if it exists
ACME_FILE="$TRAFFIC_DIR/acme.json"
if [ -f "$ACME_FILE" ]; then
sudo chmod 600 "$ACME_FILE"
echo "Set permissions for $ACME_FILE to 600" | tee -a "$LOG_FILE"
else
echo "$ACME_FILE does not exist." | tee -a "$LOG_FILE"
fi
else
echo "$TRAFFIC_DIR does not exist." | tee -a "$LOG_FILE"
fi
# End logging
echo "$(date): Script finished." >> "$LOG_FILE"
# Clear the screen and execute the menu script
clear
"$TARGET_DIR/menu/menu.sh"
# Check if menu.sh execution was successful
if [ $? -ne 0 ]; then
echo "$(date): menu.sh execution failed." >> "$LOG_FILE"
exit 1
fi