Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use patched mksquashfs --offset feature #277

Merged
merged 6 commits into from Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Expand Up @@ -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
Expand Down
54 changes: 20 additions & 34 deletions appimagetool.c
Expand Up @@ -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();

Expand All @@ -117,13 +117,15 @@ int sfs_mksquashfs(char *source, char *destination) {
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, "-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, "-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
Expand Down Expand Up @@ -472,53 +474,37 @@ 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, "rb+");
if (fpdst == NULL) {
die("Not able to open the AppImage for writing, aborting");
}

fseek(fpdst, 0, SEEK_SET);
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");
exit(1);
}
if(unlink(tempfile) != 0) {
die("Could not delete the tempfile, aborting");
}

if(bintray_user != NULL){
if(bintray_repo != NULL){
Expand Down
4 changes: 2 additions & 2 deletions build-appdirs.sh
Expand Up @@ -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/

Expand All @@ -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/
Expand Down
11 changes: 11 additions & 0 deletions resources/AppRun
@@ -0,0 +1,11 @@
#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")"
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}" $@