From e3bc578d2cb4972df7777ff2cdceffbd3ae9ca02 Mon Sep 17 00:00:00 2001 From: Rot127 <45763064+Rot127@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:10:59 +0000 Subject: [PATCH] Move debian package generation to a dispatch only workflow (#2543) * Move deb package gen files int package/deb * Fix basename check * Make debian package generation dispatch only --- .github/workflows/build_deb.yml | 26 +++++++++++++++ .github/workflows/build_release.yml | 25 +------------- debian/postinst | 6 ---- {debian => packages/deb}/.gitignore | 0 {debian => packages/deb}/Dockerfile | 38 +++++++++------------- packages/deb/README.md | 7 ++++ {debian => packages/deb}/check_capstone.sh | 8 ++--- {debian => packages/deb}/control | 0 {debian => packages/deb}/setup.sh | 12 +++---- packages/deb/triggers | 2 ++ 10 files changed, 61 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/build_deb.yml delete mode 100644 debian/postinst rename {debian => packages/deb}/.gitignore (100%) rename {debian => packages/deb}/Dockerfile (52%) create mode 100644 packages/deb/README.md rename {debian => packages/deb}/check_capstone.sh (90%) mode change 100644 => 100755 rename {debian => packages/deb}/control (100%) rename {debian => packages/deb}/setup.sh (80%) mode change 100644 => 100755 create mode 100644 packages/deb/triggers diff --git a/.github/workflows/build_deb.yml b/.github/workflows/build_deb.yml new file mode 100644 index 000000000..3caf6a0c2 --- /dev/null +++ b/.github/workflows/build_deb.yml @@ -0,0 +1,26 @@ +name: Build Debian Package + +on: workflow_dispatch + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Build Debian Package + working-directory: ./packages/deb + run: ./setup.sh "$(git describe --tags --abbrev=0)" + + - name: Run sanity checks on the Debian package + working-directory: ./packages/deb + run: | + ./check_capstone.sh ./libcapstone-dev.deb "$(git describe --tags --abbrev=0)" + + - uses: actions/upload-artifact@v4 + with: + path: ./packages/deb/libcapstone-dev.deb diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index 1e66ef989..d818270ca 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -14,31 +14,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - - name: Make setup.sh and check_capstone.sh are executable - run: | - chmod +x debian/setup.sh - chmod +x debian/check_capstone.sh - - name: Build Debian Package - working-directory: ./debian - run: ./setup.sh ${{ github.event.release.tag_name }} - - - name: Run sanity checks on the Debian package - working-directory: ./debian - run: | - ./check_capstone.sh ./libcapstone-dev.deb ${{ github.event.release.tag_name }} - - - name: Upload debian package to release - uses: softprops/action-gh-release@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.event.release.tag_name }} - files: | - ./debian/*.deb - - - name: archive + - name: Create archive id: archive run: | VERSION=${{ github.event.release.tag_name }} diff --git a/debian/postinst b/debian/postinst deleted file mode 100644 index 35ec39b8a..000000000 --- a/debian/postinst +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# postinst script for capstone package -set -e - -# Update the shared library cache -ldconfig diff --git a/debian/.gitignore b/packages/deb/.gitignore similarity index 100% rename from debian/.gitignore rename to packages/deb/.gitignore diff --git a/debian/Dockerfile b/packages/deb/Dockerfile similarity index 52% rename from debian/Dockerfile rename to packages/deb/Dockerfile index c3fb4966c..ba833b187 100644 --- a/debian/Dockerfile +++ b/packages/deb/Dockerfile @@ -1,8 +1,7 @@ ARG VERSION="" -# Assume this is run from capstone/debian directory # Run in the root of the repo -# docker build -f ./debian/Dockerfile -t packager . +# docker build -f ./packages/deb/Dockerfile -t packager . FROM debian:bookworm-slim # Install necessary tools for packaging @@ -10,10 +9,10 @@ RUN apt-get -qq update && \ DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \ fakeroot dpkg-dev dos2unix cmake -# Copy your project files into the container +# Copy project files into the container RUN mkdir /capstone COPY . /capstone -WORKDIR /capstone/ +WORKDIR /capstone/ # Using cmake, see BUILDING.md file # For debug build change "Release" to "Debug" @@ -23,36 +22,29 @@ RUN cmake --build build # List files before cmake install # RUN find / -type f > /before-install.txt -# Run cmake install, by default everything goes into /usr/local -RUN cmake --install build +# Make directories as needed +RUN mkdir -p /package-root/usr/include/capstone/ +RUN mkdir -p /package-root/usr/lib/pkgconfig/ +RUN mkdir -p /package-root/usr/bin/ + +# Run cmake install +RUN cmake --install build --prefix /package-root/usr/ # List files after cmake install # RUN find / -type f > /after-install.txt -# Make directories as needed -RUN mkdir -p /package-root/usr/local/include/capstone/ -RUN mkdir -p /package-root/usr/local/lib/pkgconfig/ -RUN mkdir -p /package-root/usr/local/bin/ - -# Copy /usr/local/include/capstone/ to /package-root/usr/local/include/capstone/ and all other cases -RUN cp -r /usr/local/include/capstone/* /package-root/usr/local/include/capstone/ -RUN cp -r /usr/local/lib/libcapstone* /package-root/usr/local/lib/ -RUN cp -r /usr/local/lib/pkgconfig/capstone* /package-root/usr/local/lib/pkgconfig/ -RUN cp -r /usr/local/bin/cstool /package-root/usr/local/bin/ - # Create DEBIAN directory and control file -COPY ./debian/control /package-root/DEBIAN/control +COPY ./packages/deb/control /package-root/DEBIAN/control # Update capstone.pc file with the correct version and remove archs field # Update control file with the correct version ARG VERSION RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/DEBIAN/control -RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/local/lib/pkgconfig/capstone.pc -RUN sed -i "/^archs=/d" /package-root/usr/local/lib/pkgconfig/capstone.pc +RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/lib/pkgconfig/capstone.pc +RUN sed -i "/^archs=/d" /package-root/usr/lib/pkgconfig/capstone.pc -# Add postinst script to run ldconfig after installation -COPY ./debian/postinst /package-root/DEBIAN/postinst -RUN chmod 755 /package-root/DEBIAN/postinst +# Add triggers script to run ldconfig after installation +COPY ./packages/deb/triggers /package-root/DEBIAN/triggers # Build the package RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev.deb diff --git a/packages/deb/README.md b/packages/deb/README.md new file mode 100644 index 000000000..fc79aa4e0 --- /dev/null +++ b/packages/deb/README.md @@ -0,0 +1,7 @@ +Incomplete Debian package implementation. +It can be used to generate an easily installable Capstone, but misses a lot of +mandatory things to add it in the Debian repos (`debian/control` is incomplete, no dependencies added etc.). + +You can build the package by dispatching the `Build Debian Package` workflow or executing the commands in the `Dockerfile`. +It assumes the current commit is tagged and `"$(git describe --tags --abbrev=0)"` returns a valid version number. +The package is uploaded as artifact. diff --git a/debian/check_capstone.sh b/packages/deb/check_capstone.sh old mode 100644 new mode 100755 similarity index 90% rename from debian/check_capstone.sh rename to packages/deb/check_capstone.sh index bd0e39183..4460f4184 --- a/debian/check_capstone.sh +++ b/packages/deb/check_capstone.sh @@ -18,7 +18,7 @@ TEMP_DIR=$(mktemp -d) dpkg-deb -x "$DEB_FILE" "$TEMP_DIR" # Path to the capstone.pc file -CAPSTONE_PC="$TEMP_DIR/usr/local/lib/pkgconfig/capstone.pc" +CAPSTONE_PC="$TEMP_DIR/usr/lib/pkgconfig/capstone.pc" # Check if the capstone.pc file exists if [[ ! -f "$CAPSTONE_PC" ]]; then @@ -48,7 +48,7 @@ if [[ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]]; then fi # Check if libcapstone.a is included in the package -LIBCAPSTONE_A="$TEMP_DIR/usr/local/lib/libcapstone.a" +LIBCAPSTONE_A="$TEMP_DIR/usr/lib/libcapstone.a" if [[ ! -f "$LIBCAPSTONE_A" ]]; then echo "libcapstone.a not found in the package!" rm -rf "$TEMP_DIR" @@ -56,7 +56,7 @@ if [[ ! -f "$LIBCAPSTONE_A" ]]; then fi # Check if libcapstone.so is included in the package -LIBCAPSTONE_SO="$TEMP_DIR/usr/local/lib/libcapstone.so" +LIBCAPSTONE_SO="$TEMP_DIR/usr/lib/libcapstone.so" if [[ ! -f "$LIBCAPSTONE_SO" ]]; then echo "libcapstone.so not found in the package!" rm -rf "$TEMP_DIR" @@ -65,4 +65,4 @@ fi echo "libcapstone-dev.deb file is correct." rm -rf "$TEMP_DIR" -exit 0 \ No newline at end of file +exit 0 diff --git a/debian/control b/packages/deb/control similarity index 100% rename from debian/control rename to packages/deb/control diff --git a/debian/setup.sh b/packages/deb/setup.sh old mode 100644 new mode 100755 similarity index 80% rename from debian/setup.sh rename to packages/deb/setup.sh index c02212ef0..a3595dfd2 --- a/debian/setup.sh +++ b/packages/deb/setup.sh @@ -6,9 +6,9 @@ get_os_version() { lsb_release -i -s 2>/dev/null } -# Check if the script is running in the ./debian folder -if [[ $(basename "$PWD") != "debian" ]]; then - echo "ERROR: Script must be run from the ./debian directory" +# Check if the script is running in the ./packages/deb folder +if [[ $(basename "$PWD") != "deb" ]]; then + echo "ERROR: Script must be run from the ./deb directory" exit 1 fi @@ -40,8 +40,8 @@ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then fi # Now build the packager container from that -pushd ../ -docker build -f ./debian/Dockerfile -t packager --build-arg VERSION="${version}" . +pushd ../../ +docker build -f ./packages/deb/Dockerfile -t packager --build-arg VERSION="${version}" . popd # Copy deb file out of container to host @@ -50,4 +50,4 @@ docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out" # Check which files existed before and after 'make install' was executed. # docker run --rm -v $(pwd):/out packager bash -c "cp /before-install.txt /out" # docker run --rm -v $(pwd):/out packager bash -c "cp /after-install.txt /out" -# diff before-install.txt after-install.txt \ No newline at end of file +# diff before-install.txt after-install.txt diff --git a/packages/deb/triggers b/packages/deb/triggers new file mode 100644 index 000000000..eafa63be7 --- /dev/null +++ b/packages/deb/triggers @@ -0,0 +1,2 @@ +# Trigger ldconfig after install +activate-noawait ldconfig