Files
OpenList/build.sh

120 lines
4.1 KiB
Bash
Raw Normal View History

2021-11-03 19:51:19 +08:00
#!/bin/bash
# 构建前端,在当前目录产生一个dist文件夹
BUILD_WEB() {
git clone https://github.com/alist-org/alist-web.git
cd alist-web
2021-11-09 16:46:03 +08:00
yarn
2022-02-21 20:31:01 +08:00
yarn build
2022-02-20 16:46:47 +08:00
sed -i -e "s/\/CDN_URL\//\//g" dist/index.html
2022-02-21 20:31:01 +08:00
sed -i -e "s/assets/\/assets/g" dist/index.html
2022-02-20 16:46:47 +08:00
rm -f dist/index.html-e
mv dist ..
2021-11-09 16:46:03 +08:00
cd ..
rm -rf alist-web
}
2021-11-09 16:46:03 +08:00
CDN_WEB() {
curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz
tar -zxvf dist.tar.gz
rm -f dist.tar.gz
}
2021-11-09 21:36:27 +08:00
# 在DOCKER中构建
BUILD_DOCKER() {
2021-11-09 16:46:03 +08:00
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
2021-11-09 17:54:38 +08:00
gitTag=$(git describe --long --tags --dirty --always)
2022-02-20 15:14:18 +08:00
webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
2021-11-09 16:46:03 +08:00
ldflags="\
-w -s \
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
2022-02-20 15:14:18 +08:00
-X 'github.com/Xhofe/alist/conf.WebTag=$webTag' \
"
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter alist.go
}
2021-11-03 19:51:19 +08:00
BUILD() {
cd alist
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
gitTag=$(git describe --long --tags --dirty --always)
2022-02-20 15:14:18 +08:00
webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
ldflags="\
2021-11-03 19:51:19 +08:00
-w -s \
2021-11-04 13:23:17 +08:00
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
2022-02-20 15:14:18 +08:00
-X 'github.com/Xhofe/alist/conf.WebTag=$webTag' \
2022-02-24 16:08:49 +08:00
"
if [ "$1" == "release" ]; then
2022-02-24 16:08:49 +08:00
OS_ARCHES=("aix/ppc64" "android/386" "android/amd64" "android/arm" "android/arm64" "darwin/amd64" "darwin/arm64" "dragonfly/amd64" "freebsd/386" "freebsd/amd64" "freebsd/arm" "freebsd/arm64" "illumos/amd64" "ios/amd64" "ios/arm64" "js/wasm" "linux/386" "linux/amd64" "linux/arm" "linux/arm64" "linux/mips" "linux/mips64" "linux/mips64le" "linux/mipsle" "linux/ppc64" "linux/ppc64le" "linux/riscv64" "linux/s390x" "netbsd/386" "netbsd/amd64" "netbsd/arm" "netbsd/arm64" "openbsd/386" "openbsd/amd64" "openbsd/arm" "openbsd/arm64" "openbsd/mips64" "plan9/386" "plan9/amd64" "plan9/arm" "solaris/amd64" "windows/386" "windows/amd64" "windows/arm" "windows/arm64")
else
2022-02-24 16:08:49 +08:00
OS_ARCHES=("darwin/amd64" "linux/amd64" "windows/amd64")
2022-01-20 13:47:21 +08:00
fi
2022-01-20 14:23:31 +08:00
for i in "${!OS_ARCHES[@]}"; do
os_arch=${OS_ARCHES[$i]}
echo building for ${os_arch}
2022-02-24 16:08:49 +08:00
export GOOS=${os_arch%%/*}
export GOARCH=${os_arch##*/}
export CGO_ENABLED=0
if [ $GOOS == "windows" ]; then
go build -o ./build/$appName-$GOOS-$GOARCH.exe -ldflags="$ldflags" -tags=jsoniter alist.go
else
go build -o ./build/$appName-$GOOS-$GOARCH -ldflags="$ldflags" -tags=jsoniter alist.go
fi
done
2022-02-24 16:08:49 +08:00
cd build
2022-02-24 22:55:50 +08:00
upx -9 ./*
2022-02-24 16:08:49 +08:00
find . -type f -print0 | xargs -0 md5sum >md5.txt
cat md5.txt
cd ..
2022-01-20 13:47:21 +08:00
cd ..
}
RELEASE() {
cd alist/build
mkdir compress
mv md5.txt compress
2022-02-24 16:08:49 +08:00
# win
mkdir windows
mv $appName-windows-* windows/
cd windows
for i in $(find . -type f -name "$appName-windows-*"); do
zip ../compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
done
2022-02-24 16:08:49 +08:00
cd ..
# end win
for i in $(find . -type f -name "$appName-*"); do
tar -czvf compress/"$i".tar.gz "$i"
done
cd ../..
}
if [ "$1" = "web" ]; then
BUILD_WEB
elif [ "$1" = "cdn" ]; then
CDN_WEB
elif [ "$1" = "docker" ]; then
BUILD_DOCKER
elif [ "$1" = "build" ]; then
2022-01-12 01:04:50 +08:00
BUILD build
elif [ "$1" = "release" ]; then
2022-01-12 01:04:50 +08:00
BUILD release
RELEASE
2021-11-04 13:23:17 +08:00
else
2022-01-18 18:19:58 +08:00
echo -e "${RED_COLOR} Parameter error ${RES}"
2021-11-05 19:03:54 +08:00
fi