Merge pull request #599 from azubieta/create_deb_using_cpack
[appimagekit/gsi.git] / testappimage
blobb47ca39cd4b28733d26a99c625188ae5d3c392e5
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 xhost + # Workaround for: QXcbConnection: Could not connect to display :0
15 HERE=$(dirname $(readlink -f "${0}"))
16 export PATH=$HERE:$HERE/usr/bin:$PATH
18 if [ "$1x" == "x" ] ; then
19 echo "Please specify a ISO or squashfs base system to run the AppImage on"
20 exit 1
23 if [ "$2x" == "x" ] ; then
24 echo "Please specify an AppDir or AppImage outside the ISO or command inside the ISO to be run"
25 exit 1
28 export PREF=$RANDOM
30 mkdir -p /tmp/$PREF/unionfs/ro
31 mkdir -p /tmp/$PREF/unionfs/root
32 mkdir -p /tmp/$PREF/unionfs/rw
33 mkdir -p /tmp/$PREF/union
34 mkdir -p /tmp/$PREF/iso
35 mkdir -p /tmp/$PREF/workdir
37 # openSUSE LEAP 42.2 does not have a tmpfs in /tmp but we need this
38 mount | grep "/tmp type tmpfs" && sudo mount -t tmpfs tmpfs /tmp/
40 # If ISO was specified, then mount it and find contained filesystem
41 THEFS="$1"
42 if [ ${1: -4} == ".iso" ] ; then
43 ISO="$1"
44 mount -o loop,ro "$ISO" /tmp/$PREF/iso
45 # If there is a squashfs file named $ISO.buildsquash then we overlay-
46 # mount this as well. This can significantly speed up subsequent builds
47 # because dependencies can be installed there. The squashfs file can be
48 # generated by squashing the unionfs/rw directory.
49 if [ -e $ISO.buildsquash ] ; then
50 mount -o loop,ro "$ISO.buildsquash" /tmp/$PREF/unionfs/ro
54 # If sfs was provided, then assume it contains a rootfs use just that
55 THEFS="$1"
56 if [ ${1: -4} == ".sfs" ] ; then
57 ISO="$1"
58 mount -o loop,ro "$ISO" /tmp/$PREF/unionfs/root
61 # If ext3 was provided, then assume it contains a rootfs use just that
62 THEFS="$1"
63 if [ ${1: -4} == "ext3" ] ; then
64 ISO="$1"
65 mount -o loop,ro "$ISO" /tmp/$PREF/unionfs/root
68 echo ""
69 echo "===================================================="
70 echo ""
71 echo $ISO
73 # In case of Ubuntu-like ISOs
74 if [ -e /tmp/$PREF/iso/casper/filesystem.squashfs ] ; then
75 THEFS=/tmp/$PREF/iso/casper/filesystem.squashfs
76 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
79 # In case of Fedora-like ISOs
80 if [ -e /tmp/$PREF/iso/LiveOS/squashfs.img ] ; then
81 mount -o loop,ro /tmp/$PREF/iso/LiveOS/squashfs.img /tmp/$PREF/iso/
82 if [ -e /tmp/$PREF/iso/LiveOS/ext3fs.img ] ; then
83 # F23 and below use https://github.com/rhinstaller/livecd-tools
84 THEFS=/tmp/$PREF/iso/LiveOS/ext3fs.img || exit 1
86 if [ -e /tmp/$PREF/iso/LiveOS/rootfs.img ] ; then
87 # F24 and above use https://github.com/rhinstaller/lorax and livemedia-creator
88 THEFS=/tmp/$PREF/iso/LiveOS/rootfs.img || exit 1
90 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
93 # In case of debian-like ISOs
94 if [ -e /tmp/$PREF/iso/live/filesystem.squashfs ] ; then
95 THEFS=/tmp/$PREF/iso/live/filesystem.squashfs
96 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
99 # In case of openSUSE-like ISOs
100 if [ -e /tmp/$PREF/iso/*-read-only.* ] ; then
101 THEFS=$(ls /tmp/$PREF/iso/*-read-only.* | head -n 1)
102 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
105 # In case of puppy-like ISOs
106 if [ -e /tmp/$PREF/iso/puppy_*.sfs ] ; then
107 THEFS=$(ls /tmp/$PREF/iso/puppy_*.sfs | head -n 1)
108 mount "$THEFS" /tmp/$PREF/unionfs/root -o loop,ro || exit 1
111 trap atexit EXIT
113 atexit()
114 { set +e
115 umount -l /tmp/$PREF/union/var/lib/dbus 2>/dev/null
116 umount -l /tmp/$PREF/union/etc/resolv.conf 2>/dev/null
117 umount -l /tmp/$PREF/union/proc 2>/dev/null
118 umount -l /tmp/$PREF/union/dev 2>/dev/null
119 umount -l /tmp/$PREF/union/mnt 2>/dev/null
120 umount -l /tmp/$PREF/union 2>/dev/null
121 umount -l /tmp/$PREF/unionfs/ro 2>/dev/null
122 umount -l /tmp/$PREF/unionfs/root 2>/dev/null
123 umount -l /tmp/$PREF/iso 2>/dev/null
124 umount -l /tmp/$PREF/iso 2>/dev/null
125 umount -l /tmp/$PREF/iso 2>/dev/null
126 rm -r /tmp/$PREF/workdir
127 rm -r /tmp/$PREF/unionfs/root
128 rm -r /tmp/$PREF/unionfs/rw
129 rm -r /tmp/$PREF/unionfs/ro
130 rm -r /tmp/$PREF/unionfs
131 rm -r /tmp/$PREF/union
132 rm -r /tmp/$PREF/iso
133 rm -r /tmp/$PREF/
136 # Kernel 4.0 or newer required
137 kernel_major=$(uname -r | cut -d . -f 1)
138 if [ ! $kernel_major -ge 4 ] ; then
139 echo "Falling back to unionfs-fuse because kernel is not 4.x or newer"
140 echo "This can potentially be unreliable"
141 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
142 else
143 echo "Using OverlayFS because kernel is 4.x or newer"
144 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
147 ls /tmp/$PREF/union/mnt >/dev/null && MNT=/mnt
148 # ls /tmp/$PREF/union/automake >/dev/null && MNT=/automake || echo "" # Puppy
150 if [ "x$MNT" == "x" ] ; then
151 echo "Could not find free mountpoint"
152 exit 1
154 if [ -f "$2" ] ; then
155 mount "$2" /tmp/$PREF/union/$MNT -o loop,ro
156 elif [ -d "$2" ] ; then
157 mount "$2" /tmp/$PREF/union/$MNT -o bind
158 else
159 shift
160 export RUN_COMMAND=$1
161 export RUN_INSIDE=$@
164 cat > /tmp/$PREF/union/run.sh <<EOF
165 #!/bin/sh
166 cat /etc/*release
167 echo ""
168 rm -rf /etc/pango
169 mkdir -p /etc/pango
170 pango-querymodules > '/etc/pango/pango.modules' 2>/dev/null # otherwise only squares instead of text
171 [ -f /si-chroot ] && ln -s /lib/ld-lsb.so.3 /lib/ld-linux.so.2
172 # 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
173 export HOME="/root"
174 export LANG="en_EN.UTF-8"
175 # export QT_PLUGIN_PATH=./lib/qt4/plugins ###################### !!!
176 #dbus-launch $MNT/AppRun ||
177 export LIBGL_DEBUG=verbose
178 export QT_DEBUG_PLUGINS=1
179 export LC_ALL=C.UTF-8
180 mkdir -p /usr/share/appimagekit
181 touch /usr/share/appimagekit/no_desktopintegration
182 dbus-uuidgen --ensure ; dbus-launch # Needed for CentOS 6.7 to launch apps that talk to dbus
183 if [ -f $MNT/usr/lib/qt5/plugins/platforms/libqxcb.so ] ; then
184 export LD_LIBRARY_PATH=$MNT/usr/lib/:$LD_LIBRARY_PATH
185 ##ldd $MNT/usr/lib/qt5/plugins/platforms/libqxcb.so | grep not
187 ##find $MNT/usr/lib -type f -exec sh -c 'ldd {} | grep "not found"' 2>/dev/null \;
188 if [ $(which $RUN_COMMAND) ] ; then
189 exec $RUN_INSIDE
190 else
191 $MNT/AppRun && echo "+++++++++ SUCCESS $ISO $2 +++++++++"
194 chmod a+x /tmp/$PREF/union/run.sh
195 mount -t proc proc /tmp/$PREF/union/proc
196 mkdir -p /tmp/$PREF/union/var/lib/dbus
197 mount --bind /dev /tmp/$PREF/union/dev
198 mount --bind /var/lib/dbus /tmp/$PREF/union/var/lib/dbus
199 touch /tmp/$PREF/union/etc/resolv.conf || echo ""
200 mount --bind /etc/resolv.conf /tmp/$PREF/union/etc/resolv.conf
201 xhost local: >/dev/null 2>&1 # otherwise "cannot open display: :0.0"
202 echo ""
203 chroot /tmp/$PREF/union/ /run.sh # $MNT/AppRun
204 echo ""
205 exit $?