-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·111 lines (90 loc) · 2.62 KB
/
setup.sh
File metadata and controls
executable file
·111 lines (90 loc) · 2.62 KB
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
#!/bin/bash
USERNAME=$1
HOSTNAME=$2
ARGC=$#
function check_uid() {
if [ $EUID -ne 0 ]; then
echo "[*] Run as root."
exit 1
fi
}
function check_args() {
if [ $ARGC -lt 2 ]; then
echo "[*] Invalid options, must be ./setup.sh username hostname"
exit 1
fi
}
function detect_os() {
case "$(uname -s)" in
Linux*) MACHINE="Linux";;
Darwin*) MACHINE="Mac";;
*) MACHINE="unknown";;
esac
echo "[*] Running on ${MACHINE}"
if [[ "$MACHINE" = "unknown" ]]; then
exit 1
fi
if [[ "$MACHINE" = "Linux" ]]; then
DISTRO=$(cat /etc/os-release | grep "^NAME=" | head -n1 | sed 's/NAME=//g' | sed 's/"//g' | awk '{print $1}')
fi
}
function config_macos_system() {
echo "[*] Configuring macOS system..."
if [ -f "system-configs/macos/brew/casks" ] &&
[ -f "system-configs/macos/brew/leaves" ] &&
[ -f "system-configs/macos/brew/taps" ]; then
echo "[*] Installing brew packages"
while read -r line; do
sudo -u $USERNAME brew tap $line
done < system-configs/macos/brew/taps
while read -r line; do
sudo -u $USERNAME brew install $line
done < system-configs/macos/brew/casks
while read -r line; do
sudo -u $USERNAME brew install $line
done < system-configs/macos/brew/leaves
fi
echo "[*] Overlaying files..."
if [ -d "system-configs/macos/files/" ]; then
rsync -tr system-configs/macos/files/* /
fi
echo "[*] Running macOS setup scripts..."
if [ -d "system-configs/macos/setup/" ]; then
for script in system-configs/macos/setup/*.sh; do
if [[ "$script" = "configure.sh" ]]; then
bash "$script $HOSTNAME"
else
bash "$script"
fi
done
fi
}
function config_arch_system() {
echo "[*] Configuring Arch Linux system..."
echo "[*] Overlaying files..."
if [ -d "system-configs/arch/files/" ]; then
rsync -tr system-configs/arch/files/* /
fi
}
function config_ubuntu_system() {
echo "[*] Configuring Ubuntu system..."
echo "[*] Overlaying files..."
if [ -d "system-configs/ubuntu/files/" ]; then
rsync -tr system-configs/ubuntu/files/* /
fi
}
function main() {
check_uid
check_args
detect_os
if [[ "$MACHINE" = "Mac" ]]; then
config_macos_system
elif [[ "$MACHINE" = "Linux" ]]; then
if [[ "$DISTRO" = "Arch" ]]; then
config_arch_system
elif [[ "$DISTRO" = "Ubuntu" ]]; then
config_ubuntu_system
fi
fi
}
main