-
Notifications
You must be signed in to change notification settings - Fork 1
/
mihomobackup.sh
129 lines (121 loc) · 4.75 KB
/
mihomobackup.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
#!/bin/bash
# Define a lock file
LOCKFILE="/tmp/mihomotproxy.lock"
# Function to remove the lock file on exit
cleanup() {
rm -f "$LOCKFILE"
exit
}
# Check if the lock file exists
if [ -e "$LOCKFILE" ]; then
echo "Script is already running. Exiting..."
exit 1
else
# Create a lock file
touch "$LOCKFILE"
trap cleanup EXIT
fi
cd /tmp || { echo "Failed to change directory to /tmp"; cleanup; }
echo "Script Version: 1.8"
sleep 3
clear
while true; do
clear
echo "================================================"
echo " Auto Script | MihomoTProxy "
echo "================================================"
echo ""
echo " [*] Auto Script By : RizkiKotet [*]"
echo ""
echo "================================================"
echo ""
echo " >> MENU BACKUP"
echo " > 1 - Backup Full Config"
echo ""
echo " >> MENU RESTORE"
echo " > 2 - Restore Backup Full Config"
echo ""
echo " >> MENU CONFIG"
echo " > 3 - Download Full Backup Config By RTA-WRT"
echo ""
echo "================================================"
echo " > X - Exit Script"
echo "================================================"
read -r choice
case $choice in
1)
echo "Backup Full Config..."
sleep 2
current_time=$(date +"%Y-%m-%d_%H-%M-%S")
output_tar_gz="/root/backup_config_mihomo_${current_time}.tar.gz"
files_to_backup=(
"/etc/mihomo/mixin.yaml"
"/etc/mihomo/profiles"
"/etc/mihomo/run"
"/etc/config/mihomo"
)
echo "Archiving and compressing files and folders..."
tar -czvf "$output_tar_gz" "${files_to_backup[@]}"
if [ $? -eq 0 ]; then
echo "Files successfully archived into $output_tar_gz"
else
echo "Failed to create the archive"
fi
sleep 3
;;
2)
echo "Restore Backup Full Config..."
read -p "Enter the path to the backup archive (e.g., /tmp/backup.tar.gz): " backup_file
if [ -f "$backup_file" ]; then
echo "Restoring files..."
tar -xzvf "$backup_file" -C / --overwrite
if [ $? -eq 0 ]; then
echo "Backup successfully restored and files overwritten."
else
echo "Failed to restore from the backup."
fi
else
echo "Backup file does not exist: $backup_file"
fi
sleep 3
;;
3)
echo "Download Full Backup Config By RTA-WRT"
sleep 2
wget -O /tmp/main.zip https://github.com/rtaserver/Config-Open-ClashMeta/archive/refs/heads/main.zip
unzip -o /tmp/main.zip -d /tmp # Use -o to overwrite existing files
rm -rf /tmp/main.zip
cd /tmp/Config-Open-ClashMeta-main || { echo "Failed to change directory"; cleanup; }
mv -f config/Country.mmdb /etc/mihomo/run/Country.mmdb && chmod +x /etc/mihomo/run/Country.mmdb
mv -f config/GeoIP.dat /etc/mihomo/run/GeoIP.dat && chmod +x /etc/mihomo/run/GeoIP.dat
mv -f config/GeoSite.dat /etc/mihomo/run/GeoSite.dat && chmod +x /etc/mihomo/run/GeoSite.dat
mv -fT config/proxy_provider /etc/mihomo/run/proxy_provider && chmod +x /etc/mihomo/run/proxy_provider/*
mv -fT config/rule_provider /etc/mihomo/run/rule_provider && chmod +x /etc/mihomo/run/rule_provider/*
mv -f configmihomo/cache.db /etc/mihomo/run/cache.db && chmod +x /etc/mihomo/run/cache.db
mv -f configmihomo/config-wrt.yaml /etc/mihomo/profiles/config-wrt.yaml && chmod +x /etc/mihomo/profiles/config-wrt.yaml
mv -f configmihomo/config.yaml /etc/mihomo/run/config.yaml && chmod +x /etc/mihomo/run/config.yaml
mv -f configmihomo/mihomo /etc/config/mihomo
rm -rf /tmp/Config-Open-ClashMeta-main
clear
echo "Download Dashboard Yacd"
sleep 2
cd /tmp
wget -O /tmp/gh-pages.zip https://github.com/MetaCubeX/Yacd-meta/archive/refs/heads/gh-pages.zip
unzip -o /tmp/gh-pages.zip -d /tmp # Use -o to overwrite existing files
rm -rf /tmp/gh-pages.zip
mv -fT /tmp/Yacd-meta-gh-pages /etc/mihomo/run/ui/dashboard
echo "Installation completed successfully!"
sleep 3
;;
x|X)
echo "Exiting..."
cleanup
;;
*)
echo "Invalid option selected!"
;;
esac
echo "Returning to the menu..."
cd /tmp || { echo "Failed to change directory to /tmp"; cleanup; }
sleep 2
done