Merge pull request #475 from th-otto/PR-2
[appimagekit/gsi.git] / testappimage
blob0a0e4efd9c6ee2dd44bf2fc1242cabe5740b3813
1 #!/bin/bash
4 # Test an AppDir or AppImage on a given ISO or squashfs or ext3 base system
5 # TODO:
6 # - Make compatible with type 2 AppImages (currently we have to first mount them by hand)
7 # - Check https://github.com/FGrose/livecd-tools/blob/liveimage-mount/tools/liveimage-mount
10 set -e
11 # set -x
13 HERE=$(dirname $(readlink -f "${0}"))
14 export PATH=$HERE:$HERE/usr/bin:$PATH
16 if [ "$1x" == "x" ] ; then
17 echo "Please specify a ISO or squashfs base system to run the AppImage on"
18 exit 1
21 if [ "$2x" == "x" ] ; then
22 echo "Please specify an AppDir or AppImage outside the ISO or command inside the ISO to be run"
23 exit 1
26 export PREF=$RANDOM
28 mkdir -p /tmp/$PREF/unionfs/ro
29 mkdir -p /tmp/$PREF/unionfs/root
30 mkdir -p /tmp/$PREF/unionfs/rw
31 mkdir -p /tmp/$PREF/union
32 mkdir -p /tmp/$PREF/iso
33 mkdir -p /tmp/$PREF/workdir
35 # openSUSE LEAP 42.2 does not have a tmpfs in /tmp but we need this
36 mount | grep "/tmp type tmpfs" && sudo mount -t tmpfs tmpfs /tmp/
38 # If ISO was specified, then mount it and find contained filesystem
39 THEFS="$1"
40 if [ ${1: -4} == ".iso" ] ; then
41 ISO="$1"
42 mount -o loop,ro "$ISO" /tmp/$PREF/iso
43 # If there is a squashfs file named $ISO.buildsquash then we overlay-
44 # mount this as well. This can significantly speed up subsequent builds
45 # because dependencies can be installed there. The squashfs file can be
46 # generated by squashing the unionfs/rw directory.
47 if [ -e $ISO.buildsquash ] ; then
48 mount -o loop,ro "$ISO.buildsquash" /tmp/$PREF/unionfs/ro
52 # If sfs was provided, then assume it contains a rootfs use just that
53 THEFS="$1"
54 if [ ${1: -4} == ".sfs" ] ; then
55 ISO="$1"
56 mount -o loop,ro "$ISO" /tmp/$PREF/unionfs/root
59 # If ext3 was provided, then assume it contains a rootfs use just that
60 THEFS="$1"
61 if [ ${1: -4} == "ext3" ] ; then
62 ISO="$1"
63 mount -o loop,ro "$ISO" /tmp/$PREF/unionfs/root
66 echo ""
67 echo "===================================================="
68 echo ""
69 echo $ISO
71 # In case of Ubuntu-like ISOs
72 if [ -e /tmp/$PREF/iso/casper/filesystem.squashfs ] ; then
73 THEFS=/tmp/$PREF/iso/casper/filesystem.squashfs
74 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
77 # In case of Fedora-like ISOs
78 if [ -e /tmp/$PREF/iso/LiveOS/squashfs.img ] ; then
79 mount -o loop,ro /tmp/$PREF/iso/LiveOS/squashfs.img /tmp/$PREF/iso/
80 if [ -e /tmp/$PREF/iso/LiveOS/ext3fs.img ] ; then
81 # F23 and below use https://github.com/rhinstaller/livecd-tools
82 THEFS=/tmp/$PREF/iso/LiveOS/ext3fs.img || exit 1
84 if [ -e /tmp/$PREF/iso/LiveOS/rootfs.img ] ; then
85 # F24 and above use https://github.com/rhinstaller/lorax and livemedia-creator
86 THEFS=/tmp/$PREF/iso/LiveOS/rootfs.img || exit 1
88 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
91 # In case of debian-like ISOs
92 if [ -e /tmp/$PREF/iso/live/filesystem.squashfs ] ; then
93 THEFS=/tmp/$PREF/iso/live/filesystem.squashfs
94 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
97 # In case of openSUSE-like ISOs
98 if [ -e /tmp/$PREF/iso/*-read-only.* ] ; then
99 THEFS=$(ls /tmp/$PREF/iso/*-read-only.* | head -n 1)
100 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
103 # In case of puppy-like ISOs
104 if [ -e /tmp/$PREF/iso/puppy_*.sfs ] ; then
105 THEFS=$(ls /tmp/$PREF/iso/puppy_*.sfs | head -n 1)
106 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
109 trap atexit EXIT
111 atexit()
112 { set +e
113 umount -l /tmp/$PREF/union/var/lib/dbus 2>/dev/null
114 umount -l /tmp/$PREF/union/etc/resolv.conf 2>/dev/null
115 umount -l /tmp/$PREF/union/proc 2>/dev/null
116 umount -l /tmp/$PREF/union/dev 2>/dev/null
117 umount -l /tmp/$PREF/union/mnt 2>/dev/null
118 umount -l /tmp/$PREF/union 2>/dev/null
119 umount -l /tmp/$PREF/unionfs/ro 2>/dev/null
120 umount -l /tmp/$PREF/unionfs/root 2>/dev/null
121 umount -l /tmp/$PREF/iso 2>/dev/null
122 umount -l /tmp/$PREF/iso 2>/dev/null
123 umount -l /tmp/$PREF/iso 2>/dev/null
124 rm -r /tmp/$PREF/workdir
125 rm -r /tmp/$PREF/unionfs/root
126 rm -r /tmp/$PREF/unionfs/rw
127 rm -r /tmp/$PREF/unionfs/ro
128 rm -r /tmp/$PREF/unionfs
129 rm -r /tmp/$PREF/union
130 rm -r /tmp/$PREF/iso
131 rm -r /tmp/$PREF/
134 # Kernel 4.0 or newer required
135 kernel_major=$(uname -r | cut -d . -f 1)
136 if [ ! $kernel_major -ge 4 ] ; then
137 echo "Falling back to unionfs-fuse because kernel is not 4.x or newer"
138 echo "This can potentially be unreliable"
139 unionfs-fuse -o allow_other,use_ino,suid,dev,nonempty -ocow,chroot=/tmp/$PREF/unionfs/,max_files=32768 /rw=RW:/ro=RO:/root=RO /tmp/$PREF/union
140 else
141 echo "Using OverlayFS because kernel is 4.x or newer"
142 sudo mount -t overlay -o lowerdir=/tmp/$PREF/unionfs/ro:/tmp/$PREF/unionfs/root,upperdir=/tmp/$PREF/unionfs/rw,workdir=/tmp/$PREF/workdir none /tmp/$PREF/union
145 ls /tmp/$PREF/union/mnt >/dev/null && MNT=/mnt
146 # ls /tmp/$PREF/union/automake >/dev/null && MNT=/automake || echo "" # Puppy
148 if [ "x$MNT" == "x" ] ; then
149 echo "Could not find free mountpoint"
150 exit 1
152 if [ -f "$2" ] ; then
153 mount "$2" /tmp/$PREF/union/$MNT -o loop,ro
154 elif [ -d "$2" ] ; then
155 mount "$2" /tmp/$PREF/union/$MNT -o bind
156 else
157 shift
158 export RUN_COMMAND=$1
159 export RUN_INSIDE=$@
162 cat > /tmp/$PREF/union/run.sh <<EOF
163 #!/bin/sh
164 cat /etc/*release
165 echo ""
166 rm -rf /etc/pango
167 mkdir -p /etc/pango
168 pango-querymodules > '/etc/pango/pango.modules' 2>/dev/null # otherwise only squares instead of text
169 [ -f /si-chroot ] && ln -s /lib/ld-lsb.so.3 /lib/ld-linux.so.2
170 # LD_LIBRARY_PATH=$MNT/usr/lib:$MNT/usr/lib32:$MNT/usr/lib64:$MNT/lib/:$LD_LIBRARY_PATH ldd $MNT/usr/bin/* $MNT/usr/lib/* 2>/dev/null | grep "not found" | sort | uniq
171 export HOME="/root"
172 export LANG="en_EN.UTF-8"
173 # export QT_PLUGIN_PATH=./lib/qt4/plugins ###################### !!!
174 #dbus-launch $MNT/AppRun ||
175 export LIBGL_DEBUG=verbose
176 export QT_DEBUG_PLUGINS=1
177 export LC_ALL=C.UTF-8
178 mkdir -p /usr/share/appimagekit
179 touch /usr/share/appimagekit/no_desktopintegration
180 dbus-uuidgen --ensure ; dbus-launch # Needed for CentOS 6.7 to launch apps that talk to dbus
181 if [ -f $MNT/usr/lib/qt5/plugins/platforms/libqxcb.so ] ; then
182 export LD_LIBRARY_PATH=$MNT/usr/lib/:$LD_LIBRARY_PATH
183 ##ldd $MNT/usr/lib/qt5/plugins/platforms/libqxcb.so | grep not
185 ##find $MNT/usr/lib -type f -exec sh -c 'ldd {} | grep "not found"' 2>/dev/null \;
186 if [ $(which $RUN_COMMAND) ] ; then
187 exec $RUN_INSIDE
188 else
189 $MNT/AppRun && echo "+++++++++ SUCCESS $ISO $2 +++++++++"
192 chmod a+x /tmp/$PREF/union/run.sh
193 mount -t proc proc /tmp/$PREF/union/proc
194 mkdir -p /tmp/$PREF/union/var/lib/dbus
195 mount --bind /dev /tmp/$PREF/union/dev
196 mount --bind /var/lib/dbus /tmp/$PREF/union/var/lib/dbus
197 touch /tmp/$PREF/union/etc/resolv.conf || echo ""
198 mount --bind /etc/resolv.conf /tmp/$PREF/union/etc/resolv.conf
199 xhost local: >/dev/null 2>&1 # otherwise "cannot open display: :0.0"
200 echo ""
201 chroot /tmp/$PREF/union/ /run.sh # $MNT/AppRun
202 echo ""
203 exit $?