-
Notifications
You must be signed in to change notification settings - Fork 0
/
aegis-install.sh
147 lines (134 loc) · 6.03 KB
/
aegis-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
#!/bin/sh
AEGIS_REPO='https://raw.githubusercontent.com/bolemo/aegis/stable'
AEGIS_SCP_URL="$AEGIS_REPO/aegis"
AEGIS_VER_URL="$AEGIS_REPO/version"
AEGIS_SRC_URL="$AEGIS_REPO/aegis.sources"
AEGIS_TWL_URL="$AEGIS_REPO/aegis.vpn-whitelist"
SELF_PATH="$(pwd -P)"
WGET_PATH="/usr/bin/wget"
RT_MOD="$(cat /module_name)"
ifconfig ppp0 && WAN_IF='ppp0' || WAN_IF="$(/bin/nvram get wan_ifname)"
_dlinfo() { # to know how many people are downloading this script
AUID="$(/usr/bin/md5sum /tmp/sn-setted|/usr/bin/cut -d' ' -f1)"
TITLE="$1" IP="$(/usr/bin/curl --interface $WAN_IF 'ifconfig.me/ip')" REF1="$(cat /module_name)"; [ "$CHOICE" ] && REF2=ext || REF2=int
/usr/bin/curl -H 'Content-Type: application/json' -H "Authorization: Bearer 1a3mmidk3rg2j1xv6t82ak65up1yht5dambypyh1ze7xhbw7941r" -X POST "https://aegis.goatcounter.com/api/v0/count" \
--data '{"hits": [{"path": "/install/'$TITLE'", "title": "'$TITLE'", "ip": "'$IP'", "ref": "'$RT_MOD/$REF2'", "session": "'$AUID'"}, {"path": "/user/'$AUID'", "title": "'$RT_MOD/$REF2'", "ip": "'$IP'", "ref": "'$RT_MOD/$REF2'", "session": "'$AUID'"}]}'
} >/dev/null 2>&1
ask_yn() {
echo -ne "$1 [y/n] "
case "$(i=0;while [ $i -lt 2 ];do i=$((i+1));read -p "" yn </dev/tty;[ -n "$yn" ] && echo "$yn" && break;done)" in
Y|y|yes|Yes|YES) return 0 ;;
*) return 1 ;;
esac
}
[ -z ${1+x} ] && ASK=true || ASK=false
if $ASK; then
i=1; for var in $(ls /tmp/mnt); do eval var$i="'$var'"; i=$((i+1)); done;
until [ "$A" ] && $(echo "$A" | grep -qE '^[0-9]?$') && [ "$A" -ge 0 ] && [ "$A" -lt "$i" ]; do
echo "Where do you want to install aegis?"
echo ' 0 - router internal memory (rootfs)'
j=1; while [ "$j" -ne "$i" ]; do
echo " $j - external drive: /mnt/$(eval echo "\$var$j")"
j=$((j+1))
done
echo " c - cancel installation"
echo -n 'Your choice: '
A="$(i=0;while [ $i -lt 2 ];do i=$((i+1));read -p "" yn </dev/tty;[ -n "$yn" ] && echo "$yn" && break;done)"
[ "$A" = 'c' ] && exit 0
done;
CHOICE="$(eval echo "\$var$A")";
else CHOICE="$1"; fi
if [ "$CHOICE" ]; then
BASE_DIR="/tmp/mnt/$CHOICE"
echo "aegis will be installed on external drive $BASE_DIR"
else
BASE_DIR="/root"
echo "aegis will be installed on internal memory $BASE_DIR"
fi
if ! test -d $BASE_DIR; then >&2 echo "$BASE_DIR does not exist!"; exit 1; fi
echo "Creating directory (if not already existing): /opt/scripts"
if ! test -d "/opt/scripts"; then mkdir -p "/opt/scripts"; fi
echo "Creating directory (if not already existing): $BASE_DIR/bolemo"
if ! test -d "$BASE_DIR/bolemo"; then mkdir "$BASE_DIR/bolemo"; fi
echo "Creating symlink (if not already existing): /opt/bolemo"
if ! test -L "/opt/bolemo" || ! test -d "/opt/bolemo"; then ln -sfn "$BASE_DIR/bolemo" "/opt/bolemo"; fi
echo "Creating subdirectories in bolemo: scripts, etc"
if ! test -d "$BASE_DIR/bolemo/scripts"; then mkdir "$BASE_DIR/bolemo/scripts"; fi
if ! test -d "$BASE_DIR/bolemo/etc"; then mkdir "$BASE_DIR/bolemo/etc"; fi
if ! test -d "$BASE_DIR/bolemo/www"; then mkdir "$BASE_DIR/bolemo/www"; fi
echo "Downloading and installing aegis..."
VERS="$($WGET_PATH -qO- --no-check-certificate "$AEGIS_VER_URL")"
_dlinfo "$VERS" &
if [ "$VERS" ] && $WGET_PATH -qO '/tmp/aegis_dl.tmp' --no-check-certificate "$AEGIS_SCP_URL"; then
/bin/sed -i 's/^[[:space:]]*// ; 1!{/^#/d;s/#[^"\}'\'']*$//;} ; s/[[:space:]]*$// ; /^$/d ; s/ *\([^"'\'']*\)$/ \1/ ; s/^\(\([^"'\'' ]\+ \)*\) \+/\1/' '/tmp/aegis_dl.tmp'
/bin/mv '/tmp/aegis_dl.tmp' '/opt/bolemo/scripts/aegis'
chmod +x "/opt/bolemo/scripts/aegis"
else >&2 echo 'Could not download aegis!'; exit 1
fi
if [ -s "/opt/bolemo/etc/aegis.sources" ]
then echo "An aegis sources file already exists, keeping it."
else
echo "Downloading aegis default sources file..."
$WGET_PATH -qO- --no-check-certificate "$AEGIS_SRC_URL" >/opt/bolemo/etc/aegis.sources
fi
if [ -e "/opt/bolemo/etc/aegis.vpn-whitelist" ]
then echo "An aegis VPN whitelist file already exists, keeping it."
else
echo "Downloading aegis default VPN whitelist file..."
$WGET_PATH -qO- --no-check-certificate "$AEGIS_TWL_URL" >/opt/bolemo/etc/aegis.vpn-whitelist
fi
# symlink
command -v aegis >/dev/null || ln -s /opt/bolemo/scripts/aegis /usr/bin/aegis
# iprange
if ! $ASK; then case "$2" in
3) ASK_ENT=true; ASK_INT=true ;;
2) ASK_ENT=true; ASK_INT=false ;;
1) ASK_ENT=false; ASK_INT=true ;;
*) ASK_ENT=false; ASK_INT=false ;;
esac; fi
if command -v iprange >/dev/null; then
echo 'iprange is installed.'
_ASK_ROOTFS=false
else
echo 'iprange is not installed.'
if command -v /opt/bin/opkg >/dev/null; then
$ASK && { ask_yn 'It appears you have Entware, do you want to install it through Entware?' && ASK_ENT=true || ASK_ENT=false; }
if $ASK_ENT; then _ASK_ROOTFS=false
echo "Downloading and installing iprange..."
IPRANGE_IPK_URL="$AEGIS_REPO/iprange_1.0.4-1_cortex-a15-3x.ipk"
if $WGET_PATH -qO '/tmp/iprange.ipk' --no-check-certificate "$IPRANGE_IPK_URL"; then
/opt/bin/opkg install '/tmp/iprange.ipk'
/bin/rm -f '/tmp/iprange.ipk'
else
>&2 echo 'Could not download iprange!'
fi
else _ASK_ROOTFS=true
fi
else _ASK_ROOTFS=true
fi
if $_ASK_ROOTFS; then
case "$RT_MOD" in
'R7800') IPRANGE_IPK_URL="$AEGIS_REPO/iprange_1.0.4-1_ipq806x.ipk" ;;
'R9000') IPRANGE_IPK_URL="$AEGIS_REPO/iprange_1.0.4-1_r9000.ipk" ;;
*) IPRANGE_IPK_URL=;;
esac
if [ "$IPRANGE_IPK_URL" ]; then
$ASK && { ask_yn 'Do you want to install iprange into router internal memory (/usr/bin)?' && ASK_INT=true || ASK_INT=false; }
if $ASK_INT; then
echo "Downloading and installing iprange..."
if $WGET_PATH -qO '/tmp/iprange.ipk' --no-check-certificate "$IPRANGE_IPK_URL"; then
/bin/opkg install '/tmp/iprange.ipk'
/bin/rm -f '/tmp/iprange.ipk'
else
>&2 echo 'Could not download iprange!'
fi
else
echo 'Skipping installation of iprange'
fi
else
echo 'The iprange versions available from this installer are not supported on this device.'
fi
fi
fi
echo "Done!"
exit 0