From f860d99e42f6990a634fc9f1a1bca5542f8f15e6 Mon Sep 17 00:00:00 2001 From: Moe-hacker Date: Sun, 27 Oct 2024 21:10:53 +0800 Subject: [PATCH] x --- .github/workflows/arm64.yml | 52 ++++++++++++++++++++++++++++++++++ .github/workflows/armv7.yml | 53 +++++++++++++++++++++++++++++++++++ .github/workflows/riscv64.yml | 52 ++++++++++++++++++++++++++++++++++ .github/workflows/x86_64.yml | 49 ++++++++++++++++++++++++++++++++ README.md | 3 +- build-riscv64.sh | 26 +++++++++++++++++ build-x86.sh | 11 ++++++++ build.sh | 22 +++++++++++++++ chroot-alpine.sh | 26 +++++++++++++++++ 9 files changed, 292 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/arm64.yml create mode 100644 .github/workflows/armv7.yml create mode 100644 .github/workflows/riscv64.yml create mode 100644 .github/workflows/x86_64.yml create mode 100644 build-riscv64.sh create mode 100644 build-x86.sh create mode 100644 build.sh create mode 100644 chroot-alpine.sh diff --git a/.github/workflows/arm64.yml b/.github/workflows/arm64.yml new file mode 100644 index 0000000..b731cd5 --- /dev/null +++ b/.github/workflows/arm64.yml @@ -0,0 +1,52 @@ +name: AARCH64 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + check_update: + name: Check update + runs-on: ubuntu-latest + steps: + - name: Check version + id: check_version + run: | + local_version=$(curl -L --header 'authorization: Bearer ${{ github.token }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + remote_version=$(curl -L https://api.github.com/repos/Moe-sushi/xz-static/releases/latest | jq -r .tag_name) + echo local_version=$local_version | tee -a $GITHUB_OUTPUT + echo remote_version=$remote_version | tee -a $GITHUB_OUTPUT + outputs: + local_version: ${{ steps.check_version.outputs.local_version }} + remote_version: ${{ steps.check_version.outputs.remote_version }} + build: + name: Build + needs: check_update + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Set env + run: | + echo remote_version=${{ needs.check_update.outputs.remote_version }} | tee -a $GITHUB_ENV + echo build_time=$(TZ=Asia/Shanghai date '+%Y%m%d%H%M') | tee -a $GITHUB_ENV + - uses: actions/checkout@v4 + - uses: uraimo/run-on-arch-action@v2 + name: Install packages + id: runcmd + with: + arch: aarch64 + distro: ubuntu_latest + run: | + bash chroot-alpine.sh + - name: Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.remote_version }} + body: | + Build time: ${{ env.build_time }} + prerelease: false + files: | + /home/runner/work/xz-static/xz-static/aarch64.tar diff --git a/.github/workflows/armv7.yml b/.github/workflows/armv7.yml new file mode 100644 index 0000000..b1ec409 --- /dev/null +++ b/.github/workflows/armv7.yml @@ -0,0 +1,53 @@ +name: ARMV7 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + check_update: + name: Check update + runs-on: ubuntu-latest + steps: + - name: Check version + id: check_version + run: | + local_version=$(curl -L --header 'authorization: Bearer ${{ github.token }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + remote_version=$(curl -L https://api.github.com/repos/Moe-sushi/xz-static/releases/latest | jq -r .tag_name) + echo local_version=$local_version | tee -a $GITHUB_OUTPUT + echo remote_version=$remote_version | tee -a $GITHUB_OUTPUT + outputs: + local_version: ${{ steps.check_version.outputs.local_version }} + remote_version: ${{ steps.check_version.outputs.remote_version }} + build: + name: Build + needs: check_update + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Set env + run: | + echo remote_version=${{ needs.check_update.outputs.remote_version }} | tee -a $GITHUB_ENV + echo build_time=$(TZ=Asia/Shanghai date '+%Y%m%d%H%M') | tee -a $GITHUB_ENV + - uses: actions/checkout@v4 + - uses: uraimo/run-on-arch-action@v2 + name: Install packages + id: runcmd + with: + arch: armv7 + distro: ubuntu_latest + run: | + bash chroot-alpine.sh + mv *.tar armv7.tar + - name: Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.remote_version }} + body: | + Build time: ${{ env.build_time }} + prerelease: false + files: | + /home/runner/work/xz-static/xz-static/armv7.tar diff --git a/.github/workflows/riscv64.yml b/.github/workflows/riscv64.yml new file mode 100644 index 0000000..7809edd --- /dev/null +++ b/.github/workflows/riscv64.yml @@ -0,0 +1,52 @@ +name: RISCV64 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + check_update: + name: Check update + runs-on: ubuntu-latest + steps: + - name: Check version + id: check_version + run: | + local_version=$(curl -L --header 'authorization: Bearer ${{ github.token }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + remote_version=$(curl -L https://api.github.com/repos/Moe-sushi/xz-static/releases/latest | jq -r .tag_name) + echo local_version=$local_version | tee -a $GITHUB_OUTPUT + echo remote_version=$remote_version | tee -a $GITHUB_OUTPUT + outputs: + local_version: ${{ steps.check_version.outputs.local_version }} + remote_version: ${{ steps.check_version.outputs.remote_version }} + build: + name: Build + needs: check_update + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Set env + run: | + echo remote_version=${{ needs.check_update.outputs.remote_version }} | tee -a $GITHUB_ENV + echo build_time=$(TZ=Asia/Shanghai date '+%Y%m%d%H%M') | tee -a $GITHUB_ENV + - uses: actions/checkout@v4 + - uses: uraimo/run-on-arch-action@v2 + name: Install packages + id: runcmd + with: + arch: riscv64 + distro: ubuntu_latest + run: | + bash build-riscv64.sh + - name: Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.remote_version }} + body: | + Build time: ${{ env.build_time }} + prerelease: false + files: | + /home/runner/work/xz-static/xz-static/riscv64.tar diff --git a/.github/workflows/x86_64.yml b/.github/workflows/x86_64.yml new file mode 100644 index 0000000..8645b9f --- /dev/null +++ b/.github/workflows/x86_64.yml @@ -0,0 +1,49 @@ +name: X86_64 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + check_update: + name: Check update + runs-on: ubuntu-latest + steps: + - name: Check version + id: check_version + run: | + local_version=$(curl -L --header 'authorization: Bearer ${{ github.token }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + remote_version=$(curl -L https://api.github.com/repos/Moe-sushi/xz-static/releases/latest | jq -r .tag_name) + echo local_version=$local_version | tee -a $GITHUB_OUTPUT + echo remote_version=$remote_version | tee -a $GITHUB_OUTPUT + outputs: + local_version: ${{ steps.check_version.outputs.local_version }} + remote_version: ${{ steps.check_version.outputs.remote_version }} + build: + name: Build + needs: check_update + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Set env + run: | + echo remote_version=${{ needs.check_update.outputs.remote_version }} | tee -a $GITHUB_ENV + echo build_time=$(TZ=Asia/Shanghai date '+%Y%m%d%H%M') | tee -a $GITHUB_ENV + - uses: actions/checkout@v4 + - name: Install packages + run: | + sudo bash chroot-alpine.sh + - name: Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.remote_version }} + body: | + This is ruri binary release. + Build time: ${{ env.build_time }} + prerelease: false + files: | + /home/runner/work/xz-static/xz-static/x86_64.tar + /home/runner/work/xz-static/xz-static/i386.tar diff --git a/README.md b/README.md index 2a3e96b..c96682c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# xz-static -xz static binary for aarch64, armv7, x86_64, i386 and riscv64 +xz static binary \ No newline at end of file diff --git a/build-riscv64.sh b/build-riscv64.sh new file mode 100644 index 0000000..803b382 --- /dev/null +++ b/build-riscv64.sh @@ -0,0 +1,26 @@ +apt update +apt install -y sudo +sudo apt install -y git wget +yes|sudo apt install --no-install-recommends -y curl xz-utils \ + make \ + clang \ + libseccomp-dev \ + libcap-dev \ + libc6-dev \ + binutils + +BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/riscv64" +ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs"|grep "riscv64.tar.gz" | head -n 1|awk '{print $2}') +FULL_URL="$BASE_URL/$ROOTFS_URL" +wget "$FULL_URL" +mkdir alpine +tar -xvf "$ROOTFS_URL" -C alpine +git clone https://github.com/moe-hacker/ruri +cd ruri +cc -Wl,--gc-sections -static src/*.c src/easteregg/*.c -o ruri -lcap -lseccomp -lpthread +cd .. +sudo cp file.c alpine/file.c +sudo cp build.sh alpine/build.sh +sudo chmod +x alpine/build.sh +sudo ./ruri/ruri ./alpine /bin/sh /build.sh +cp alpine/$(uname -m).tar . \ No newline at end of file diff --git a/build-x86.sh b/build-x86.sh new file mode 100644 index 0000000..6d3dbe3 --- /dev/null +++ b/build-x86.sh @@ -0,0 +1,11 @@ +BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/x86" +ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs"|grep "x86.tar.gz" | head -n 1|awk '{print $2}') +FULL_URL="$BASE_URL/$ROOTFS_URL" +wget "$FULL_URL" +mkdir x86 +tar -xvf "$ROOTFS_URL" -C x86 +sudo cp file.c x86/file.c +sudo cp build.sh x86/build.sh +sudo chmod +x x86/build.sh +sudo ./ruri/ruri ./x86 /bin/sh /build.sh +cp x86/*.tar ./i386.tar \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..c503cd0 --- /dev/null +++ b/build.sh @@ -0,0 +1,22 @@ +rm /etc/resolv.conf +echo nameserver 1.1.1.1 > /etc/resolv.conf +echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories +apk add wget make clang git xz-dev libintl libbsd-static libsemanage-dev libselinux-utils libselinux-static xz-libs zlib zlib-static libselinux-dev linux-headers libssl3 libbsd libbsd-dev gettext-libs gettext-static gettext-dev gettext python3 build-base openssl-misc openssl-libs-static openssl zlib-dev xz-dev openssl-dev automake libtool bison flex gettext autoconf gettext sqlite sqlite-dev pcre-dev wget texinfo docbook-xsl libxslt docbook2x musl-dev gettext gettext-asprintf gettext-dbg gettext-dev gettext-doc gettext-envsubst gettext-lang gettext-libs gettext-static +apk add upx +mkdir output + +# OK +git clone https://github.com/xz-mirror/xz +cd xz +autoreconf -fi +./autogen.sh +./configure LDFLAGS="-static" --enable-static --disable-shared +make -j8 LDFLAGS="--static" +strip src/xz/xz +upx src/xz/xz +cp src/xz/xz ../output/ +cp COPYING ../output/LICENSE-xz +cd .. +cd output +tar -cvf ../$(uname -m).tar . +exit 0 diff --git a/chroot-alpine.sh b/chroot-alpine.sh new file mode 100644 index 0000000..ebfe386 --- /dev/null +++ b/chroot-alpine.sh @@ -0,0 +1,26 @@ +apt update +apt install -y sudo +sudo apt install -y git wget +yes|sudo apt install --no-install-recommends -y curl xz-utils \ + make \ + clang \ + libseccomp-dev \ + libcap-dev \ + libc6-dev \ + binutils +git clone https://github.com/moe-hacker/rootfstool +rootfstool/rootfstool d -d alpine -v edge +mkdir alpine +sudo tar -xvf rootfs.tar.xz -C alpine +git clone https://github.com/moe-hacker/ruri +cd ruri +cc -Wl,--gc-sections -static src/*.c src/easteregg/*.c -o ruri -lcap -lseccomp -lpthread +cd .. +sudo cp file.c alpine/file.c +sudo cp build.sh alpine/build.sh +sudo chmod +x alpine/build.sh +sudo ./ruri/ruri ./alpine /bin/sh /build.sh +cp alpine/$(uname -m).tar . +if [[ $(uname -m) == "amd64" ]]||[[ $(uname -m) == "x86_64" ]]; then + bash build-x86.sh +fi \ No newline at end of file