From 1fa676035c88d946df50dcfa5f03dca95eac5f9e Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 12 Nov 2016 17:57:47 +0100 Subject: [PATCH 1/6] Try writing at an offset using the patched mksquashfs --- appimagetool.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/appimagetool.c b/appimagetool.c index 8ef52107c..2bd022279 100644 --- a/appimagetool.c +++ b/appimagetool.c @@ -105,7 +105,7 @@ int sfs_ls(char* image) { /* Generate a squashfs filesystem using mksquashfs on the $PATH * execlp(), execvp(), and execvpe() search on the $PATH */ -int sfs_mksquashfs(char *source, char *destination) { +int sfs_mksquashfs(char *source, char *destination, int offset) { pid_t parent = getpid(); pid_t pid = fork(); @@ -121,9 +121,9 @@ int sfs_mksquashfs(char *source, char *destination) { { // https://jonathancarter.org/2015/04/06/squashfs-performance-testing/ says: // improved performance by using a 16384 block size with a sacrifice of around 3% more squashfs image space - execlp("mksquashfs", "mksquashfs", source, destination, "-comp", "xz", "-root-owned", "-noappend", "-Xdict-size", "100%", "-b", "16384", "-no-xattrs", "-root-owned", NULL); + execlp("mksquashfs", "mksquashfs", source, destination, "-offset", offset, "-comp", "xz", "-root-owned", "-noappend", "-Xdict-size", "100%", "-b", "16384", "-no-xattrs", "-root-owned", NULL); } else { - execlp("mksquashfs", "mksquashfs", source, destination, "-comp", sqfs_comp, "-root-owned", "-noappend", "-no-xattrs", "-root-owned", NULL); + execlp("mksquashfs", "mksquashfs", source, destination, "-offset", offset, "-comp", sqfs_comp, "-root-owned", "-noappend", "-no-xattrs", "-root-owned", NULL); } perror("execlp"); // execlp() returns only on error return(-1); // exec never returns @@ -472,45 +472,32 @@ main (int argc, char *argv[]) } } - /* mksquashfs can currently not start writing at an offset, - * so we need a tempfile. https://github.com/plougher/squashfs-tools/pull/13 + /* Upstream mksquashfs can currently not start writing at an offset, + * so we need a patched one. https://github.com/plougher/squashfs-tools/pull/13 * should hopefully change that. */ - char *tempfile; + fprintf (stderr, "Generating squashfs...\n"); - tempfile = br_strcat(destination, ".temp"); - int result = sfs_mksquashfs(source, tempfile); - if(result != 0) - die("sfs_mksquashfs error"); - - fprintf (stderr, "Generating AppImage...\n"); - FILE *fpsrc = fopen(tempfile, "rb"); - if (fpsrc == NULL) { - die("Not able to open the tempfile for reading, aborting"); - } - FILE *fpdst = fopen(destination, "w"); - if (fpdst == NULL) { - die("Not able to open the destination file for writing, aborting"); - } - /* runtime is embedded into this executable * http://stupefydeveloper.blogspot.de/2008/08/cc-embed-binary-data-into-elf.html */ int size = (int)&_binary_runtime_size; char *data = (char *)&_binary_runtime_start; if (verbose) printf("Size of the embedded runtime: %d bytes\n", size); - fwrite(data, size, 1, fpdst); - fseek (fpdst, 0, SEEK_END); - char byte; - while (!feof(fpsrc)) - { - fread(&byte, sizeof(char), 1, fpsrc); - fwrite(&byte, sizeof(char), 1, fpdst); - } + int result = sfs_mksquashfs(source, destination, size); + if(result != 0) + die("sfs_mksquashfs error"); - fclose(fpsrc); + fprintf (stderr, "Embedding ELF...\n"); + FILE *fpdst = fopen(destination, "w+"); + if (fpdst == NULL) { + die("Not able to open the AppImage for writing, aborting"); + } + + rewind(fpdst); + fwrite(data, size, 1, fpdst); fclose(fpdst); - + fprintf (stderr, "Marking the AppImage as executable...\n"); if (chmod (destination, 0755) < 0) { printf("Could not set executable bit, aborting\n"); From 648af7c8a8fcb6d2122f239fb51a40e564d02e5b Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 12 Nov 2016 18:15:53 +0100 Subject: [PATCH 2/6] Update appimagetool.c --- appimagetool.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/appimagetool.c b/appimagetool.c index 2bd022279..fd7084754 100644 --- a/appimagetool.c +++ b/appimagetool.c @@ -503,9 +503,6 @@ main (int argc, char *argv[]) printf("Could not set executable bit, aborting\n"); exit(1); } - if(unlink(tempfile) != 0) { - die("Could not delete the tempfile, aborting"); - } if(bintray_user != NULL){ if(bintray_repo != NULL){ From f217b949065e6101be38af86968dd043d244ff9f Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 12 Nov 2016 18:34:39 +0100 Subject: [PATCH 3/6] Use AppRun --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1354738f..49cdbfeec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,8 @@ script: - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh - find ./out/appimagetool.AppDir/ - find ./out/appimaged.AppDir/ - - export PATH=./appimagetool.AppDir/usr/bin/:$PATH - - ( cd out/ ; ./appimagetool.AppDir/usr/bin/appimagetool ./appimagetool.AppDir/ -s -v -u "zsync|https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage.zsync" ) - - ( cd out/ ; ./appimagetool.AppDir/usr/bin/appimagetool ./appimaged.AppDir/ -s -v -u "zsync|https://github.com/probonopd/AppImageKit/releases/download/continuous/appimaged-x86_64.AppImage.zsync" ) + - ( cd out/ ; ./appimagetool.AppDir/AppRun ./appimagetool.AppDir/ -s -v -u "zsync|https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage.zsync" ) + - ( cd out/ ; ./appimagetool.AppDir/AppRun ./appimaged.AppDir/ -s -v -u "zsync|https://github.com/probonopd/AppImageKit/releases/download/continuous/appimaged-x86_64.AppImage.zsync" ) - rm -rf out/appimaged out/appimagetool out/validate out/digest out/mksquashfs || true - rm -rf out/runtime || true # Not needed, might confuse users - sudo rm -rf out/*.AppDir out/*.AppImage.digest || true # Not needed From 4115f0b6f185d980f651853d7164b80a0900bcd7 Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 12 Nov 2016 18:48:28 +0100 Subject: [PATCH 4/6] new file: resources/AppRun --- resources/AppRun | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 resources/AppRun diff --git a/resources/AppRun b/resources/AppRun new file mode 100755 index 000000000..8cc8977ee --- /dev/null +++ b/resources/AppRun @@ -0,0 +1,13 @@ +#!/bin/sh +HERE="$(dirname "$(readlink -f "${0}")")" +export UNION_PRELOAD="${HERE}" +export LD_PRELOAD="${HERE}/libunionpreload.so" +export PATH="${HERE}"/usr/bin/:"${HERE}"/usr/sbin/:"${HERE}"/usr/games/:"${HERE}"/bin/:"${HERE}"/sbin/:"${PATH}" +export LD_LIBRARY_PATH="${HERE}"/usr/lib/:"${HERE}"/usr/lib/i386-linux-gnu/:"${HERE}"/usr/lib/x86_64-linux-gnu/:"${HERE}"/usr/lib32/:"${HERE}"/usr/lib64/:"${HERE}"/lib/:"${HERE}"/lib/i386-linux-gnu/:"${HERE}"/lib/x86_64-linux-gnu/:"${HERE}"/lib32/:"${HERE}"/lib64/:"${LD_LIBRARY_PATH}" +export PYTHONPATH="${HERE}"/usr/share/pyshared/:"${PYTHONPATH}" +export XDG_DATA_DIRS="${HERE}"/usr/share/:"${XDG_DATA_DIRS}" +export PERLLIB="${HERE}"/usr/share/perl5/:"${HERE}"/usr/lib/perl5/:"${PERLLIB}" +export GSETTINGS_SCHEMA_DIR="${HERE}"/usr/share/glib-2.0/schemas/:"${GSETTINGS_SCHEMA_DIR}" +export QT_PLUGIN_PATH="${HERE}"/usr/lib/qt4/plugins/:"${HERE}"/usr/lib/i386-linux-gnu/qt4/plugins/:"${HERE}"/usr/lib/x86_64-linux-gnu/qt4/plugins/:"${HERE}"/usr/lib32/qt4/plugins/:"${HERE}"/usr/lib64/qt4/plugins/:"${HERE}"/usr/lib/qt5/plugins/:"${HERE}"/usr/lib/i386-linux-gnu/qt5/plugins/:"${HERE}"/usr/lib/x86_64-linux-gnu/qt5/plugins/:"${HERE}"/usr/lib32/qt5/plugins/:"${HERE}"/usr/lib64/qt5/plugins/:"${QT_PLUGIN_PATH}" +EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 1) +exec "${EXEC}" $@ From c21ab5abaf5d057a2ad4dc5e70361a77203736b7 Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 12 Nov 2016 18:49:17 +0100 Subject: [PATCH 5/6] Use bash AppRun because it does not chdir() and hence allows relative paths --- build-appdirs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-appdirs.sh b/build-appdirs.sh index d1ac3bb00..8e82bd324 100644 --- a/build-appdirs.sh +++ b/build-appdirs.sh @@ -19,7 +19,7 @@ cp mksquashfs ../../build cd ../../ -cp build/AppRun appimagetool.AppDir/ +cp resources/AppRun appimagetool.AppDir/ cp build/appimagetool appimagetool.AppDir/usr/bin/ cp build/mksquashfs appimagetool.AppDir/usr/bin/ @@ -39,7 +39,7 @@ mkdir -p appimaged.AppDir/usr/lib cp -f build/appimaged appimaged.AppDir/usr/bin cp -f build/validate appimaged.AppDir/usr/bin -cp build/AppRun appimaged.AppDir/ +cp resources/AppRun appimaged.AppDir/ find /usr/lib -name libarchive.so.3 -exec cp {} appimaged.AppDir/usr/lib/ \; cp resources/appimaged.desktop appimaged.AppDir/ From 31129dfabb3c1bf74e66779342970deb0f45a682 Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 12 Nov 2016 19:18:00 +0100 Subject: [PATCH 6/6] Use patched mksquashfs --- appimagetool.c | 10 ++++++---- resources/AppRun | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/appimagetool.c b/appimagetool.c index fd7084754..0e26d0c10 100644 --- a/appimagetool.c +++ b/appimagetool.c @@ -117,13 +117,15 @@ int sfs_mksquashfs(char *source, char *destination, int offset) { waitpid(pid, &status, 0); } else { // we are the child + gchar *offset_string; + offset_string = g_strdup_printf("%i", offset); if(0==strcmp("xz", sqfs_comp)) { // https://jonathancarter.org/2015/04/06/squashfs-performance-testing/ says: // improved performance by using a 16384 block size with a sacrifice of around 3% more squashfs image space - execlp("mksquashfs", "mksquashfs", source, destination, "-offset", offset, "-comp", "xz", "-root-owned", "-noappend", "-Xdict-size", "100%", "-b", "16384", "-no-xattrs", "-root-owned", NULL); + execlp("mksquashfs", "mksquashfs", source, destination, "-offset", offset_string, "-comp", "xz", "-root-owned", "-noappend", "-Xdict-size", "100%", "-b", "16384", "-no-xattrs", "-root-owned", NULL); } else { - execlp("mksquashfs", "mksquashfs", source, destination, "-offset", offset, "-comp", sqfs_comp, "-root-owned", "-noappend", "-no-xattrs", "-root-owned", NULL); + execlp("mksquashfs", "mksquashfs", source, destination, "-offset", offset_string, "-comp", sqfs_comp, "-root-owned", "-noappend", "-no-xattrs", "-root-owned", NULL); } perror("execlp"); // execlp() returns only on error return(-1); // exec never returns @@ -489,12 +491,12 @@ main (int argc, char *argv[]) die("sfs_mksquashfs error"); fprintf (stderr, "Embedding ELF...\n"); - FILE *fpdst = fopen(destination, "w+"); + FILE *fpdst = fopen(destination, "rb+"); if (fpdst == NULL) { die("Not able to open the AppImage for writing, aborting"); } - rewind(fpdst); + fseek(fpdst, 0, SEEK_SET); fwrite(data, size, 1, fpdst); fclose(fpdst); diff --git a/resources/AppRun b/resources/AppRun index 8cc8977ee..eb9d90de1 100755 --- a/resources/AppRun +++ b/resources/AppRun @@ -1,7 +1,5 @@ #!/bin/sh HERE="$(dirname "$(readlink -f "${0}")")" -export UNION_PRELOAD="${HERE}" -export LD_PRELOAD="${HERE}/libunionpreload.so" export PATH="${HERE}"/usr/bin/:"${HERE}"/usr/sbin/:"${HERE}"/usr/games/:"${HERE}"/bin/:"${HERE}"/sbin/:"${PATH}" export LD_LIBRARY_PATH="${HERE}"/usr/lib/:"${HERE}"/usr/lib/i386-linux-gnu/:"${HERE}"/usr/lib/x86_64-linux-gnu/:"${HERE}"/usr/lib32/:"${HERE}"/usr/lib64/:"${HERE}"/lib/:"${HERE}"/lib/i386-linux-gnu/:"${HERE}"/lib/x86_64-linux-gnu/:"${HERE}"/lib32/:"${HERE}"/lib64/:"${LD_LIBRARY_PATH}" export PYTHONPATH="${HERE}"/usr/share/pyshared/:"${PYTHONPATH}"