2022-08-29 14:44:55 +00: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)
|
|
|
|
|
2022-09-08 12:18:45 +00:00
|
|
|
if [ "$1" = "dev" ]; then
|
2022-08-29 14:44:55 +00:00
|
|
|
version="dev"
|
|
|
|
webVersion="dev"
|
2022-09-08 12:18:45 +00:00
|
|
|
else
|
2022-09-09 08:48:12 +00:00
|
|
|
version=$(git describe --abbrev=0 --tags)
|
2022-09-08 12:18:45 +00:00
|
|
|
webVersion=$(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')
|
2022-08-29 14:44:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "build version: $gitTag"
|
|
|
|
|
|
|
|
ldflags="\
|
|
|
|
-w -s \
|
|
|
|
-X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=$builtAt' \
|
|
|
|
-X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=$goVersion' \
|
|
|
|
-X 'github.com/alist-org/alist/v3/internal/conf.GitAuthor=$gitAuthor' \
|
|
|
|
-X 'github.com/alist-org/alist/v3/internal/conf.GitCommit=$gitCommit' \
|
|
|
|
-X 'github.com/alist-org/alist/v3/internal/conf.Version=$version' \
|
|
|
|
-X 'github.com/alist-org/alist/v3/internal/conf.WebVersion=$webVersion' \
|
|
|
|
"
|
|
|
|
|
2022-09-08 12:18:45 +00:00
|
|
|
FetchWebDev() {
|
2022-08-29 14:44:55 +00:00
|
|
|
curl -L https://codeload.github.com/alist-org/web-dist/tar.gz/refs/heads/main -o web-dist-main.tar.gz
|
|
|
|
tar -zxvf web-dist-main.tar.gz
|
2022-08-30 07:53:40 +00:00
|
|
|
rm -rf public/dist
|
|
|
|
mv -f web-dist-main/dist public
|
2022-08-29 14:44:55 +00:00
|
|
|
rm -rf web-dist-main web-dist-main.tar.gz
|
|
|
|
}
|
|
|
|
|
2022-09-08 13:22:21 +00:00
|
|
|
FetchWebRelease() {
|
2022-09-09 05:34:22 +00:00
|
|
|
curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz
|
2022-09-08 13:22:21 +00:00
|
|
|
tar -zxvf dist.tar.gz
|
2022-09-09 07:51:20 +00:00
|
|
|
rm -rf public/dist
|
2022-09-08 13:22:21 +00:00
|
|
|
mv -f dist public
|
|
|
|
rm -rf dist.tar.gz
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:44:55 +00:00
|
|
|
BuildDev() {
|
|
|
|
rm -rf .git/
|
|
|
|
xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out "$appName" -ldflags="$ldflags" -tags=jsoniter .
|
|
|
|
mkdir -p "dist"
|
|
|
|
mv alist-* dist
|
|
|
|
cd dist
|
|
|
|
upx -9 ./alist-linux*
|
|
|
|
upx -9 ./alist-windows*
|
|
|
|
find . -type f -print0 | xargs -0 md5sum >md5.txt
|
|
|
|
cat md5.txt
|
|
|
|
}
|
|
|
|
|
2022-09-08 12:18:45 +00:00
|
|
|
BuildDocker() {
|
|
|
|
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter .
|
|
|
|
}
|
|
|
|
|
2022-09-08 13:22:21 +00:00
|
|
|
BuildRelease() {
|
|
|
|
rm -rf .git/
|
|
|
|
mkdir -p "build"
|
2022-09-09 07:51:20 +00:00
|
|
|
muslflags="--extldflags '-static -fpic' $ldflags"
|
2022-09-08 13:22:21 +00:00
|
|
|
BASE="https://musl.nn.ci/"
|
|
|
|
FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross arm-linux-musleabihf-cross mips-linux-musl-cross mips64-linux-musl-cross mips64el-linux-musl-cross mipsel-linux-musl-cross powerpc64le-linux-musl-cross s390x-linux-musl-cross)
|
|
|
|
for i in "${FILES[@]}"; do
|
|
|
|
url="${BASE}${i}.tgz"
|
|
|
|
curl -L -o "${i}.tgz" "${url}"
|
|
|
|
sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local
|
|
|
|
done
|
|
|
|
OS_ARCHES=(linux-musl-amd64 linux-musl-arm64 linux-musl-arm linux-musl-mips linux-musl-mips64 linux-musl-mips64le linux-musl-mipsle linux-musl-ppc64le linux-musl-s390x)
|
|
|
|
CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc arm-linux-musleabihf-gcc mips-linux-musl-gcc mips64-linux-musl-gcc mips64el-linux-musl-gcc mipsel-linux-musl-gcc powerpc64le-linux-musl-gcc s390x-linux-musl-gcc)
|
|
|
|
for i in "${!OS_ARCHES[@]}"; do
|
|
|
|
os_arch=${OS_ARCHES[$i]}
|
|
|
|
cgo_cc=${CGO_ARGS[$i]}
|
|
|
|
echo building for ${os_arch}
|
|
|
|
export GOOS=${os_arch%%-*}
|
|
|
|
export GOARCH=${os_arch##*-}
|
|
|
|
export CC=${cgo_cc}
|
|
|
|
export CGO_ENABLED=1
|
2022-09-09 07:51:20 +00:00
|
|
|
go build -o ./build/$appName-$os_arch -ldflags="$muslflags" -tags=jsoniter .
|
2022-09-08 13:22:21 +00:00
|
|
|
done
|
2022-09-09 07:51:20 +00:00
|
|
|
xgo -out "$appName" -ldflags="$ldflags" -tags=jsoniter .
|
|
|
|
# why? Because some target platforms seem to have issues with upx compression
|
|
|
|
upx -9 ./alist-linux-amd64
|
|
|
|
upx -9 ./alist-windows*
|
|
|
|
mv alist-* build
|
2022-09-08 13:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MakeRelease() {
|
|
|
|
cd build
|
|
|
|
mkdir compress
|
|
|
|
for i in $(find . -type f -name "$appName-linux-*"); do
|
|
|
|
cp "$i" alist
|
|
|
|
tar -czvf compress/"$i".tar.gz alist
|
|
|
|
rm -f alist
|
|
|
|
done
|
|
|
|
for i in $(find . -type f -name "$appName-darwin-*"); do
|
|
|
|
cp "$i" alist
|
2022-09-09 08:31:43 +00:00
|
|
|
tar -czvf compress/"$i".tar.gz alist
|
2022-09-08 13:22:21 +00:00
|
|
|
rm -f alist
|
|
|
|
done
|
|
|
|
for i in $(find . -type f -name "$appName-windows-*"); do
|
|
|
|
cp "$i" alist.exe
|
2022-09-09 08:31:43 +00:00
|
|
|
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip alist.exe
|
2022-09-08 13:22:21 +00:00
|
|
|
rm -f alist.exe
|
|
|
|
done
|
|
|
|
cd compress
|
|
|
|
find . -type f -print0 | xargs -0 md5sum >md5.txt
|
|
|
|
cat md5.txt
|
|
|
|
cd ../..
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:44:55 +00:00
|
|
|
if [ "$1" = "dev" ]; then
|
2022-09-08 12:18:45 +00:00
|
|
|
FetchWebDev
|
|
|
|
if [ "$2" = "docker" ]; then
|
|
|
|
BuildDocker
|
|
|
|
else
|
|
|
|
BuildDev
|
|
|
|
fi
|
2022-08-29 14:44:55 +00:00
|
|
|
elif [ "$1" = "release" ]; then
|
2022-09-08 13:22:21 +00:00
|
|
|
FetchWebRelease
|
|
|
|
if [ "$2" = "docker" ]; then
|
|
|
|
BuildDocker
|
|
|
|
else
|
|
|
|
BuildRelease
|
|
|
|
MakeRelease
|
|
|
|
fi
|
2022-08-29 14:44:55 +00:00
|
|
|
else
|
|
|
|
echo -e "Parameter error"
|
2022-09-08 13:22:21 +00:00
|
|
|
fi
|