Chris@700: #!/bin/bash Chris@700: Chris@700: set -eu Chris@700: Chris@700: program=EasyMercurial Chris@700: Chris@700: get_id() { Chris@700: if [ -d .hg ]; then Chris@700: hg id | sed 's/[+ ].*$//' Chris@700: elif [ -d .git ]; then Chris@700: git rev-parse --short HEAD Chris@700: else Chris@700: echo "WARNING: can't figure out revision from VCS metadata" 1>&2 Chris@700: echo "unknown" Chris@700: fi Chris@700: } Chris@700: Chris@700: version=$(get_id) Chris@700: Chris@700: if [ ! -x ./appimagetool-x86_64.AppImage ]; then Chris@700: echo "Failed to find executable ./appimagetool-x86_64.AppImage, please provide that first" Chris@700: exit 2 Chris@700: fi Chris@700: Chris@700: targetdir="${program}.AppDir" Chris@700: Chris@700: echo "Target dir is $targetdir" Chris@700: Chris@700: if [ -d "$targetdir" ]; then Chris@700: echo "Target directory exists, not overwriting" Chris@700: exit 2 Chris@700: fi Chris@700: Chris@700: mkdir "$targetdir" Chris@700: Chris@700: mkdir -p "$targetdir"/usr/bin Chris@700: mkdir -p "$targetdir"/usr/lib Chris@700: Chris@700: cp "$program" "$targetdir"/usr/bin/ Chris@700: Chris@700: add_dependencies() { Chris@700: Chris@700: local binary="$1" Chris@700: Chris@700: echo "ldd $binary yields:" Chris@700: ldd "$binary" Chris@700: Chris@700: for lib in $(ldd "$binary" | grep '=> [^ ]*/lib/' | \ Chris@700: sed 's/^.*=> //' | sed 's/ .*$//'); do Chris@700: Chris@700: base=$(basename "$lib") Chris@700: if grep -v '^#' deploy/linux/appimage-excludelist | Chris@700: grep -q "^$base$" ; then Chris@700: echo "excluding: $lib" Chris@700: continue Chris@700: fi Chris@700: Chris@700: target="$targetdir/usr/lib/$(basename $lib)" Chris@700: Chris@700: mkdir -p "$(dirname $target)" Chris@700: Chris@700: if [ ! -f "$target" ]; then Chris@700: Chris@700: cp -Lv "$lib" "$target" Chris@700: chmod +x "$target" Chris@700: Chris@700: add_dependencies "$lib" Chris@700: Chris@700: fi Chris@700: done Chris@700: } Chris@700: Chris@700: add_dependencies "$program" Chris@700: Chris@700: qtplugins="gif icns ico jpeg tga tiff wbmp webp cocoa minimal offscreen xcb" Chris@700: qtlibdirs="/usr/lib/x86_64-linux-gnu/qt5 /usr/lib/x86_64-linux-gnu/qt /usr/lib/qt5 /usr/lib/qt" Chris@700: Chris@700: QTDIR=${QTDIR:-} Chris@700: if [ -n "$QTDIR" ]; then Chris@700: qtlibdirs="$QTDIR $qtlibdirs" Chris@700: fi Chris@700: Chris@700: for plug in $qtplugins; do Chris@700: for libdir in $qtlibdirs; do Chris@700: lib=$(find $libdir/plugins -name libq$plug.so -print 2>/dev/null || true) Chris@700: if [ -n "$lib" ]; then Chris@700: if [ -f "$lib" ]; then Chris@700: subdir=$(basename $(dirname $lib)) Chris@700: if [ t"$subdir" = t"plugins" ]; then Chris@700: subdir="" Chris@700: fi Chris@700: target="$targetdir/usr/lib/qt5/plugins/$subdir/$(basename $lib)" Chris@700: mkdir -p "$(dirname $target)" Chris@700: cp -v "$lib" "$target" Chris@700: chmod +x "$target" Chris@700: add_dependencies "$lib" Chris@700: break Chris@700: fi Chris@700: fi Chris@700: done Chris@700: done Chris@700: Chris@700: cp "deploy/linux/$program.desktop" "$targetdir/" Chris@700: Chris@700: cp images/icon/scalable/easyhg-icon.svg "$targetdir/" Chris@700: cp images/icon/scalable/easyhg-icon.svg "$targetdir/$program.svg" Chris@700: cp images/icon/128/easyhg-icon.png "$targetdir/" Chris@700: Chris@700: cp "deploy/linux/AppRun" "$targetdir/" Chris@700: Chris@700: chmod +x "$targetdir/AppRun" Chris@700: Chris@700: # Do this with a separate extraction step, so as to make it work even Chris@700: # in situations where FUSE is unavailable like in a Docker container Chris@700: export ARCH=x86_64 Chris@700: ./appimagetool-x86_64.AppImage --appimage-extract Chris@700: ./squashfs-root/AppRun "$targetdir" "$program-$version-x86_64.AppImage"