This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·134 lines (118 loc) · 2.83 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
# Get current location of this script
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LINKS_ONLY=false
INSTALLER="Unknown"
declare -a TARGET_APPS
detect_package_manager() {
if [ -n "$PREFIX" ] && command -v pkg >/dev/null; then
INSTALLER="pkg install -yq"
elif command -v apt-get >/dev/null; then
INSTALLER="sudo apt-get install -yq"
elif command -v dnf >/dev/null; then
INSTALLER="sudo dnf install -yq"
elif command -v yum >/dev/null; then
INSTALLER="sudo yum install -yq"
elif command -v pacman >/dev/null; then
INSTALLER="sudo pacman -S --noconfirm"
elif command -v zypper >/dev/null; then
INSTALLER="sudo zypper install -yq"
elif command -v pkg >/dev/null; then
INSTALLER="sudo pkg install -yq"
fi
}
install_app() {
local app_dir="$1"
if [ $LINKS_ONLY = true ]; then
echo "Setting symlinks for $app_dir"
get_symlinks "$app_dir"
else
echo "Installing $app_dir..."
install_requirements "$app_dir"
execute_install_script "$app_dir"
get_symlinks "$app_dir"
fi
}
install_requirements() {
local app_dir="$1"
if [[ -f "$app_dir/requirements.txt" ]]; then
while IFS= read -r requirement || [[ -n "$requirement" ]]; do
if [[ -z "$requirement" ]]; then
continue
fi
echo "Found requirement: $requirement"
install_app "$requirement"
done <"$app_dir/requirements.txt"
fi
}
execute_install_script() {
local app_dir="$1"
if [[ -f "$app_dir/install.sh" ]]; then
echo "Launching $app_dir install.sh"
(cd "$app_dir" && bash install.sh)
fi
}
get_symlinks() {
local app_dir="$1"
if [[ -f "$app_dir/symlinks.txt" ]]; then
while IFS= read -r link || [[ -n $link ]]; do
[[ "$link" =~ ^# || -z "$link" ]] && continue
while [[ $link =~ \$DIR || $link =~ \$HOME ]]; do
link=${link/\$DIR/$DIR}
link=${link/\$HOME/$HOME}
done
eval src="${link%=*}"
eval dest="${link#*=}"
src=${src%/}
dest=${dest%/}
create_symlink "$src" "$dest"
done <"$app_dir/symlinks.txt"
fi
}
create_symlink() {
local src=$1
local dest=$2
if [ ! -e "$src" ]; then
echo "Source $src does not exist. Skipping..."
return
fi
if [ -e "$dest" ] || [ -L "$dest" ]; then
echo "Removing existing file or symlink at $dest"
rm -rf "$dest"
fi
mkdir --parents "$(dirname "$dest")"
echo "Creating symlink $src -> $dest"
ln -s "$src" "$dest"
}
parse_args() {
if [ "$#" -eq 0 ]; then
echo "No arguments provided. Use --all to install all or specify individual apps."
exit 1
fi
while (("$#")); do
case "$1" in
-l | --links)
LINKS_ONLY=true
shift
;;
*)
if [[ -d $1 ]]; then
TARGET_APPS+=("$1")
else
echo "Warning: '$1' is not a recognized app directory."
fi
shift
;;
esac
done
}
main() {
parse_args "$@"
detect_package_manager
export INSTALLER
for app in "${TARGET_APPS[@]}"; do
install_app "$app"
done
echo "Installation complete."
}
main "$@"