diff --git a/dist/AppImage/AppRun b/dist/AppImage/AppRun deleted file mode 100644 index 2f9426cc2..000000000 --- a/dist/AppImage/AppRun +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -SELF=$(readlink -f "$0") -HERE=${SELF%/*} -export PATH="${HERE}/usr/bin/:${HERE}/usr/sbin/:${HERE}/usr/games/:${HERE}/bin/:${HERE}/sbin/${PATH:+:$PATH}" -export LD_LIBRARY_PATH="${HERE}/usr/lib/:${HERE}/usr/lib/i386-linux-gnu/:${HERE}/usr/lib/x86_64-linux-gnu/:${HERE}/usr/lib32/:${HERE}/usr/lib64/:${HERE}/lib/:${HERE}/lib/i386-linux-gnu/:${HERE}/lib/x86_64-linux-gnu/:${HERE}/lib32/:${HERE}/lib64/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" -export PYTHONPATH="${HERE}/usr/share/pyshared/${PYTHONPATH:+:$PYTHONPATH}" -export XDG_DATA_DIRS="${HERE}/usr/share/${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" -export PERLLIB="${HERE}/usr/share/perl5/:${HERE}/usr/lib/perl5/${PERLLIB:+:$PERLLIB}" -export GSETTINGS_SCHEMA_DIR="${HERE}/usr/share/glib-2.0/schemas/${GSETTINGS_SCHEMA_DIR:+:$GSETTINGS_SCHEMA_DIR}" -export QT_PLUGIN_PATH="${HERE}/usr/lib/qt4/plugins/:${HERE}/usr/lib/i386-linux-gnu/qt4/plugins/:${HERE}/usr/lib/x86_64-linux-gnu/qt4/plugins/:${HERE}/usr/lib32/qt4/plugins/:${HERE}/usr/lib64/qt4/plugins/:${HERE}/usr/lib/qt5/plugins/:${HERE}/usr/lib/i386-linux-gnu/qt5/plugins/:${HERE}/usr/lib/x86_64-linux-gnu/qt5/plugins/:${HERE}/usr/lib32/qt5/plugins/:${HERE}/usr/lib64/qt5/plugins/${QT_PLUGIN_PATH:+:$QT_PLUGIN_PATH}" -EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 1) -exec "${EXEC}" "$@" diff --git a/dist/AppImage/Dockerfile b/dist/AppImage/Dockerfile index d52b3754e..1fe4dc626 100644 --- a/dist/AppImage/Dockerfile +++ b/dist/AppImage/Dockerfile @@ -2,6 +2,7 @@ FROM debian:bullseye-slim LABEL maintainer Example ARG TAG=master +ARG REPO=https://github.com/WerWolv/ImHex.git USER root @@ -13,13 +14,12 @@ RUN apt-get update \ git \ cmake \ curl \ - libfuse2 \ - file + squashfs-tools # Fetch source and dependencies RUN mkdir -p /source \ && cd /source \ - && git clone https://github.com/WerWolv/ImHex.git \ + && git clone $REPO \ && cd ImHex \ && git checkout $TAG \ && git submodule update --init --recursive \ @@ -35,27 +35,6 @@ RUN mkdir -p /source/ImHex/build \ && make -j # Prepare for AppImage -RUN mkdir -p /source/ImHex.AppDir/usr/bin \ - && mkdir -p /source/ImHex.AppDir/usr/lib \ - && mkdir -p /source/ImHex.AppDir/usr/share/imhex/plugins \ - && cp /source/ImHex/build/imhex /source/ImHex.AppDir/usr/bin/imhex \ - && cp /source/ImHex/build/plugins/builtin/builtin.hexplug /source/ImHex.AppDir/usr/share/imhex/plugins - -COPY AppRun ImHex.desktop imhex.png /source/ImHex.AppDir/ -#RUN inkscape -z -o /source/ImHex.AppDir/imhex.png -w 128 -h 128 /source/ImHex/res/icon.svg - -# Gather the needed libraries -RUN chmod a+x /source/ImHex.AppDir/AppRun \ - && ldd /source/ImHex/build/imhex | awk '/ => /{print $3}' | xargs -I '{}' cp '{}' /source/ImHex.AppDir/usr/lib - -# Package the prepared AppDir -RUN cd /source \ - && curl -L https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-x86_64.AppImage -o appimagetool-x86_64.AppImage \ - && chmod a+x appimagetool-x86_64.AppImage - -# All that remains is the following. However, due to docker limitations with fuse -# this cannot be done in a build container. -# -# /source/appimagetool-x86_64.AppImage ImHex.AppDir - -ENTRYPOINT sh -c '/source/appimagetool-x86_64.AppImage /source/ImHex.AppDir; sleep 60' +RUN cd /source/ImHex/dist/AppImage \ + && ./package.sh /source/ImHex/build \ + && mv /source/ImHex/build/ImHex-x86_64.AppImage / diff --git a/dist/AppImage/README.md b/dist/AppImage/README.md index 15a701ee2..bbda0ab18 100644 --- a/dist/AppImage/README.md +++ b/dist/AppImage/README.md @@ -1,3 +1,22 @@ -The environment variable TAG can be set to build for a specific git tag. Without the master branch is build. +# Building an AppImage +There are two ways of building an AppImage for ImHex, using the provided +tools here. -First run `build.sh` to create a docker image. Then run `extract.sh` to get an AppImage. +If you want to create an AppImage and do not have a build to work from +already, you can use docker to build ImHex and package an AppImage. + +Alternatively you can create an AppImage using an existing build. + +## Using docker +First run `build.sh` to create a docker image. Then run `extract.sh` to get the +AppImage out. This needs to be in two steps, as a docker build cannot copy +files out. Nor can docker build use volume mounts. + +The environment variable TAG can be set to build for a specific git tag. +Without the master branch is build. + +## Using an existing build +Run `package.sh` with the build dir as an argument. E.g.: +``` +./package.sh ../../build +``` diff --git a/dist/AppImage/build.sh b/dist/AppImage/build.sh index 9a90ccc4c..0c0561270 100755 --- a/dist/AppImage/build.sh +++ b/dist/AppImage/build.sh @@ -1,14 +1,16 @@ #!/bin/bash # Set the TAG environment variable to build a specific tag +# Set the REPO environment variable to point at a different git repository -# Make sure we're in the same direcotry as this script +# Make sure we're in the same directory as this script pushd $(dirname "$(realpath "$0")") -if [ -z "$TAG" ]; then - docker build -t imhex-appimage-build . -else - docker build --build-arg=TAG=$TAG -t imhex-appimage-build-$TAG . -fi +BUILDARG="" +SUFFIX="" +[ -n "${TAG}" ] && BUILDARG="${BUILDARG} --build-arg=TAG=${TAG}" && SUFFIX=":${TAG}" +[ -n "${REPO}" ] && BUILDARG="${BUILDARG} --build-arg=REPO=${REPO}" + +docker build ${BUILDARG} -t imhex-appimage-build${SUFFIX} . popd diff --git a/dist/AppImage/extract.sh b/dist/AppImage/extract.sh index 3c43e74bf..298a8c299 100755 --- a/dist/AppImage/extract.sh +++ b/dist/AppImage/extract.sh @@ -2,25 +2,25 @@ # Set the TAG environment variable to move to a versioned name while extracting -# Make sure we're in the same direcotry as this script +# Make sure we're in the same directory as this script pushd $(dirname "$(realpath "$0")") +SUFFIX="" +[ -n "$TAG" ] && SUFFIX=":$TAG" + # Remove old containers docker rm imhex 2>&1 > /dev/null -# AppImage uses FUSE, which makes --device /dev/fuse --cap-add SYS_ADMIN necessary here -# on Debian --security-opt apparmor:unconfined is also needed -if [ -z "$TAG" ]; then - docker run -d --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined --name imhex imhex-appimage-build -else - docker run -d --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined --name imhex imhex-appimage-build-$TAG -fi -sleep 10 +docker run -d --name imhex imhex-appimage-build${SUFFIX} sleep 30 & +sleep 15 docker cp imhex:/ImHex-x86_64.AppImage . # Move to tagged name if $TAG set if [ -n "$TAG" ]; then mv ImHex-x86_64.AppImage ImHex-${TAG}-x86_64.AppImage + echo -e "\nThe created AppImage can be found here:\n $(pwd)/ImHex-${TAG}-x86_64.AppImage\n\n" +else + echo -e "\nThe created AppImage can be found here:\n $(pwd)/ImHex-x86_64.AppImage\n\n" fi popd diff --git a/dist/AppImage/package.sh b/dist/AppImage/package.sh new file mode 100755 index 000000000..39edbf42d --- /dev/null +++ b/dist/AppImage/package.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -e # Exit on error +set -o pipefail # Bash specific + +usage() { + echo "Tool to package an ImHex build into an AppImage" + echo + echo "Usage:" + echo "$0 " + echo + exit +} + +MYDIR=$(dirname "$(realpath "$0")") + +# Check is a build dir has been specified and it's a dir +[ -z "$1" ] && usage +[ -d "$1" ] || usage + +set -u # Throw errors when unset variables are used + +BUILDDIR=$1 +APPDIR=${BUILDDIR}/ImHex.AppDir +APPIMAGE=${BUILDDIR}/ImHex-x86_64.AppImage + +# Prepare for AppImage +## Fetch the needed AppImage binaries +curl -L https://github.com/AppImage/AppImageKit/releases/download/13/AppRun-x86_64 -o ${MYDIR}/AppRun-x86_64 +curl -L https://github.com/AppImage/AppImageKit/releases/download/13/runtime-x86_64 -o ${MYDIR}/runtime-x86_64 + +## Setup directory structure +mkdir -p ${BUILDDIR}/ImHex.AppDir/usr/{bin,lib} ${BUILDDIR}/ImHex.AppDir/usr/share/imhex/plugins + +## Add ImHex files to structure +cp ${BUILDDIR}/imhex ${APPDIR}/usr/bin +cp ${BUILDDIR}/plugins/builtin/builtin.hexplug ${APPDIR}/usr/share/imhex/plugins +cp ${MYDIR}/{AppRun-x86_64,ImHex.desktop,imhex.png} ${APPDIR}/ +mv ${BUILDDIR}/ImHex.AppDir/AppRun-x86_64 ${APPDIR}/AppRun +chmod a+x ${BUILDDIR}/ImHex.AppDir/AppRun + +## Add all dependencies +ldd ${BUILDDIR}/imhex | awk '/ => /{print $3}' | xargs -I '{}' cp '{}' ${APPDIR}/usr/lib + +# Package it up as described here: +# https://github.com/AppImage/AppImageKit#appimagetool-usage +# under 'If you want to generate an AppImage manually' +# This builds a v2 AppImage according to +# https://github.com/AppImage/AppImageSpec/blob/master/draft.md#type-2-image-format +mksquashfs ${APPDIR} ${BUILDDIR}/ImHex.squashfs -root-owned -noappend +cat ${MYDIR}/runtime-x86_64 > ${APPIMAGE} +cat ${BUILDDIR}/ImHex.squashfs >> ${APPIMAGE} +chmod a+x ${APPIMAGE} + +if [ ! -f /.dockerenv ]; then + echo -e "\nThe created AppImage can be found here:\n ${APPIMAGE}\n\n" +fi