From 65578bc2ce07d9de6ec9d15ee208fdd9542e485e Mon Sep 17 00:00:00 2001 From: Jrohy Date: Tue, 7 Dec 2021 16:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=96=E8=AF=91=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/build.sh b/build.sh index 9df2c1b7..67dbd966 100644 --- a/build.sh +++ b/build.sh @@ -7,26 +7,24 @@ PROJECT="Jrohy/trojan" #获取当前的这个脚本所在绝对路径 SHELL_PATH=$(cd `dirname $0`; pwd) -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) + 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)" + 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 "" + 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 + 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 } cd $SHELL_PATH @@ -40,17 +38,25 @@ LDFLAGS="-w -s -X 'trojan/trojan.MVersion=$VERSION' -X 'trojan/trojan.BuildDate= GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o "result/trojan-linux-amd64" . GOOS=linux GOARCH=arm64 go build -ldflags "$LDFLAGS" -o "result/trojan-linux-arm64" . -cd result +if [[ $# == 0 ]];then + cd result -UPLOAD_ITEM=($(ls -l|awk '{print $9}'|xargs -r)) + UPLOAD_ITEM=($(ls -l|awk '{print $9}'|xargs -r)) -for ITEM in ${UPLOAD_ITEM[@]} -do - upload $ITEM -done + curl -X POST -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$PROJECT/releases -d '{"tag_name":"'$VERSION'", "name":"'$VERSION'"}' -echo "upload completed!" + sleep 2 -cd $SHELL_PATH + 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/,//'` + + for ITEM in ${UPLOAD_ITEM[@]} + do + upload $ITEM + done + + echo "upload completed!" + + cd $SHELL_PATH -rm -rf result \ No newline at end of file + rm -rf result +fi \ No newline at end of file