33# github: https://github.com/Jrohy/trojan
44
55# 定义操作变量, 0为否, 1为是
6- HELP =0
6+ help =0
77
8- REMOVE =0
8+ remove =0
99
10- UPDATE =0
10+ update =0
1111
12- DOWNLAOD_URL =" https://github.com/Jrohy/trojan/releases/download/"
12+ download_url =" https://github.com/Jrohy/trojan/releases/download/"
1313
14- VERSION_CHECK =" https://api.github.com/repos/Jrohy/trojan/releases/latest"
14+ version_check =" https://api.github.com/repos/Jrohy/trojan/releases/latest"
1515
16- SERVICE_URL =" https://raw.githubusercontent.com/Jrohy/trojan/master/asset/trojan-web.service"
16+ service_url =" https://raw.githubusercontent.com/Jrohy/trojan/master/asset/trojan-web.service"
1717
18- [[ -e /var/lib/trojan-manager ]] && UPDATE =1
18+ [[ -e /var/lib/trojan-manager ]] && update =1
1919
2020# Centos 临时取消别名
2121[[ -f /etc/redhat-release && -z $( echo $SHELL | grep zsh) ]] && unalias -a
2222
23- [[ -z $( echo $SHELL | grep zsh) ]] && SHELL_WAY =" bash" || SHELL_WAY =" zsh"
23+ [[ -z $( echo $SHELL | grep zsh) ]] && shell_way =" bash" || shell_way =" zsh"
2424
2525# ######color code########
26- RED =" 31m"
27- GREEN =" 32m"
28- YELLOW =" 33m"
29- BLUE =" 36m"
30- FUCHSIA =" 35m"
26+ red =" 31m"
27+ green =" 32m"
28+ yellow =" 33m"
29+ blue =" 36m"
30+ fuchsia =" 35m"
3131
3232colorEcho (){
33- COLOR =$1
34- echo -e " \033[${COLOR }${@: 2} \033[0m"
33+ color =$1
34+ echo -e " \033[${color }${@: 2} \033[0m"
3535}
3636
3737# ######get params#########
3838while [[ $# > 0 ]]; do
39- KEY =" $1 "
40- case $KEY in
39+ key =" $1 "
40+ case $key in
4141 --remove)
42- REMOVE =1
42+ remove =1
4343 ;;
4444 -h|--help)
45- HELP =1
45+ help =1
4646 ;;
4747 * )
4848 # unknown option
@@ -77,30 +77,30 @@ removeTrojan() {
7777 rm -rf /home/mysql /home/mariadb > /dev/null 2>&1
7878
7979 # 移除环境变量
80- sed -i ' /trojan/d' ~ /.${SHELL_WAY } rc
81- source ~ /.${SHELL_WAY } rc
80+ sed -i ' /trojan/d' ~ /.${shell_way } rc
81+ source ~ /.${shell_way } rc
8282
83- colorEcho ${GREEN } " uninstall success!"
83+ colorEcho ${green } " uninstall success!"
8484}
8585
8686checkSys () {
8787 # 检查是否为Root
88- [ $( id -u) != " 0" ] && { colorEcho ${RED } " Error: You must be root to run this script" ; exit 1; }
88+ [ $( id -u) != " 0" ] && { colorEcho ${red } " Error: You must be root to run this script" ; exit 1; }
8989
90- ARCH =$( uname -m 2> /dev/null)
91- if [[ $ARCH != x86_64 && $ARCH != aarch64 ]]; then
92- colorEcho $YELLOW " not support $ARCH machine" .
90+ arch =$( uname -m 2> /dev/null)
91+ if [[ $arch != x86_64 && $arch != aarch64 ]]; then
92+ colorEcho $yellow " not support $arch machine" .
9393 exit 1
9494 fi
9595
9696 if [[ ` command -v apt-get` ]]; then
97- PACKAGE_MANAGER =' apt-get'
97+ package_manager =' apt-get'
9898 elif [[ ` command -v dnf` ]]; then
99- PACKAGE_MANAGER =' dnf'
99+ package_manager =' dnf'
100100 elif [[ ` command -v yum` ]]; then
101- PACKAGE_MANAGER =' yum'
101+ package_manager =' yum'
102102 else
103- colorEcho $RED " Not support OS!"
103+ colorEcho $red " Not support OS!"
104104 exit 1
105105 fi
106106
@@ -110,60 +110,60 @@ checkSys() {
110110
111111# 安装依赖
112112installDependent (){
113- if [[ ${PACKAGE_MANAGER } == ' dnf' || ${PACKAGE_MANAGER } == ' yum' ]]; then
114- ${PACKAGE_MANAGER } install socat crontabs bash-completion -y
113+ if [[ ${package_manager } == ' dnf' || ${package_manager } == ' yum' ]]; then
114+ ${package_manager } install socat crontabs bash-completion -y
115115 else
116- ${PACKAGE_MANAGER } update
117- ${PACKAGE_MANAGER } install socat cron bash-completion xz-utils -y
116+ ${package_manager } update
117+ ${package_manager } install socat cron bash-completion xz-utils -y
118118 fi
119119}
120120
121121setupCron () {
122122 if [[ ` crontab -l 2> /dev/null| grep acme` ]]; then
123123 if [[ -z ` crontab -l 2> /dev/null| grep trojan-web` || ` crontab -l 2> /dev/null| grep trojan-web| grep " &" ` ]]; then
124124 # 计算北京时间早上3点时VPS的实际时间
125- ORIGIN_TIME_ZONE =$( date -R| awk ' {printf"%d",$6}' )
126- LOCAL_TIME_ZONE =${ORIGIN_TIME_ZONE % 00}
127- BEIJING_ZONE =8
128- BEIJING_UPDATE_TIME =3
129- DIFF_ZONE =$[$BEIJING_ZONE - $LOCAL_TIME_ZONE ]
130- LOCAL_TIME =$[$BEIJING_UPDATE_TIME - $DIFF_ZONE ]
131- if [ $LOCAL_TIME -lt 0 ]; then
132- LOCAL_TIME =$[24+$LOCAL_TIME ]
133- elif [ $LOCAL_TIME -ge 24 ]; then
134- LOCAL_TIME =$[$LOCAL_TIME -24]
125+ origin_time_zone =$( date -R| awk ' {printf"%d",$6}' )
126+ local_time_zone =${origin_time_zone % 00}
127+ beijing_zone =8
128+ beijing_update_time =3
129+ diff_zone =$[$beijing_zone - $local_time_zone ]
130+ local_time =$[$beijing_update_time - $diff_zone ]
131+ if [ $local_time -lt 0 ]; then
132+ local_time =$[24+$local_time ]
133+ elif [ $local_time -ge 24 ]; then
134+ local_time =$[$local_time -24]
135135 fi
136136 crontab -l 2> /dev/null| sed ' /acme.sh/d' > crontab.txt
137- echo " 0 ${LOCAL_TIME } " ' * * * systemctl stop trojan-web; "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null; systemctl start trojan-web' >> crontab.txt
137+ echo " 0 ${local_time } " ' * * * systemctl stop trojan-web; "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null; systemctl start trojan-web' >> crontab.txt
138138 crontab crontab.txt
139139 rm -f crontab.txt
140140 fi
141141 fi
142142}
143143
144144installTrojan (){
145- local SHOW_TIP =0
146- if [[ $UPDATE == 1 ]]; then
145+ local show_tip =0
146+ if [[ $update == 1 ]]; then
147147 systemctl stop trojan-web > /dev/null 2>&1
148148 rm -f /usr/local/bin/trojan
149149 fi
150- LASTEST_VERSION =$( curl -H ' Cache-Control: no-cache' -s " $VERSION_CHECK " | grep ' tag_name' | cut -d\" -f4)
151- echo " 正在下载管理程序` colorEcho $BLUE $LASTEST_VERSION ` 版本..."
152- [[ $ARCH == x86_64 ]] && BIN =" trojan-linux-amd64" || BIN =" trojan-linux-arm64"
153- curl -L " $DOWNLAOD_URL / $LASTEST_VERSION / $BIN " -o /usr/local/bin/trojan
150+ lastest_version =$( curl -H ' Cache-Control: no-cache' -s " $version_check " | grep ' tag_name' | cut -d\" -f4)
151+ echo " 正在下载管理程序` colorEcho $blue $lastest_version ` 版本..."
152+ [[ $arch == x86_64 ]] && bin =" trojan-linux-amd64" || bin =" trojan-linux-arm64"
153+ curl -L " $download_url / $lastest_version / $bin " -o /usr/local/bin/trojan
154154 chmod +x /usr/local/bin/trojan
155155 if [[ ! -e /etc/systemd/system/trojan-web.service ]]; then
156- SHOW_TIP =1
157- curl -L $SERVICE_URL -o /etc/systemd/system/trojan-web.service
156+ show_tip =1
157+ curl -L $service_url -o /etc/systemd/system/trojan-web.service
158158 systemctl daemon-reload
159159 systemctl enable trojan-web
160160 fi
161161 # 命令补全环境变量
162- [[ -z $( grep trojan ~ /.${SHELL_WAY } rc) ]] && echo " source <(trojan completion ${SHELL_WAY } )" >> ~ /.${SHELL_WAY } rc
163- source ~ /.${SHELL_WAY } rc
164- if [[ $UPDATE == 0 ]]; then
165- colorEcho $GREEN " 安装trojan管理程序成功!\n"
166- echo -e " 运行命令` colorEcho $BLUE trojan` 可进行trojan管理\n"
162+ [[ -z $( grep trojan ~ /.${shell_way } rc) ]] && echo " source <(trojan completion ${shell_way } )" >> ~ /.${shell_way } rc
163+ source ~ /.${shell_way } rc
164+ if [[ $update == 0 ]]; then
165+ colorEcho $green " 安装trojan管理程序成功!\n"
166+ echo -e " 运行命令` colorEcho $blue trojan` 可进行trojan管理\n"
167167 /usr/local/bin/trojan
168168 else
169169 if [[ ` cat /usr/local/etc/trojan/config.json| grep -w " \" db\" " ` ]]; then
@@ -175,19 +175,19 @@ installTrojan(){
175175 /usr/local/bin/trojan upgrade config
176176 fi
177177 systemctl restart trojan-web
178- colorEcho $GREEN " 更新trojan管理程序成功!\n"
178+ colorEcho $green " 更新trojan管理程序成功!\n"
179179 fi
180180 setupCron
181- [[ $SHOW_TIP == 1 ]] && echo " 浏览器访问'` colorEcho $BLUE https://域名` '可在线trojan多用户管理"
181+ [[ $show_tip == 1 ]] && echo " 浏览器访问'` colorEcho $blue https://域名` '可在线trojan多用户管理"
182182}
183183
184184main (){
185- [[ ${HELP } == 1 ]] && help && return
186- [[ ${REMOVE } == 1 ]] && removeTrojan && return
187- [[ $UPDATE == 0 ]] && echo " 正在安装trojan管理程序.." || echo " 正在更新trojan管理程序.."
185+ [[ ${help } == 1 ]] && help && return
186+ [[ ${remove } == 1 ]] && removeTrojan && return
187+ [[ $update == 0 ]] && echo " 正在安装trojan管理程序.." || echo " 正在更新trojan管理程序.."
188188 checkSys
189- [[ $UPDATE == 0 ]] && installDependent
189+ [[ $update == 0 ]] && installDependent
190190 installTrojan
191191}
192192
193- main
193+ main
0 commit comments