generic-appimage.sh 3.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/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

11 12
[ "$PRODUCT" = "AppImage" ] && fatal "Can't recognize correct package name ($PRODUCT is incorrect name)"

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

fix_chrome_sandbox

19

20
cd $BUILDROOT$PRODUCTDIR
21 22 23

# TODO
if false ; then
24 25 26 27

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

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
# 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

47
DESKTOPFILE="$(echo *.desktop | head -n1)"
48

49
FROMICONFILE=''
50
ICONNAME=$PRODUCT
51

52 53 54 55
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
56

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

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

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

67 68
fi

69 70 71 72 73 74 75 76 77 78
if [ -n "$ICONNAME" ] ; then
    ICONFILE=$ICONNAME.png

    # 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
79
fi
80

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

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

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

94 95
PRODUCTCUR="$(echo $PRODUCT | tr "[A-Z_]" "[a-z-]")"
[ "$PRODUCT" = "$PRODUCTCUR" ] || add_bin_link_command $PRODUCTCUR $PRODUCT