-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
GITHUB_TOKEN="" | ||
|
||
PROJECT="Jrohy/trojan" | ||
|
||
RELEASE_ID=`curl -H 'Cache-Control: no-cache' -s https://api.github.com/repos/$PROJECT/releases/latest|grep id|awk 'NR==1{print $2}'|sed 's/,//'` | ||
|
||
function uploadfile() { | ||
FILE=$1 | ||
CTYPE=$(file -b --mime-type $FILE) | ||
|
||
curl -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: ${CTYPE}" --data-binary @$FILE "https://uploads.github.com/repos/$PROJECT/releases/${RELEASE_ID}/assets?name=$(basename $FILE)" | ||
|
||
echo "" | ||
} | ||
|
||
function upload() { | ||
FILE=$1 | ||
DGST=$1.dgst | ||
openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >> $DGST | ||
openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >> $DGST | ||
openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >> $DGST | ||
openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >> $DGST | ||
uploadfile $FILE | ||
uploadfile $DGST | ||
} | ||
|
||
pushd `pwd` &>/dev/null | ||
|
||
go get -u github.com/gobuffalo/packr/packr | ||
|
||
packr build -ldflags "-s -w" -o "result/trojan" .. | ||
|
||
cd result | ||
|
||
UPLOAD_ITEM=($(ls -l|awk '{print $9}'|xargs -r)) | ||
|
||
for ITEM in ${UPLOAD_ITEM[@]} | ||
do | ||
upload $ITEM | ||
done | ||
|
||
echo "" | ||
echo "upload completed!" | ||
|
||
popd &>/dev/null | ||
|
||
rm -rf result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,135 @@ | ||
#!/bin/bash | ||
# Author: Jrohy | ||
# github: https://github.com/Jrohy/trojan | ||
|
||
docker run -d --name test --net=host --privileged trojan-manager /sbin/init | ||
#定义操作变量, 0为否, 1为是 | ||
HELP=0 | ||
|
||
docker run -it -d --name test -v /var/run/docker.sock:/var/run/docker.sock -v `which docker`:`which docker` centos tail -f | ||
REMOVE=0 | ||
|
||
UPDATE=0 | ||
|
||
DOWNLAOD_URL="https://github.com/Jrohy/trojan/releases/download/" | ||
|
||
VERSION_CHECK="https://api.github.com/repos/Jrohy/trojan/releases/latest" | ||
|
||
[[ -e /var/lib/trojan-manager ]] && UPDATE=1 | ||
|
||
#Centos 临时取消别名 | ||
[[ -f /etc/redhat-release && -z $(echo $SHELL|grep zsh) ]] && unalias -a | ||
|
||
[[ -z $(echo $SHELL|grep zsh) ]] && SHELL_WAY="bash" || SHELL_WAY="zsh" | ||
|
||
#######color code######## | ||
RED="31m" | ||
GREEN="32m" | ||
YELLOW="33m" | ||
BLUE="36m" | ||
FUCHSIA="35m" | ||
|
||
colorEcho(){ | ||
COLOR=$1 | ||
echo -e "\033[${COLOR}${@:2}\033[0m" | ||
} | ||
|
||
#######get params######### | ||
while [[ $# > 0 ]];do | ||
KEY="$1" | ||
case $KEY in | ||
--remove) | ||
REMOVE=1 | ||
;; | ||
-h|--help) | ||
HELP=1 | ||
;; | ||
*) | ||
# unknown option | ||
;; | ||
esac | ||
shift # past argument or value | ||
done | ||
############################# | ||
|
||
help(){ | ||
echo "bash $0 [-h|--help] [--remove]" | ||
echo " -h, --help Show help" | ||
echo " --remove remove trojan" | ||
echo " no params to new install" | ||
return 0 | ||
} | ||
|
||
removeTrojan() { | ||
#移除trojan | ||
rm -rf /usr/bin/trojan | ||
rm -rf /usr/local/etc/trojan | ||
rm -f /etc/systemd/system/trojan.service | ||
systemctl daemon-reload | ||
|
||
#移除trojan管理程序 | ||
rm -f /usr/local/bin/trojan | ||
rm -rf /var/lib/trojan-manager | ||
|
||
#移除环境变量 | ||
sed -i '/trojan/d' ~/${SHELL_WAY}rc | ||
source ~/.${SHELL_WAY}rc | ||
|
||
|
||
colorEcho ${GREEN} "uninstall success!" | ||
} | ||
|
||
checkSys() { | ||
#检查是否为Root | ||
[ $(id -u) != "0" ] && { colorEcho ${RED} "Error: You must be root to run this script"; exit 1; } | ||
if [[ $(uname -m 2> /dev/null) != x86_64 ]]; then | ||
colorEcho $YELLOW "Please run this script on x86_64 machine." | ||
exit 1 | ||
fi | ||
|
||
if [[ `command -v apt-get` ]];then | ||
PACKAGE_MANAGER='apt-get' | ||
elif [[ `command -v dnf` ]];then | ||
PACKAGE_MANAGER='dnf' | ||
elif [[ `command -v yum` ]];then | ||
PACKAGE_MANAGER='yum' | ||
else | ||
colorEcho $RED "Not support OS!" | ||
exit 1 | ||
fi | ||
} | ||
|
||
#安装依赖 | ||
installDependent(){ | ||
if [[ ${PACKAGE_MANAGER} == 'dnf' || ${PACKAGE_MANAGER} == 'yum' ]];then | ||
if [[ ${PACKAGE_MANAGER} == 'yum' ]];then | ||
${PACKAGE_MANAGER} ntpdate -y | ||
fi | ||
${PACKAGE_MANAGER} install socat bash-completion -y | ||
else | ||
${PACKAGE_MANAGER} update | ||
${PACKAGE_MANAGER} install socat bash-completion -y | ||
fi | ||
} | ||
|
||
installTrojan(){ | ||
LASTEST_VERSION=$(curl -H 'Cache-Control: no-cache' -s "$VERSION_CHECK" | grep 'tag_name' | cut -d\" -f4 | sed 's/v//g') | ||
curl -L "$DOWNLAOD_URL/$LASTEST_VERSION/trojan" -o /usr/local/bin/trojan | ||
#命令补全环境变量 | ||
[[ -z $(grep trojan ~/.${SHELL_WAY}rc) ]] && { echo "source <(trojan completion ${SHELL_WAY})" >> ~/.${SHELL_WAY}rc; source ~/.${SHELL_WAY}rc; } | ||
if [[ UPDATE == 0 ]];then | ||
colorEcho $GREEN "安装trojan管理程序成功!\n" | ||
echo "运行命令`colorEcho $BLUE trojan`可进行trojan管理" | ||
trojan | ||
else | ||
colorEcho $GREEN "更新trojan管理程序成功!\n" | ||
fi | ||
} | ||
|
||
main(){ | ||
[[ ${HELP} == 1 ]] && help && return | ||
[[ ${REMOVE} == 1 ]] && removeTrojan && return | ||
checkSys | ||
installDependent | ||
installTrojan | ||
} | ||
|
||
main |