-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·313 lines (258 loc) · 10.6 KB
/
setup.sh
File metadata and controls
executable file
·313 lines (258 loc) · 10.6 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
# ArchRiot Setup - Bulletproof Minimal Version
# Purpose: Download repository and run installer (nothing else!)
set -euo pipefail # Exit on any error, undefined vars, or pipe failures
# Colors for output
readonly PURPLE='\033[0;35m'
readonly BLUE='\033[0;34m'
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly NC='\033[0m'
# Constants with safety checks
readonly HOME="${HOME:-$(getent passwd "$(whoami)" | cut -d: -f6)}"
readonly REPO_URL="https://github.com/CyphrRiot/ArchRiot/archive/refs/heads/master.tar.gz"
readonly INSTALL_DIR="$HOME/.local/share/archriot"
readonly INSTALLER_PATH="$INSTALL_DIR/install/archriot"
# Error handler
error_exit() {
echo -e "${RED}❌ Error: $1${NC}" >&2
exit 1
}
# Success message
success_msg() {
echo -e "${GREEN}✅ $1${NC}"
}
# Info message
info_msg() {
echo -e "${PURPLE}🔄 $1${NC}"
}
# Warning message
warn_msg() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
# Enhanced WiFi and network connectivity detection
check_network_connectivity() {
info_msg "Checking network connectivity..."
local connection_type=""
local interface_found=false
# Check for active network interfaces
while read -r interface; do
[[ -n "$interface" ]] || continue
interface_found=true
if [[ "$interface" =~ ^wl ]]; then
connection_type="WiFi"
info_msg "Found WiFi interface: $interface"
# Check WiFi connection status
if command -v iwconfig >/dev/null 2>&1; then
local essid=$(iwconfig "$interface" 2>/dev/null | grep -o 'ESSID:"[^"]*"' | cut -d'"' -f2)
if [[ -n "$essid" && "$essid" != "off/any" ]]; then
info_msg "Connected to WiFi network: $essid"
else
warn_msg "WiFi interface found but not connected to a network"
fi
fi
elif [[ "$interface" =~ ^en|^eth ]]; then
connection_type="Ethernet"
info_msg "Found Ethernet interface: $interface"
fi
done < <(ip route show default 2>/dev/null | awk '{print $5}' | sort -u)
# If no interfaces found via routing, check all available interfaces
if ! $interface_found; then
info_msg "No default route found, checking all network interfaces..."
while read -r line; do
local iface=$(echo "$line" | awk '{print $2}' | tr -d ':')
local status=$(echo "$line" | grep -o 'state [A-Z]*' | awk '{print $2}')
if [[ "$iface" != "lo" && "$status" == "UP" ]]; then
interface_found=true
if [[ "$iface" =~ ^wl ]]; then
connection_type="WiFi"
info_msg "Found active WiFi interface: $iface"
elif [[ "$iface" =~ ^en|^eth ]]; then
connection_type="Ethernet"
info_msg "Found active Ethernet interface: $iface"
fi
fi
done < <(ip link show 2>/dev/null | grep -E "^[0-9]+:")
fi
# Test actual internet connectivity with multiple fallbacks
info_msg "Testing internet connectivity..."
local test_urls=(
"8.8.8.8" # Google DNS
"1.1.1.1" # Cloudflare DNS
"github.com" # GitHub
"archlinux.org" # Arch Linux
)
local connectivity_test_passed=false
for url in "${test_urls[@]}"; do
if ping -c 1 -W 3 "$url" >/dev/null 2>&1; then
connectivity_test_passed=true
break
elif command -v curl >/dev/null 2>&1 && curl -s --connect-timeout 5 --max-time 10 "http://$url" >/dev/null 2>&1; then
connectivity_test_passed=true
break
elif command -v wget >/dev/null 2>&1 && wget -q --timeout=5 --tries=1 --spider "http://$url" >/dev/null 2>&1; then
connectivity_test_passed=true
break
fi
done
if ! $connectivity_test_passed; then
error_exit "No internet connectivity detected. Please check your network connection and try again."
fi
# Additional WiFi-specific checks
if [[ "$connection_type" == "WiFi" ]]; then
# Check signal strength if iwconfig is available
if command -v iwconfig >/dev/null 2>&1; then
local wifi_interface=$(ip route show default 2>/dev/null | awk '/^default.*wl/ {print $5}' | head -1)
if [[ -n "$wifi_interface" ]]; then
local signal_info=$(iwconfig "$wifi_interface" 2>/dev/null | grep -E "(Signal level|Link Quality)")
if [[ -n "$signal_info" ]]; then
info_msg "WiFi signal info: $(echo "$signal_info" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g')"
fi
fi
fi
# Check for common WiFi issues
if command -v networkctl >/dev/null 2>&1; then
local wifi_status=$(networkctl status 2>/dev/null | grep -E "(State:|WiFi|Wireless)")
if [[ -n "$wifi_status" ]]; then
info_msg "Network status: $(echo "$wifi_status" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g')"
fi
fi
fi
success_msg "Network connectivity verified ($connection_type connection)"
}
# Verify prerequisites
check_prerequisites() {
info_msg "Checking prerequisites..."
# Verify we have a home directory
[[ -n "$HOME" && -d "$HOME" ]] || error_exit "No valid home directory found"
# Check network connectivity first
check_network_connectivity
# Check if we have git
if ! command -v git >/dev/null 2>&1; then
info_msg "Installing git..."
# Check for package manager and sudo
command -v pacman >/dev/null 2>&1 || error_exit "pacman not found - are you on Arch Linux?"
command -v sudo >/dev/null 2>&1 || error_exit "sudo not found - please install git manually"
sudo pacman -Sy --noconfirm --needed git || error_exit "Failed to install git"
fi
# Test repository connectivity with HTTP request
info_msg "Testing repository connectivity..."
if ! curl -fsSL --connect-timeout 10 --max-time 30 --head "$REPO_URL" >/dev/null 2>&1; then
error_exit "Cannot connect to ArchRiot repository - check network connection"
fi
success_msg "Prerequisites verified"
}
# Download or update repository
setup_repository() {
info_msg "Setting up ArchRiot repository..."
if [[ -d "$INSTALL_DIR/.git" ]]; then
info_msg "Updating existing installation..."
# Safely update in subshell to avoid directory issues
(
cd "$INSTALL_DIR" || error_exit "Cannot access $INSTALL_DIR"
git fetch origin || error_exit "Failed to fetch updates"
git reset --hard origin/master || error_exit "Failed to update repository"
)
success_msg "Repository updated"
else
info_msg "Fresh installation..."
# Remove any existing directory and create parent
[[ -d "$INSTALL_DIR" ]] && rm -rf "$INSTALL_DIR"
mkdir -p "$(dirname "$INSTALL_DIR")" || error_exit "Cannot create directory structure"
# Download and extract release tarball (much faster than git clone)
info_msg "Downloading latest release..."
local temp_file="/tmp/archriot-latest.tar.gz"
# Download tarball
curl -fSL "$REPO_URL" -o "$temp_file" || error_exit "Failed to download repository"
# Extract to temporary directory first
local temp_dir="/tmp/archriot-extract"
mkdir -p "$temp_dir" || error_exit "Cannot create temp directory"
# Extract tarball (GitHub creates a subdirectory named ArchRiot-master)
tar -xzf "$temp_file" -C "$temp_dir" || error_exit "Failed to extract repository"
# Move from temp location to final location
mv "$temp_dir/ArchRiot-master" "$INSTALL_DIR" || error_exit "Failed to move extracted files"
# Cleanup
rm -f "$temp_file"
rm -rf "$temp_dir"
success_msg "Repository downloaded and extracted (no git history)"
fi
}
# Verify installer
verify_installer() {
info_msg "Verifying installer..."
[[ -f "$INSTALLER_PATH" ]] || error_exit "Installer binary not found at $INSTALLER_PATH"
if [[ ! -x "$INSTALLER_PATH" ]]; then
warn_msg "Installer is not executable; attempting to set executable bit"
chmod +x "$INSTALLER_PATH" || error_exit "Failed to set executable bit on installer"
[[ -x "$INSTALLER_PATH" ]] || error_exit "Installer binary is not executable after chmod"
fi
# Test installer responds
"$INSTALLER_PATH" --version >/dev/null 2>&1 || error_exit "Installer binary failed basic test"
success_msg "Installer verified"
}
# Main execution
main() {
echo -e "${BLUE}"
echo '▄ ▄▀█ █▀█ █▀▀ █ █ █▀█ █ █▀█ ▀█▀ ▄'
echo '▄ █▀█ █▀▄ █▄▄ █▀█ █▀▄ █ █▄█ █ ▄'
echo -e "${NC}"
echo
echo -e "${PURPLE}🎭 ArchRiot Setup${NC}"
echo -e "${PURPLE}=====================${NC}"
echo
# Parse mode flags (default: install). Show short usage when no flags.
MODE="install"
SHOW_USAGE=0
case "${1-}" in
"" )
SHOW_USAGE=1
;;
--help|-h)
echo -e "${YELLOW}Usage:${NC} setup.sh [--install | --upgrade | --help]"
echo " --install Run the installer (default)"
echo " --upgrade Run the upgrade flow"
echo " --help Show this message and exit"
exit 0
;;
--install)
MODE="install"
;;
--upgrade)
MODE="upgrade"
;;
*)
SHOW_USAGE=1
;;
esac
if [[ $SHOW_USAGE -eq 1 ]]; then
echo -e "${YELLOW}Usage:${NC} setup.sh [--install | --upgrade | --help]"
echo "Defaulting to --install..."
echo
fi
# Execute setup steps
check_prerequisites
setup_repository
verify_installer
echo
info_msg "Starting ArchRiot installer..."
echo
# Hand off to the real installer (pass through flags when supported; fallback safe)
if "$INSTALLER_PATH" --help >/dev/null 2>&1; then
if [[ "$MODE" == "upgrade" ]] && "$INSTALLER_PATH" --help 2>/dev/null | grep -q -- "--upgrade"; then
exec "$INSTALLER_PATH" --upgrade
elif [[ "$MODE" == "install" ]] && "$INSTALLER_PATH" --help 2>/dev/null | grep -q -- "--install"; then
exec "$INSTALLER_PATH" --install
else
if [[ "$MODE" == "upgrade" ]]; then
warn_msg "Installer does not support --upgrade; running default installer"
fi
exec "$INSTALLER_PATH"
fi
else
# Very old installer without --help: run without flags
exec "$INSTALLER_PATH"
fi
}
# Run main function
main "$@"