-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·101 lines (84 loc) · 2.1 KB
/
install.sh
File metadata and controls
executable file
·101 lines (84 loc) · 2.1 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
#!/bin/bash
install_deps=0
install_gui=0
dry_run=0
script_dir=$(dirname "$0")
target_dir=""
os_type=""
# Function to log messages, supports dry-run mode
log() {
if [[ $dry_run == 1 ]]; then
echo "[DRY_RUN]: $1"
else
echo "$1"
fi
}
export -f log
copy() {
local source="$1"
local destination="$2"
if [[ -d "$source" ]]; then
# Source is a directory, copy recursively
cp -r "$source/." "$destination/"
else
# Source is a file, copy it directly
cp "$source" "$destination"
fi
}
export -f copy
# Function to run a setup.sh file
setup() {
local setup_dir=$(dirname $setup_file)
local setup_file=$(basename $1)
log "Running: $setup_file in $(basename $setup_dir)"
if [[ $dry_run == 0 ]]; then
pushd "$setup_dir" > /dev/null
OS="$os_type" INSTALL_DEPS="$install_deps" "./$setup_file"
popd > /dev/null
fi
}
# Detect the operating system and set os_type
detect_os() {
case "$(uname -s)" in
Linux*) os_type="linux" ;;
Darwin*) os_type="macos" ;;
CYGWIN*|MINGW*) os_type="windows" ;;
*) os_type="macos" ;;
esac
export OS_TYPE="$os_type"
log "OS: $os_type"
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--install-deps) install_deps=1 ;;
--install-gui) install_gui=1 ;;
--dry-run) dry_run=1 ;;
*) target_dir="$1" ;;
esac
shift
done
# Detect the OS before running any scripts
detect_os
# Ensure ~/.config exists
if [[ $dry_run == 0 ]]; then
mkdir -p ~/.config
fi
# If a target directory is specified, run its setup.sh
if [[ -n $target_dir ]]; then
setup_file="$script_dir/$target_dir/setup.sh"
if [[ -f $setup_file ]]; then
setup "$setup_file"
else
log "Error: setup.sh not found in $target_dir."
exit 1
fi
else
# If no target directory, find and run all setup.sh files
setup_files=$(find "$script_dir" -mindepth 2 -maxdepth 2 -type f -name 'setup.sh' | sort)
for setup_file in $setup_files; do
setup "$setup_file"
done
fi
log "Done."
unset -f log