This repository was archived by the owner on May 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy paththrone-linux.sh
More file actions
executable file
·541 lines (454 loc) · 16.8 KB
/
Copy paththrone-linux.sh
File metadata and controls
executable file
·541 lines (454 loc) · 16.8 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
#!/bin/bash
set -euo pipefail
# Configuration
THRONE_URL="https://api.github.com/repos/throneproj/Throne/releases/latest"
THRONE_FILE_NAME="Throne"
THRONE_DESKTOP_FILE="$HOME/.local/share/applications/throne.desktop"
CURL_TIMEOUT=15
TMPDIR=$(mktemp -d)
# Hotspot Configuration
SSID="ohmythrone"
TUN_IFACE="nekoray-tun"
NFT_TABLE="throne_hotspot"
REQUIRED_INET_TABLE="sing-box"
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
BOLD='\033[1m'
# Display banner
show_banner() {
echo -e "${YELLOW}"
cat <<EOF
████████╗██╗ ██╗██████╗ ██████╗ ███╗ ██╗███████╗
╚══██╔══╝██║ ██║██╔══██╗██╔═══██╗████╗ ██║██╔════╝
██║ ███████║██████╔╝██║ ██║██╔██╗ ██║█████╗
██║ ██╔══██║██╔══██╗██║ ██║██║╚██╗██║██╔══╝
██║ ██║ ██║██║ ██║╚██████╔╝██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝
██╗███╗ ██╗███████╗████████╗ █████╗ ██╗ ██╗ ███████╗██████╗
██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██║ ██║ ██╔════╝██╔══██╗
██║██╔██╗ ██║███████╗ ██║ ███████║██║ ██║ █████╗ ██████╔╝
██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║ ██║ ██╔══╝ ██╔══██╗
██║██║ ╚████║███████║ ██║ ██║ ██║███████╗███████╗███████╗██║ ██║
╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝
EOF
echo -e "${NC}"
echo -e "${BLUE}Throne Installer for macOS${NC}\n\n\n"
}
# Show main menu
show_menu() {
echo -e "${YELLOW}Please select an option:${NC}"
echo "1) Install Throne"
echo "2) Backup configuration"
echo "3) Restore configuration"
echo "4) Uninstall"
echo "5) Enable Hotspot"
echo "6) Disable Hotspot"
echo "7) Exit"
echo
}
# Function to get app name from user
get_app_name() {
read -rp "👉 Enter which app (nekoray, throne): " APP_NAME
APP_NAME=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]')
if [[ "$APP_NAME" != "nekoray" && "$APP_NAME" != "throne" ]]; then
echo -e "${RED}Invalid app name. Only 'nekoray' or 'throne' allowed.${NC}"
exit 1
fi
}
# Safe command runner for hotspot operations
run_cmd() {
local dry_run=${1:-false}
shift
if $dry_run; then
echo -e "${BLUE}→ $*${NC}"
else
eval "$@"
fi
}
# Function to check for existing installations
check_installations() {
local app_name=${1:-"throne"}
local found=false
# Set app variants based on app name
if [[ "$app_name" == "throne" ]]; then
local app_variants=("throne" "Throne")
else
local app_variants=("nekoray" "NekoRay")
fi
# Check package installations
if dpkg -l | grep -q "$app_name" 2>/dev/null || rpm -q "$app_name" 2>/dev/null; then
echo -e "${YELLOW}$app_name package is installed.${NC}"
found=true
fi
# Check system locations
for variant in "${app_variants[@]}"; do
local system_locations=(
"/opt/$variant"
"/usr/share/applications/$variant.desktop"
"$HOME/.local/share/applications/$variant.desktop"
"$HOME/.config/$variant"
)
for location in "${system_locations[@]}"; do
if [ -d "$location" ] || [ -f "$location" ]; then
echo -e "${YELLOW}Found system installation: $location${NC}"
found=true
fi
done
done
# Return result (0 = found, 1 = not found)
if [ "$found" = true ]; then
return 0
else
return 1
fi
}
# Install function
install_app() {
echo -e "${BLUE}=== INSTALLATION ===${NC}\n"
# Check for existing installations
echo "Checking for existing Throne installations..."
if check_installations "throne" || check_installations "nekoray"; then
echo -e "${YELLOW}Please uninstall existing Throne or NekoRay installations first using option 4 (Uninstall).${NC}\n"
return 0
fi
echo -e "${GREEN}✅ No existing installations found. Proceeding with installation...${NC}\n"
# Detect Linux distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
else
echo -e "${RED}Cannot detect Linux distribution.${NC}"
exit 1
fi
# Determine package type and manager based on distribution
case "$DISTRO" in
ubuntu|debian|linuxmint|pop)
PACKAGE_TYPE="deb"
PACKAGE_MANAGER="dpkg"
INSTALL_CMD="sudo dpkg -i"
FIX_DEPS_CMD="sudo apt-get install -f -y"
PACKAGE_PATTERN="Throne.*debian.*\.deb"
;;
fedora|rhel|centos|rocky|almalinux)
PACKAGE_TYPE="rpm"
PACKAGE_MANAGER="rpm"
INSTALL_CMD="sudo rpm -i"
FIX_DEPS_CMD="sudo dnf install -y"
PACKAGE_PATTERN="Throne.*\.el.*\.rpm"
;;
*)
echo -e "${RED}Unsupported distribution: $DISTRO${NC}"
echo -e "${RED}Supported distributions: Ubuntu, Debian, Fedora, RHEL, CentOS${NC}"
exit 1
;;
esac
# Check for required commands
for cmd in curl $PACKAGE_MANAGER; do
if ! command -v $cmd &> /dev/null; then
echo -e "${RED}$cmd is not installed.${NC}"
echo -e "${RED}Install $cmd in your system.${NC}"
case "$DISTRO" in
ubuntu|debian|linuxmint|pop)
echo -e "${RED}For example: sudo apt install $cmd${NC}"
;;
fedora|rhel|centos|rocky|almalinux)
echo -e "${RED}For example: sudo dnf install $cmd${NC}"
;;
esac
exit 1
fi
done
echo -e "Fetching latest Throne release information..."
# Get the latest release info and find the appropriate package URL
RELEASE_INFO=$(curl --max-time $CURL_TIMEOUT -s $THRONE_URL)
PACKAGE_URL=$(echo "$RELEASE_INFO" | grep -E "browser_download_url.*$PACKAGE_PATTERN" | head -1 | cut -d '"' -f 4)
if [ -z "$PACKAGE_URL" ]; then
echo -e "${RED}Could not find $PACKAGE_TYPE package in the latest release.${NC}"
echo -e "${RED}Available packages:${NC}"
echo "$RELEASE_INFO" | grep "browser_download_url" | cut -d '"' -f 4 | sed 's/.*\///g'
exit 1
fi
PACKAGE_NAME=$(basename "$PACKAGE_URL")
echo -e "Downloading $PACKAGE_NAME..."
# Download the package
curl --max-time $CURL_TIMEOUT -L --progress-bar -o "$TMPDIR/$PACKAGE_NAME" "$PACKAGE_URL"
echo -e "Installing Throne $PACKAGE_TYPE package..."
# Install the package
if $INSTALL_CMD "$TMPDIR/$PACKAGE_NAME"; then
echo -e "${GREEN}✅ Throne installed successfully!${NC}"
else
echo -e "${YELLOW}Installation completed with some warnings. Fixing dependencies...${NC}"
$FIX_DEPS_CMD
fi
# Clean up
rm "$TMPDIR/$PACKAGE_NAME"
echo -e "\n${GREEN}✅ Done! Throne has been installed system-wide. You can find it in your applications menu!${NC}\n"
}
# Backup function
backup_config() {
echo -e "${BLUE}=== BACKUP CONFIGURATION ===${NC}\n"
get_app_name
CONFIG_DIR=""
# Check for both old NekoRay and new Throne configs
if [[ "$APP_NAME" == "nekoray" ]]; then
# Support both old and new paths for NekoRay
if [ -d "$HOME/.config/nekoray/config" ]; then
CONFIG_DIR="$HOME/.config/nekoray/config"
fi
elif [[ "$APP_NAME" == "throne" ]]; then
if [ -d "$HOME/.config/Throne/config" ]; then
CONFIG_DIR="$HOME/.config/Throne/config"
fi
fi
BACKUP_NAME="${APP_NAME}-backup-$(date +%Y-%m-%d).zip"
DEST_DIR="$(pwd)"
if [ ! -d "$CONFIG_DIR" ]; then
echo -e "${RED}Config directory does not exist: $CONFIG_DIR${NC}"
exit 1
fi
if ! command -v zip &> /dev/null; then
echo -e "${RED}Missing 'zip'. Install it with:${NC}"
echo -e "${RED} Debian/Ubuntu: sudo apt install zip${NC}"
echo -e "${RED} Fedora: sudo dnf install zip${NC}"
echo -e "${RED} Arch: sudo pacman -S zip${NC}"
exit 1
fi
echo "📦 Compressing config ..."
echo "Compressing config from $CONFIG_DIR..."
(cd "$CONFIG_DIR" && zip -rq "$DEST_DIR/$BACKUP_NAME" .)
echo -e "${GREEN}✅ Backup created:${NC}"
echo -e "${GREEN}$DEST_DIR/$BACKUP_NAME${NC}\n"
}
# Restore function
restore_config() {
echo -e "${BLUE}=== RESTORE CONFIGURATION ===${NC}\n"
read -rp "Enter the path to the backup .zip file: " ZIP_FILE
if [[ -z "$ZIP_FILE" ]]; then
echo -e "${RED}Please provide the path to the backup .zip file.${NC}"
exit 1
fi
if [[ ! -f "$ZIP_FILE" ]]; then
echo -e "${RED}File not found: $ZIP_FILE${NC}"
exit 1
fi
get_app_name
RESTORE_DIR=""
# Determine restore directory based on app name and what's installed
if [[ "$APP_NAME" == "nekoray" ]]; then
# For NekoRay, check if new Throne is installed and use that, otherwise use old path
if [ -d "$HOME/.config/nekoray/" ]; then
RESTORE_DIR="$HOME/.config/nekoray/config"
fi
elif [[ "$APP_NAME" == "throne" ]]; then
# For Throne, use the new path
if [ -d "$HOME/.config/Throne/" ]; then
RESTORE_DIR="$HOME/.config/Throne/config"
fi
fi
if ! command -v unzip &> /dev/null; then
echo -e "${RED}'unzip' is required. Install it with:${NC}"
echo -e "${RED} Debian/Ubuntu: sudo apt install unzip${NC}"
echo -e "${RED} Fedora: sudo dnf install unzip${NC}"
echo -e "${RED} Arch: sudo pacman -S unzip${NC}"
exit 1
fi
if [[ -d "$RESTORE_DIR" ]]; then
echo "Removing existing config: $RESTORE_DIR"
rm -rf "$RESTORE_DIR"
fi
mkdir -p "$RESTORE_DIR"
echo "📦 Restoring backup to: $RESTORE_DIR"
unzip -q "$ZIP_FILE" -d "$RESTORE_DIR"
echo -e "${GREEN}✅ Restore complete!${NC}\n"
}
# Uninstall function
uninstall_app() {
echo -e "${BLUE}=== UNINSTALL ===${NC}\n"
get_app_name
echo -e "\nUninstalling $APP_NAME..."
# Check if any installations exist
if ! check_installations "$APP_NAME"; then
echo -e "\n${YELLOW}⚠ No $APP_NAME installations found on this system.${NC}\n"
return 0
fi
# Remove installations
if [[ "$APP_NAME" == "throne" ]]; then
local app_variants=("throne" "Throne")
else
local app_variants=("nekoray" "NekoRay")
fi
# Remove package installations
if dpkg -l | grep -q "$APP_NAME" 2>/dev/null; then
echo "Removing $APP_NAME .deb package..."
sudo dpkg -r "$APP_NAME"
elif rpm -q "$APP_NAME" 2>/dev/null; then
echo "Removing $APP_NAME .rpm package..."
sudo rpm -e "$APP_NAME"
fi
# Remove installations
echo "Checking for $APP_NAME installations..."
for variant in "${app_variants[@]}"; do
local user_locations=(
"/opt/$variant"
"/usr/share/applications/$variant.desktop"
"$HOME/.local/share/applications/$variant.desktop"
"$HOME/.config/$variant"
)
for location in "${user_locations[@]}"; do
if [ -d "$location" ] || [ -f "$location" ]; then
sudo rm -rf "$location"
fi
done
done
# Provide feedback
echo -e "\n${GREEN}✅ $APP_NAME installations have been removed.${NC}\n"
}
# Enable hotspot function
enable_hotspot() {
echo -e "${BLUE}=== ENABLE HOTSPOT ===${NC}\n"
echo -e "${GREEN}🚀 Starting Throne Hotspot...${NC}"
# Parse dry-run option
local dry_run=false
read -rp "Run in dry-run mode? (y/N): " dry_choice
if [[ "$dry_choice" =~ ^[Yy]$ ]]; then
dry_run=true
echo -e "${YELLOW}🧪 Running in dry-run mode — no changes will be made.${NC}"
fi
# Check required commands
for cmd in nmcli iw nft; do
if ! command -v "$cmd" &>/dev/null; then
echo -e "${RED}❌ '$cmd' command not found. Please install it.${NC}"
case "$cmd" in
nmcli)
echo -e " Debian/Ubuntu: sudo apt install network-manager"
echo -e " Fedora: sudo dnf install NetworkManager"
echo -e " Arch: sudo pacman -S networkmanager"
;;
iw)
echo -e " Debian/Ubuntu: sudo apt install iw"
echo -e " Fedora: sudo dnf install iw"
echo -e " Arch: sudo pacman -S iw"
;;
nft)
echo -e " Debian/Ubuntu: sudo apt install nftables"
echo -e " Fedora: sudo dnf install nftables"
echo -e " Arch: sudo pacman -S nftables"
;;
esac
exit 1
fi
done
# Detect Wi-Fi interface
HOTSPOT_IFACE=$(nmcli device status | awk '$2 == "wifi" {print $1; exit}')
if [ -z "$HOTSPOT_IFACE" ]; then
echo -e "${RED}❌ No Wi-Fi interface found. Exiting.${NC}"
exit 1
fi
echo -e "${GREEN}✅ Wi-Fi interface: ${BOLD}$HOTSPOT_IFACE${NC}"
# Check required nftables table
if ! sudo nft list table inet "$REQUIRED_INET_TABLE" &>/dev/null; then
echo -e "${RED}❌ Missing 'inet $REQUIRED_INET_TABLE' nftables table.${NC}"
echo -e " Please enable 'Tun Mode' in Throne/NekoRay GUI settings."
exit 1
fi
echo -e "${GREEN}✅ Enabling Wi-Fi...${NC}"
run_cmd $dry_run "nmcli radio wifi on"
# Check if a Wi-Fi hotspot is already active
if iw dev "$HOTSPOT_IFACE" info 2>/dev/null | grep -q "type AP"; then
echo -e "${YELLOW}⚠ A Wi-Fi hotspot is already active on $HOTSPOT_IFACE. Skipping creation.${NC}"
return 0
fi
echo -e "${GREEN}✅ Starting hotspot...${NC}"
# Get password from user
while true; do
read -rsp $'\n🔒 Enter hotspot password (min 8 chars): ' PASSWORD
echo
if [ ${#PASSWORD} -ge 8 ]; then
break
else
echo -e "${RED}❌ Password must be at least 8 characters.${NC}"
fi
done
if ! $dry_run && ! nmcli dev wifi hotspot ifname "$HOTSPOT_IFACE" ssid "$SSID" password "$PASSWORD" >/dev/null 2>&1; then
echo -e "${RED}❌ Failed to start hotspot — maybe AP mode is unsupported.${NC}"
exit 1
fi
if $dry_run; then
echo -e "${BLUE}→ nmcli dev wifi hotspot ifname \"$HOTSPOT_IFACE\" ssid \"$SSID\" password \"********\"${NC}"
fi
echo -e "${GREEN}✅ Setting up nftables rules...${NC}"
run_cmd $dry_run "sudo nft delete table ip $NFT_TABLE 2>/dev/null || true"
run_cmd $dry_run "sudo nft add table ip $NFT_TABLE"
run_cmd $dry_run "sudo nft add chain ip $NFT_TABLE postrouting { type nat hook postrouting priority srcnat\; policy accept\; }"
run_cmd $dry_run "sudo nft add rule ip $NFT_TABLE postrouting oifname \"$TUN_IFACE\" masquerade"
run_cmd $dry_run "sudo nft add chain ip $NFT_TABLE forward { type filter hook forward priority filter\; policy accept\; }"
run_cmd $dry_run "sudo nft add rule ip $NFT_TABLE forward iifname \"$HOTSPOT_IFACE\" oifname \"$TUN_IFACE\" accept"
run_cmd $dry_run "sudo nft add rule ip $NFT_TABLE forward iifname \"$TUN_IFACE\" oifname \"$HOTSPOT_IFACE\" ct state established,related accept"
echo -e "\n${BOLD}${GREEN}✔ Hotspot is ready and running!${NC}\n"
echo "SSID: $SSID"
echo "Password: $PASSWORD"
echo
}
# Disable hotspot function
disable_hotspot() {
echo -e "${BLUE}=== DISABLE HOTSPOT ===${NC}\n"
# Parse dry-run option
local dry_run=false
read -rp "Run in dry-run mode? (y/N): " dry_choice
if [[ "$dry_choice" =~ ^[Yy]$ ]]; then
dry_run=true
echo -e "${YELLOW}🧪 Running in dry-run mode — no changes will be made.${NC}"
fi
echo -e "${GREEN}✅ Stopping hotspot...${NC}"
run_cmd $dry_run "nmcli connection down Hotspot 2>/dev/null || true"
run_cmd $dry_run "nmcli connection delete Hotspot 2>/dev/null || true"
echo -e "${GREEN}✅ Removing nftables table...${NC}"
run_cmd $dry_run "sudo nft delete table ip $NFT_TABLE 2>/dev/null || true"
echo -e "\n${BOLD}${GREEN}✔ Hotspot stopped and nftables rules removed.${NC}\n"
}
# Main function
main() {
show_banner
while true; do
show_menu
read -rp "Enter your choice (1-7): " choice
echo
case $choice in
1)
install_app
;;
2)
backup_config
;;
3)
restore_config
;;
4)
uninstall_app
;;
5)
enable_hotspot
;;
6)
disable_hotspot
;;
7)
echo -e "${GREEN}Goodbye!${NC}"
exit 0
;;
*)
echo -e "${RED}Invalid choice. Please select 1-7.${NC}\n"
;;
esac
read -rp "Press Enter to continue..."
echo
done
}
# Cleanup on exit
trap 'rm -rf "$TMPDIR"' EXIT
# Run main function
main