generic-appimage.sh 3.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh -x
# It will run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"

PRODUCT="$(grep "^Name: " $SPEC | sed -e "s|Name: ||g" | head -n1)"
PRODUCTDIR=/opt/$PRODUCT

. $(dirname $0)/common.sh

# move package to /opt
ROOTDIR=$(basename $(find $BUILDROOT -mindepth 1 -maxdepth 1 -type d))
13
move_to_opt /$ROOTDIR
14 15 16

fix_chrome_sandbox

17

18
cd $BUILDROOT$PRODUCTDIR
19 20 21

# TODO
if false ; then
22 23 24 25

# /opt/whatsapp-for-linux/usr/lib/ssl/certs -> /etc/ssl/certs
# /opt/whatsapp-for-linux/usr/lib/ssl/private -> /etc/ssl/private

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# on whatsapp-for-linux example
epm assure patchelf || exit
# hack for
# ldd: ERROR: /var/tmp/tmp.kroKx0mR2G/whatsapp-for-linux-1.5.1-x86_64.AppImage.tmpdir/whatsapp-for-linux--1.5.1/opt/whatsapp-for-linux-/bin/systemd-hwdb: program interpreter /tmp/appimage-fcba8c70-fea2-41f2-8775-57ce8e19ffe9-ld-linux-x86-64.so.2 not found
find -executable -type f | while read elf ; do
    file $elf | grep -q "ELF 64-bit.*interpreter" || continue
    file $elf | grep -q "interpreter /lib64/ld-linux-x86-64.so.2" && continue
    a= patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $elf
done

for i in usr/lib/x86_64-linux-gnu/*.so* lib/x86_64-linux-gnu/*.so* lib/x86_64-linux-gnu/security/*.so* opt/libc/lib/x86_64-linux-gnu/libc.so.6  ; do
    [ -s "$i" ] || continue
    a= patchelf --set-rpath '$ORIGIN:$ORIGIN/..:$ORIGIN/../../usr/lib/x86_64-linux-gnu:$ORIGIN/../../../usr/lib/x86_64-linux-gnu:' "$i"
    file $i | grep -q "ELF 64-bit.*interpreter" || continue
    file $i | grep -q "interpreter /lib64/ld-linux-x86-64.so.2" && continue
    a= patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $i
done
fi

45
DESKTOPFILE="$(echo *.desktop | head -n1)"
46

47
FROMICONFILE=''
48
ICONNAME=$PRODUCT
49

50 51 52 53
if [ -r "$DESKTOPFILE" ] ; then
    mkdir -p $BUILDROOT/usr/share/applications/
    cat $DESKTOPFILE | sed -e "s|AppRun|$PRODUCT|" -e 's|X-AppImage-Integrate.*||' > $BUILDROOT/usr/share/applications/$DESKTOPFILE
    pack_file /usr/share/applications/$DESKTOPFILE
54

55
    ICONNAME="$(cat $DESKTOPFILE | grep "^Icon=" | head -n1 | sed -e 's|Icon=||')"
56
    FROMICONFILE="$ICONNAME.png"
57

58
    EXEC="$(cat $BUILDROOT/usr/share/applications/$DESKTOPFILE | grep "^Exec=" | head -n1 | sed -e 's|Exec=||' -e 's| .*||')"
59 60 61 62 63 64

    if [ -n "$EXEC" ] && [ "$PRODUCT" != "$EXEC" ] ; then
        PRODUCTCUR="$EXEC"
        add_bin_link_command $PRODUCTCUR $PRODUCT
    fi

65 66
fi

67 68
[ -n "$ICONNAME" ] || fatal "Couldn't retrieve icon name from $DESKTOPFILE"

69
ICONFILE=$ICONNAME.png
70

71 72 73 74 75 76 77
# it is strange, there is no icon file
# https://docs.appimage.org/reference/appdir.html
if [ ! -s "$FROMICONFILE" ] ; then
    FROMICONFILE=".DirIcon"
    grep -q "^<svg" $FROMICONFILE && ICONFILE="$PRODUCT.svg"
fi
install_file $PRODUCTDIR/$FROMICONFILE /usr/share/pixmaps/$ICONFILE
78

79 80 81 82 83 84
# copy icons if possible
for i in usr/share/icons/hicolor/*x*/apps/* ; do
    [ -f "$i" ] || continue
    install_file $PRODUCTDIR/$i /$i
done

85 86 87
# hack for remove MacOS only stuffs
remove_dir $(find $BUILDROOT -type d -name "*catalina*" | sed -e "s|$BUILDROOT||")

88
add_bin_cdexec_command $PRODUCT $PRODUCTDIR/AppRun
89 90
# Strange AppRun script uses args as path, so override path detection
subst "2iexport APPDIR=$PRODUCTDIR" $BUILDROOT/usr/bin/$PRODUCT
91

92
if [ -f v8_context_snapshot.bin ] ; then
93
    echo "electron based application detected, adding requires ..."
94 95 96 97 98
    . $(dirname $0)/common-chromium-browser.sh
    # don't use install: we disabled AutoReq before
    add_deps
fi

99 100
# ignore embedded libs
drop_embedded_reqs