Initial commit

This commit is contained in:
darealshinji 2017-04-26 15:27:46 +02:00
commit 67024f9062
4 changed files with 169 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/AppRun-patched
/AppRun.c
/AppRun.c.orig

28
AppRun.c.patch Normal file
View file

@ -0,0 +1,28 @@
--- a/AppRun.c
+++ b/AppRun.c
@@ -44,6 +44,8 @@ THE SOFTWARE.
#define LINE_SIZE 255
+char *checkrt(char *usr_in_appdir);
+
int filter(const struct dirent *dir) {
char *p = (char*) &dir->d_name;
p = strrchr(p, '.');
@@ -156,6 +158,7 @@ int main(int argc, char *argv[]) {
char *old_env;
const LENGTH = 2047;
char new_env[8][LENGTH+1];
+ char *optional = checkrt(usr_in_appdir);
/* https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME */
snprintf(new_env[0], LENGTH, "PYTHONHOME=%s/usr/", appdir);
@@ -165,7 +168,7 @@ int main(int argc, char *argv[]) {
snprintf(new_env[1], LENGTH, "PATH=%s/usr/bin/:%s/usr/sbin/:%s/usr/games/:%s/bin/:%s/sbin/:%s", appdir, appdir, appdir, appdir, appdir, old_env);
old_env = getenv("LD_LIBRARY_PATH") ?: "";
- snprintf(new_env[2], LENGTH, "LD_LIBRARY_PATH=%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env);
+ snprintf(new_env[2], LENGTH, "LD_LIBRARY_PATH=%s%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", optional, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env);
old_env = getenv("PYTHONPATH") ?: "";
snprintf(new_env[3], LENGTH, "PYTHONPATH=%s/usr/share/pyshared/:%s", appdir, old_env);

18
Makefile Normal file
View file

@ -0,0 +1,18 @@
CFLAGS ?= -O2 -Wall -Wextra
LDFLAGS += -s
BIN = AppRun_patched
all: $(BIN)
clean:
-rm -f $(BIN) *.o AppRun.c AppRun_patched.c
$(BIN): AppRun_patched.o checkrt.o
AppRun_patched.c: AppRun.c
patch -p1 --output $@ < AppRun.c.patch
AppRun.c:
wget -c "https://raw.githubusercontent.com/probonopd/AppImageKit/appimagetool/master/AppRun.c"

120
checkrt.c Normal file
View file

@ -0,0 +1,120 @@
/* Copyright (c) 2017 djcj <djcj@gmx.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#ifndef LIBC6_ARCH
# if (__WORDSIZE == 64)
# define LIBC6_ARCH "libc6,x86-64"
# else
# define LIBC6_ARCH "libc6"
# endif
#endif
#define LINE_SIZE 255
#define SCANLIB(lib,sym,regex) \
sprintf(command, format, lib, regex); \
f = popen(command, "r"); \
ret = fscanf(f, "%s", sym); (void)ret; \
pclose(f);
#define CXXDIR "optional/libstdc++"
#define GCCDIR "optional/libgcc"
char *checkrt(char *usr_in_appdir)
{
char path[1024];
int ret;
FILE *f;
char command[LINE_SIZE];
char stdcxx_sys_lib[LINE_SIZE], gcc_sys_lib[LINE_SIZE];
char stdcxx_sys_sym[LINE_SIZE], gcc_sys_sym[LINE_SIZE];
char stdcxx_bundle_sym[LINE_SIZE], gcc_bundle_sym[LINE_SIZE];
int stdcxx_sys_ver=1, stdcxx_bundle_ver=0, gcc_sys_ver=1, gcc_bundle_ver=0;
char *stdcxx_bundle_lib = "./" CXXDIR "/libstdc++.so.6";
char *gcc_bundle_lib = "./" GCCDIR "/libgcc_s.so.1";
const char *format = "tr '\\0' '\\n' < '%s' | grep -e '%s' | tail -n1";
if (access(stdcxx_bundle_lib, F_OK) == 0) {
f = popen("ldconfig -p | grep 'libstdc++.so.6 (" LIBC6_ARCH ")' | awk 'NR==1{print $NF}'", "r");
ret = fscanf(f, "%s", stdcxx_sys_lib); (void)ret;
pclose(f);
if (access(stdcxx_sys_lib, F_OK) == 0) {
SCANLIB(stdcxx_sys_lib, stdcxx_sys_sym, "^GLIBCXX_3\\.4");
SCANLIB(stdcxx_bundle_lib, stdcxx_bundle_sym, "^GLIBCXX_3\\.4");
stdcxx_sys_ver = atoi(stdcxx_sys_sym+12);
stdcxx_bundle_ver = atoi(stdcxx_bundle_sym+12);
//printf("%s ==> %s (%d)\n", stdcxx_sys_lib, stdcxx_sys_sym, stdcxx_sys_ver);
//printf("%s ==> %s (%d)\n\n", stdcxx_bundle_lib, stdcxx_bundle_sym, stdcxx_bundle_ver);
}
}
if (access(gcc_bundle_lib, F_OK) == 0) {
f = popen("ldconfig -p | grep 'libgcc_s.so.1 (" LIBC6_ARCH ")' | awk 'NR==1{print $NF}'", "r");
ret = fscanf(f, "%s", gcc_sys_lib); (void)ret;
pclose(f);
if (access(gcc_sys_lib, F_OK) == 0) {
SCANLIB(gcc_sys_lib, gcc_sys_sym, "^GCC_[0-9]\\.[0-9]");
SCANLIB(gcc_bundle_lib, gcc_bundle_sym, "^GCC_[0-9]\\.[0-9]");
gcc_sys_ver = atoi(gcc_sys_sym+4) * 100 + atoi(gcc_sys_sym+6) * 10 + atoi(gcc_sys_sym+8);
gcc_bundle_ver = atoi(gcc_bundle_sym+4) * 100 + atoi(gcc_bundle_sym+6) * 10 + atoi(gcc_bundle_sym+8);
//printf("%s ==> %s (%d)\n", gcc_sys_lib, gcc_sys_sym, gcc_sys_ver);
//printf("%s ==> %s (%d)\n\n", gcc_bundle_lib, gcc_bundle_sym, gcc_bundle_ver);
}
}
int bundle_cxx = 0;
int bundle_gcc = 0;
if (stdcxx_bundle_ver > stdcxx_sys_ver)
bundle_cxx = 1;
if (gcc_bundle_ver > gcc_sys_ver)
bundle_gcc = 1;
char *tmp;
if (bundle_cxx == 1 && bundle_gcc == 0) {
sprintf(path, "%s/" CXXDIR ":", usr_in_appdir);
strcpy(tmp, path);
return tmp;
} else if (bundle_cxx == 0 && bundle_gcc == 1) {
sprintf(path, "%s/" GCCDIR ":", usr_in_appdir);
strcpy(tmp, path);
return tmp;
} else if (bundle_cxx == 1 && bundle_gcc == 1) {
sprintf(path, "%s/" GCCDIR ":%s/" CXXDIR ":", usr_in_appdir, usr_in_appdir);
strcpy(tmp, path);
return tmp;
}
return "";
}