diff --git a/.gitignore b/.gitignore index 7a8c4e3..39f9f7b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,6 @@ go.work .vscode bin/ dist/ -ipkg/etc/ -ipkg/usr/ +scripts/ipkg/etc/ +scripts/ipkg/usr/ test/ \ No newline at end of file diff --git a/build.sh b/scripts/build.sh similarity index 75% rename from build.sh rename to scripts/build.sh index 00f2650..baef06b 100755 --- a/build.sh +++ b/scripts/build.sh @@ -1,8 +1,8 @@ #!/bin/sh # -------------------------------- # Usage examples: -# ./build.sh # default: linux all + win/darwin 64/arm64 -# ./build.sh linux/amd64 windows/arm64 +# ./scripts/build.sh # default: linux all + win/darwin 64/arm64 +# ./scripts/build.sh linux/amd64 windows/arm64 # -------------------------------- set -e @@ -10,8 +10,6 @@ set -e project_name="ua3f" release_version="1.8.4" target=main.go -dist=./dist -release_dir=./bin LINUX_ARCHS="amd64 arm arm64 mipsle mips64 riscv64 386 mipsle-softfloat mipsle-hardfloat armv7 armv8" @@ -28,12 +26,17 @@ else TARGET_LIST="$DEFAULT_TARGETS" fi +script_dir="$(cd "$(dirname "$0")" && pwd)" +project_root="$(cd "$script_dir/.." && pwd)" +dist="$project_root/dist" +release_dir="$project_root/bin" + rm -rf "$release_dir"/* "$dist"/* mkdir -p "$release_dir" "$dist/bin" -cd "$(dirname "$0")" +cd "$project_root" gofmt -w ./ -cd "$(dirname "$0")/src" +cd "$project_root/src" for target_item in $TARGET_LIST; do goos=$(echo "$target_item" | cut -d'/' -f1) @@ -54,28 +57,28 @@ for target_item in $TARGET_LIST; do ;; armv8) alias_name=$project_name-$release_version-${goos}-arm64 - if [ ! -f "../dist/bin/$alias_name" ]; then + if [ ! -f "$project_root/dist/bin/$alias_name" ]; then echo ">>> Building $goos/arm64 (for armv8 alias)" CGO_ENABLED=0 GOOS=$goos GOARCH=arm64 go build -trimpath -ldflags="-s -w" -o "$alias_name" "$target" - cp "$alias_name" ../dist/bin/ + cp "$alias_name" "$project_root/dist/bin/" fi - cp "../dist/bin/$alias_name" "$obj_name" + cp "$project_root/dist/bin/$alias_name" "$obj_name" ;; *) CGO_ENABLED=0 GOOS=$goos GOARCH="$goarch" go build -trimpath -ldflags="-s -w" -o "$obj_name" "$target" ;; esac - cp "$obj_name" ../dist/bin/ + cp "$obj_name" "$project_root/dist/bin/" echo ">>> Packaging for $goos/$goarch ..." if [ "$goos" = "windows" ]; then mv "$obj_name" "$project_name.exe" - zip ../bin/$project_name-$release_version-"${goos}"-"${goarch}".zip "$project_name.exe" + zip "$project_root/bin/$project_name-$release_version-${goos}-${goarch}.zip" "$project_name.exe" rm -f "$project_name.exe" elif [ "$goos" = "darwin" ]; then mv "$obj_name" "$project_name" - zip -q ../bin/$project_name-$release_version-"${goos}"-"${goarch}".zip "$project_name" + zip -q "$project_root/bin/$project_name-$release_version-${goos}-${goarch}.zip" "$project_name" rm -f "$project_name" else mv "$obj_name" "$project_name" @@ -84,15 +87,15 @@ for target_item in $TARGET_LIST; do echo ">>> Skipping packaging for linux/$goarch (only arm64 and amd64 are packaged)" rm -f "$project_name" else - tar -zcf ../bin/$project_name-$release_version-"${goos}"-"${goarch}".tar.gz "$project_name" + tar -zcf "$project_root/bin/$project_name-$release_version-${goos}-${goarch}.tar.gz" "$project_name" rm -f "$project_name" fi fi done cd .. -opkg_template=./ipkg -ipkg_build=ipkg-build.sh +opkg_template=./scripts/ipkg +ipkg_build=./scripts/ipkg-build.sh mkdir -p \ $opkg_template/usr/bin \ @@ -123,11 +126,11 @@ for target_item in $TARGET_LIST; do mv "$dist/bin/$obj_name" $opkg_template/usr/bin/ua3f sh "$ipkg_build" "$opkg_template" - mv "$project_name"_"$release_version"-1_all.ipk "$dist/$project_name"_"$release_version"-1_"${goos}_${goarch}".ipk + mv "$project_root/$project_name"_"$release_version"-1_all.ipk "$dist/$project_name"_"$release_version"-1_"${goos}_${goarch}".ipk done -rm -rf "dist/bin" -mv bin/* dist/ -rm -rf bin +rm -rf "$dist/bin" +mv "$release_dir"/* "$dist/" +rm -rf "$release_dir" echo "✅ Build complete:$TARGET_LIST" diff --git a/ipkg-build.sh b/scripts/ipkg-build.sh similarity index 100% rename from ipkg-build.sh rename to scripts/ipkg-build.sh diff --git a/ipkg/CONTROL/conffiles b/scripts/ipkg/CONTROL/conffiles similarity index 100% rename from ipkg/CONTROL/conffiles rename to scripts/ipkg/CONTROL/conffiles diff --git a/ipkg/CONTROL/control b/scripts/ipkg/CONTROL/control similarity index 100% rename from ipkg/CONTROL/control rename to scripts/ipkg/CONTROL/control diff --git a/ipkg/CONTROL/control-e b/scripts/ipkg/CONTROL/control-e similarity index 100% rename from ipkg/CONTROL/control-e rename to scripts/ipkg/CONTROL/control-e diff --git a/ipkg/CONTROL/postinst b/scripts/ipkg/CONTROL/postinst similarity index 100% rename from ipkg/CONTROL/postinst rename to scripts/ipkg/CONTROL/postinst diff --git a/ipkg/CONTROL/postrm b/scripts/ipkg/CONTROL/postrm similarity index 100% rename from ipkg/CONTROL/postrm rename to scripts/ipkg/CONTROL/postrm diff --git a/ipkg/CONTROL/prerm b/scripts/ipkg/CONTROL/prerm similarity index 100% rename from ipkg/CONTROL/prerm rename to scripts/ipkg/CONTROL/prerm