-
Notifications
You must be signed in to change notification settings - Fork 3
/
shadowsocks-rust_bin_installer.sh@mipsel
134 lines (122 loc) · 4.03 KB
/
shadowsocks-rust_bin_installer.sh@mipsel
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
#!/bin/bash
arch_shadowsocks_rust="mipsel"
kernel_shadowsocks_rust="linux"
system_shadowsocks_rust="musl"
arch_v2ray_plugin="mips"
kernel_v2ray_plugin="linux"
arch_version_v2ray_plugin="le_sf"
path_install_to="/usr/bin"
guess_package_manager(){
local res
local package_managers="apt opkg"
for package_manager in $package_managers
do
which $package_manager >/dev/null
if [ $? == 0 ];then
res=$package_manager
break
fi
done
echo $res
}
get_version_from_github(){
local version=$(curl -s https://api.github.com/repos/shadowsocks/$1/releases/latest | jq -r ".tag_name")
echo $version
}
get_version_from_bin(){
local version=v$($1 --version | sed -n 1p | cut -d " " -f2 | grep -oE '([0-9]{1,4}\.)*[0-9]{1,4}')
echo $version
}
install_shadowsocks_rust(){
local need_update="0"
local version_new=$(get_version_from_github "shadowsocks-rust")
local version_cur=""
local bins="sslocal ssmanager ssserver ssservice ssurl"
for bin in $bins
do
version_cur=$(get_version_from_bin $bin)
if [ "$version_new" != "$version_cur" ];then
need_update="1"
break
fi
done
if [ "$need_update" == "1" ];then
local tmp_dir=`mktemp -d /tmp/shadowsocks-rust_bin.XXXXXX`
cd $tmp_dir
wget https://github.com/shadowsocks/shadowsocks-rust/releases/download/"$version_new"/shadowsocks-"$version_new"."$arch_shadowsocks_rust"-unknown-"$kernel_shadowsocks_rust"-"$system_shadowsocks_rust".tar.xz -O shadowsocks-"$version_new"."$arch_shadowsocks_rust"-unknown-"$kernel_shadowsocks_rust"-"$system_shadowsocks_rust".tar.xz > /dev/null 2>&1
tar xvf shadowsocks-"$version_new"."$arch_shadowsocks_rust"-unknown-"$kernel_shadowsocks_rust"-"$system_shadowsocks_rust".tar.xz
service shadowsocks-rust_transproxy stop > /dev/null 2>&1
service shadowsocks-rust_server stop > /dev/null 2>&1
for bin in $bins
do
chmod +x $bin
local version_new_bin=$(get_version_from_bin "./$bin")
if [ "$version_new_bin" == "$version_new" ];then
mv -f $bin $path_install_to/$bin
fi
done
service shadowsocks-rust_transproxy start > /dev/null 2>&1
service shadowsocks-rust_server start > /dev/null 2>&1
rm -rf $tmp_dir
fi
}
install_v2ray_plugin(){
local need_update="0"
local version_new=$(get_version_from_github "v2ray-plugin")
local version_cur=""
local bins="v2ray-plugin"
for bin in $bins
do
version_cur=$(get_version_from_bin $bin)
if [ "$version_new" != "$version_cur" ];then
need_update="1"
break
fi
done
if [ "$need_update" == "1" ];then
local tmp_dir=`mktemp -d /tmp/v2ray-plugin_bin.XXXXXX`
cd $tmp_dir
wget https://github.com/shadowsocks/v2ray-plugin/releases/download/"$version_new"/v2ray-plugin-"$kernel_v2ray_plugin"-"$arch_v2ray_plugin"-"$version_new".tar.gz -O v2ray-plugin-"$kernel_v2ray_plugin"-"$arch_v2ray_plugin"-"$version_new".tar.gz > /dev/null 2>&1
tar xvf v2ray-plugin-"$kernel_v2ray_plugin"-"$arch_v2ray_plugin"-"$version_new".tar.gz
service shadowsocks-rust_transproxy stop > /dev/null 2>&1
service shadowsocks-rust_server stop > /dev/null 2>&1
chmod +x v2ray-plugin_"$kernel_v2ray_plugin"_"$arch_v2ray_plugin""$arch_version_v2ray_plugin"
local version_new_bin=$(get_version_from_bin "./v2ray-plugin_"$kernel_v2ray_plugin"_"$arch_v2ray_plugin""$arch_version_v2ray_plugin"")
if [ "$version_new_bin" == "$version_new" ];then
mv -f v2ray-plugin_"$kernel_v2ray_plugin"_"$arch_v2ray_plugin""$arch_version_v2ray_plugin" $path_install_to/v2ray-plugin
fi
service shadowsocks-rust_transproxy start > /dev/null 2>&1
service shadowsocks-rust_server start > /dev/null 2>&1
rm -rf $tmp_dir
fi
}
install(){
pm=$(guess_package_manager)
$pm install curl -y > /dev/null 2>&1
$pm install jq -y > /dev/null 2>&1
install_shadowsocks_rust
install_v2ray_plugin
}
uninstall(){
local bins="sslocal ssmanager ssserver ssservice ssurl v2ray-plugin"
for bin in $bins
do
rm -f $path_install_to/$bin
done
}
update(){
install_shadowsocks_rust
install_v2ray_plugin
}
case "$1" in
install) install
;;
uninstall) uninstall
;;
update) update
;;
*) echo "Usage: install|uninstall|update"
exit 2
;;
esac
exit 0