-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
71 lines (57 loc) · 1.59 KB
/
install.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
#!/usr/bin/env bash
# more consistent errors
error() {
echo -e "\033[31mError: \033[0m$1"
exit 1
}
# check if an argument is provided
if [ $# -eq 0 ]; then
echo "Usage: ./install.sh <system>"
error "No argument provided"
fi
# create symlinks for all dirs in ~/.config
create_symlinks() {
local source_path=$1
local remote_path="$HOME/.config"
# check if .config exists, if not create it
if [ ! -d "$remote_path" ]; then
mkdir -p "$remote_path"
fi
# iterate over files and directories in source path
for item in "$source_path"/*; do
base_name=$(basename "$item")
# skip README files
if [[ "$base_name" == "README.md" ]]; then
continue
fi
target="$remote_path/$base_name"
# if target already exists, rename it to name.OLD
if [ -e "$target" ]; then
mv "$target" "$target.OLD"
fi
# create symbolic link in remote_path
ln -s "$item" "$target"
done
echo "System configured successfully."
}
case $1 in
darwin)
echo "Configuring Darwin"
git sparse-checkout set darwin shared
if [ $? -ne 0 ]; then
error "Failed to configure git sparse-checkout for Darwin."
fi
create_symlinks ./darwin
;;
server)
echo "Configuring Server"
git sparse-checkout set server shared
if [ $? -ne 0 ]; then
error "Failed to configure git sparse-checkout for Server."
fi
create_symlinks ./server
;;
*)
error "Unrecognized config $1"
;;
esac