Skip to content

Commit

Permalink
优化编译脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Dec 7, 2021
1 parent 946e171 commit 65578bc
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
rm -rf result
fi

0 comments on commit 65578bc

Please sign in to comment.