forked from Xentrk/x3mRouting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install_x3mRouting.sh
89 lines (80 loc) · 3.12 KB
/
Install_x3mRouting.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
#!/bin/sh
####################################################################################################
# Script: Install_x3mRouting.sh
# VERSION=2.1.0
# Author: Xentrk
# Date: 6-August-2020
#
#####################################################################################################
# Description:
# Create nvram LAN client files based on the routing configuration defined in the file
# /jffs/configs/x3mRouting_lan_client_rules
#
#####################################################################################################
GIT_REPO="x3mRouting"
BRANCH="master"
# Change branch to master after merge
GITHUB_DIR="https://raw.githubusercontent.com/Xentrk/$GIT_REPO/$BRANCH"
Chk_Entware() {
# ARGS [wait attempts] [specific_entware_utility]
READY="1" # Assume Entware Utilities are NOT available
ENTWARE_UTILITY="" # Specific Entware utility to search for
MAX_TRIES="30"
if [ -n "$2" ] && [ "$2" -eq "$2" ] 2>/dev/null; then
MAX_TRIES="$2"
elif [ -z "$2" ] && [ "$1" -eq "$1" ] 2>/dev/null; then
MAX_TRIES="$1"
fi
if [ -n "$1" ] && ! [ "$1" -eq "$1" ] 2>/dev/null; then
ENTWARE_UTILITY="$1"
fi
# Wait up to (default) 30 seconds to see if Entware utilities available.....
TRIES="0"
while [ "$TRIES" -lt "$MAX_TRIES" ]; do
if [ -f "/opt/bin/opkg" ]; then
if [ -n "$ENTWARE_UTILITY" ]; then # Specific Entware utility installed?
if [ -n "$(opkg list-installed "$ENTWARE_UTILITY")" ]; then
READY="0" # Specific Entware utility found
else
# Not all Entware utilities exists as a stand-alone package e.g. 'find' is in package 'findutils'
if [ -d /opt ] && [ -n "$(find /opt/ -name "$ENTWARE_UTILITY")" ]; then
READY="0" # Specific Entware utility found
fi
fi
else
READY="0" # Entware utilities ready
fi
break
fi
sleep 1
logger -st "($(basename "$0"))" "$$ Entware $ENTWARE_UTILITY not available - wait time $((MAX_TRIES - TRIES - 1)) secs left"
TRIES=$((TRIES + 1))
done
return "$READY"
}
Chk_Entware 30
if [ "$READY" -eq 1 ]; then
echo "You must first install Entware before proceeding"
printf 'Exiting %s\n' "$(basename "$0")"
exit 1
fi
while true; do
echo "Downloading, please wait patiently..."
mkdir -p /jffs/addons/x3mRouting
/usr/sbin/curl -s --retry 3 $GITHUB_DIR/x3mRouting_Menu.sh -o /jffs/addons/x3mRouting/x3mRouting_Menu.sh
chmod 755 /jffs/addons/x3mRouting/x3mRouting_Menu.sh
# Remove old link or alias if exist
if [ "$(/opt/bin/find /opt/bin/ -maxdepth 1 -type l -ls | grep -c "/opt/bin/x3mRouting -> /jffs/scripts/x3mRouting/x3mRouting.sh")" -eq 0 ]; then
if [ -d "/opt/bin" ] && [ "$(/opt/bin/find /opt/bin/ -maxdepth 1 -type l -ls | grep -c "/opt/bin/x3mRouting -> /jffs/addons/x3mRouting/x3mRouting_Menu.sh")" -eq 0 ]; then
if [ -s "/opt/bin/x3mRouting" ]; then # old alias situation
rm -rf /opt/bin/x3mRouting 2>/dev/null
fi
else
rm -rf /opt/bin/x3mRouting 2>/dev/null
fi
fi
rm -rf /opt/bin/x3mMenu 2>/dev/null
ln -s "/jffs/addons/x3mRouting/x3mRouting_Menu.sh" "/opt/bin/x3mMenu"
x3mMenu
exit 0
done