-
Notifications
You must be signed in to change notification settings - Fork 23
/
porttranfree.sh
165 lines (160 loc) · 4.42 KB
/
porttranfree.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#bin
version='5.0.1.5'
shell_version='2.1.1'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
myFile=$version.tar.gz
installfolder='/etc/porttran'
if [ ! -f "$myFile" ]; then
echo "\n"
else
rm $version.tar.gz
fi
kill_porttran(){
PROCESS=`ps -ef|grep porttran|grep -v grep|grep -v PPID|awk '{ print $2}'`
for i in $PROCESS
do
echo "Kill the $1 process [ $i ]"
kill -9 $i
done
}
kill_ppexec(){
PROCESS=`ps -ef|grep ppexec|grep -v grep|grep -v PPID|awk '{ print $2}'`
for i in $PROCESS
do
echo "Kill the $1 process [ $i ]"
kill -9 $i
done
}
install() {
wget https://github.com/mingmingge891/porttran/archive/refs/tags/$version.tar.gz
tar -zxvf $version.tar.gz
cd porttran-$version/porttranfree
tar -zxvf porttranlatest.tar.gz
cd ../..
mv porttran-$version/porttranfree/porttran/portdir.sh porttran-$version/porttranfree/porttran/porttran
mkdir porttran && chmod 777 porttran
mv porttran-$version/porttranfree/porttran/* porttran
cd porttran/ && chmod +x porttran && chmod +x ppexec
cd ../
rm -rf porttran-$version
rm $version.tar.gz
rm porttranfree.sh
cp -r porttran /etc/
rm -rf porttran/
clear
before_show_menu
}
check_install() {
if [ ! -d "$installfolder" ]; then
echo -e " ${red}<<转发没有安装>>"
else
echo -e " ${green}<<转发已经安装>>"
fi
}
before_show_menu() {
echo && echo -n -e "${yellow}操作完成按回车返回主菜单: ${plain}" && read temp
show_menu
}
update_shell() {
wget https://raw.githubusercontent.com/mingmingge891/porttran/main/porttranfree.sh -O -> /usr/bin/porttran-ui && chmod +x /usr/bin/porttran-ui && porttran-ui
echo
exit 0
}
update_app() {
kill_porttran
kill_ppexec
wget https://github.com/mingmingge891/porttran/archive/refs/tags/$version.tar.gz
tar -zxvf $version.tar.gz
cd porttran-$version/porttranfree
tar -zxvf porttranlatest.tar.gz
cd ../..
mv porttran-$version/porttranfree/porttran/portdir.sh porttran-$version/porttranfree/porttran/porttran
mkdir porttran && chmod 777 porttran
mv porttran-$version/porttranfree/porttran/* porttran
cd porttran/ && chmod +x porttran && chmod +x ppexec
cd ../
rm -rf porttran-$version
rm $version.tar.gz
rm porttranfree.sh
rm /etc/porttran/porttran
rm /etc/porttran/ppexec
rm -rf /etc/porttran/ui
cp porttran/ppexec /etc/porttran/
cp porttran/porttran /etc/porttran/
cd porttran/
cp -r ui /etc/porttran
cd ../
rm -rf porttran/
before_show_menu
}
uninstall_app() {
echo && echo -n -e "${yellow}确定卸载吗,按回车确定,CTRL+C退出: ${plain}" && read temp
kill_porttran
kill_ppexec
rm -rf /etc/porttran
before_show_menu
}
uninstall_shell() {
echo && echo -n -e "${yellow}确定卸载吗,按回车确定,CTRL+C退出: ${plain}" && read temp
rm /usr/bin/porttran-ui
before_show_menu
}
start() {
cd /etc/porttran
setsid ./porttran &
sleep 2
before_show_menu
}
stop() {
echo && echo -n -e "${yellow}确定停止吗,按回车确定,CTRL+C退出: ${plain}" && read temp
kill_porttran
kill_ppexec
before_show_menu
}
show_menu() {
clear
check_install
echo -e "
${green}porttran脚本管理界面安装完成${red}版本${shell_version},转发软件版本${version}
${green}任意目录下输入porttran-ui 启动管理界面
${red}转发软件浏览器默认端口62438,默认用户名密码admin,admin${plain}
————————————————
${green}0.${plain} 退出
————————————————
${green}1.${plain} 安装转发
${green}2.${plain} 更新转发
${green}3.${plain} 卸载转发
————————————————
${green}4.${plain} 更新脚本
${green}5.${plain} 卸载脚本
————————————————
${green}6.${plain} 启动转发
${green}7.${plain} 停止转发
————————————————
"
echo && read -p "请输入选择 [0-7]: " num
case "${num}" in
0) exit 0
;;
1) install
;;
2) update_app
;;
3) uninstall_app
;;
4) update_shell
;;
5) uninstall_shell
;;
6) start
;;
7) stop
;;
*) echo -e "${red}请输入正确的数字 [0-7]${plain}"
;;
esac
}
show_menu