-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·182 lines (167 loc) · 6.42 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env sh
# Soar Package Manager Installation Script
# POSIX compliant installation script
set -eu
main() {
DEFAULT_VERSION="latest"
SOAR_VERSION="${SOAR_VERSION:-$DEFAULT_VERSION}"
# ASCII Colors
RED="\033[0;31m"
GREEN="\033[0;32m"
BLUE="\033[0;34m"
YELLOW="\033[0;33m"
RESET="\033[0m"
# Function to check for a downloader, sorted by sanest choice
check_download_tool() {
if command -v curl >/dev/null 2>&1; then
printf "curl -fSL -o"
return 0
elif command -v wget >/dev/null 2>&1; then
printf "wget -O"
return 0
elif command -v soar-dl >/dev/null 2>&1; then
printf "soar-dl -o"
return 0
elif command -v soar >/dev/null 2>&1; then
printf "soar dl -o"
return 0
elif command -v aria2 >/dev/null 2>&1; then
printf "aria2 -o"
return 0
elif command -v aria2c >/dev/null 2>&1; then
printf "aria2c -o"
return 0
elif command -v axel >/dev/null 2>&1; then
printf "axel -o"
return 0
elif command -v http >/dev/null 2>&1; then
printf "http -Fdm -o"
return 0
elif command -v GET >/dev/null 2>&1; then
printf "PERL_GET"
return 0
elif command -v python >/dev/null 2>&1; then
printf "PYTHON_GET"
return 0
elif command -v python3 >/dev/null 2>&1; then
printf "PYTHON3_GET"
return 0
elif command -v busybox >/dev/null 2>&1; then
printf "busybox wget --no-check-certificate -O"
return 0
else
printf "${RED}✗ Error: Could not find a downloader (curl, wget, soar-dl, aria2, axel, httpie, perl, python, busybox).${RESET}\n" >&2
return 1
fi
}
# Function to determine installation directory
get_install_dir() {
# Check environment variables first
if [ -n "${SOAR_INSTALL_DIR-}" ]; then
if [ -d "$SOAR_INSTALL_DIR" ] && [ -w "$SOAR_INSTALL_DIR" ]; then
printf "%s" "$SOAR_INSTALL_DIR"
return
else
printf "${RED}✗ Error: SOAR_INSTALL_DIR ${BLUE}($SOAR_INSTALL_DIR)${RED} is not writable or doesn't exist${RESET}\n" >&2
exit 1
fi
fi
if [ -n "${INSTALL_DIR-}" ]; then
if [ -d "$INSTALL_DIR" ] && [ -w "$INSTALL_DIR" ]; then
printf "%s" "$INSTALL_DIR"
return
else
printf "${RED}✗ Error: INSTALL_DIR ${BLUE}($INSTALL_DIR)${RED} is not writable or doesn't exist${RESET}\n" >&2
exit 1
fi
fi
# Check ~/.local/bin
local_bin="$HOME/.local/bin"
if [ -d "$local_bin" ] && [ -w "$local_bin" ]; then
printf "%s" "$local_bin"
return
fi
# Fallback to /usr/local/bin if running as root
if [ "$(id -u)" = "0" ]; then
if [ -d "/usr/local/bin" ] && [ -w "/usr/local/bin" ]; then
printf "/usr/local/bin"
return
fi
fi
# Fallback to current directory
printf "${YELLOW}⚠ Notice: ${BLUE}~/.local/bin${YELLOW} not found or not writable. Installing in current directory.${RESET}\n" >&2
printf "${YELLOW}You should move the binary to a location in your ${BLUE}\$PATH.${RESET}\n" >&2
printf "%s" "$(pwd)"
}
# Function to download and install
install_soar() {
DOWNLOAD_TOOL=""
if ! DOWNLOAD_TOOL=$(check_download_tool); then
exit 1
fi
INSTALL_PATH=$(get_install_dir)
# Detect architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
ARCH="x86_64"
;;
aarch64)
ARCH="aarch64"
;;
*)
printf "${RED}Error: Unsupported architecture: ${YELLOW}$ARCH${RESET}\n" >&2
exit 1
;;
esac
# Get latest release URL
printf "Downloading Soar..."
case "$SOAR_VERSION" in
*nightly*)
RELEASE_URL="https://github.com/pkgforge/soar/releases/download/nightly/soar-$ARCH-linux"
;;
*latest*)
RELEASE_URL="https://github.com/pkgforge/soar/releases/latest/download/soar-$ARCH-linux"
;;
*)
RELEASE_URL="https://github.com/pkgforge/soar/releases/download/v$SOAR_VERSION/soar-$ARCH-linux"
;;
esac
printf " <== $RELEASE_URL\n"
# Download and install
if [ "$DOWNLOAD_TOOL" = "PERL_GET" ]; then
printf "[+] Using GET\n"
GET "$RELEASE_URL" > "$INSTALL_PATH/soar"
printf "\n"
elif [ "$DOWNLOAD_TOOL" = "PYTHON_GET" ]; then
printf "[+] Using python -c\n"
python -c "import urllib.request; urllib.request.urlretrieve('$RELEASE_URL', '$INSTALL_PATH/soar')"
printf "\n"
elif [ "$DOWNLOAD_TOOL" = "PYTHON3_GET" ]; then
printf "[+] Using python3 -c\n"
python3 -c "import urllib.request; urllib.request.urlretrieve('$RELEASE_URL', '$INSTALL_PATH/soar')"
printf "\n"
else
printf "[+] Using $DOWNLOAD_TOOL\n"
$DOWNLOAD_TOOL "$INSTALL_PATH/soar" "$RELEASE_URL"
fi
if [ ! -f "$INSTALL_PATH/soar" ]; then
printf "${RED}Error: Download failed${RESET}\n"
exit 1
fi
# Make executable
chmod +x "$INSTALL_PATH/soar"
"$INSTALL_PATH/soar" --version
printf "${GREEN}✓ Soar has been installed to: ${BLUE}$INSTALL_PATH/soar${RESET}\n"
printf "${YELLOW}ⓘ Make sure ${BLUE}$INSTALL_PATH${YELLOW} is in your ${BLUE}PATH.${RESET}\n"
printf "${YELLOW}ⓘ Documentation: ${BLUE}https://soar.qaidvoid.dev${RESET}\n"
printf "${YELLOW}ⓘ Discord: ${BLUE}https://docs.pkgforge.dev/contact/chat${RESET}\n"
printf "${YELLOW}ⓘ External Repositories are ${RED}NOT Enabled${YELLOW} by default${RESET}\n"
printf "${YELLOW}ⓘ Learn More: ${BLUE}https://docs.pkgforge.dev/repositories/external${RESET}\n"
printf "${YELLOW}ⓘ To enable external repos, Run: ${GREEN}soar defconfig --external${RESET}\n"
}
# Execute installation
install_soar
}
# Call main function
main