First shot at a script to merge two file systems into one FatELF install.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 04 Oct 2009 14:59:34 -0400
changeset 67 944bb02f0743
parent 66 e27512942681
child 68 79f33789900d
First shot at a script to merge two file systems into one FatELF install.
misc/iself.c
misc/merge.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/iself.c	Sun Oct 04 14:59:34 2009 -0400
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+static void check_elf(const char *fname)
+{
+	static const unsigned char magic[4] = { 0x7F, 0x45, 0x4C, 0x46 };
+	size_t br = 0;
+	unsigned char buf[4];
+	FILE *f = fopen(fname, "rb");
+	if (f == NULL)
+	{
+		fprintf(stderr, "Can't open %s: %s\n", fname, strerror(errno));
+		return;
+	}
+
+	br = fread(buf, 4, 1, f);
+	fclose(f);
+
+	if (br != 1)
+	{
+		if (ferror(f))
+			fprintf(stderr, "Can't read %s: %s\n", fname, strerror(errno));
+		return;
+	}
+
+	if (memcmp(buf, magic, 4) == 0)
+		printf("%s\n", fname);
+}
+
+int main(int argc, const char **argv)
+{
+	int i;
+	for (i = 1; i < argc; i++)
+		check_elf(argv[i]);
+	return 0;
+}
+
+// end of iself.c ...
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/merge.sh	Sun Oct 04 14:59:34 2009 -0400
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+if [ "x`id -u`" != "x0" ]; then
+    echo "not root."
+    exit 1
+fi
+
+set -x
+set -e
+
+rm -rf cmake-build
+mkdir cmake-build
+cd cmake-build
+
+cmake -DCMAKE_BUILD_TYPE=Release ../..
+make -j2
+gcc -o iself -s -O3 ../iself.c
+
+#time for feh in bin boot etc lib opt sbin usr var ; do find /$feh -type f -exec ./iself {} \; ; done |perl -w -pi -e 's/\A\///;' |grep -v "usr/lib32/" |sort |uniq > ./binaries-64
+time for feh in bin boot etc lib opt sbin usr var ; do find /x86/$feh -type f -exec ./iself {} \; ; done |perl -w -pi -e 's/\A\/x86\///;' |grep -v "usr/lib64" |sort |uniq > ./binaries-32
+
+for feh in `cat binaries-32` ; do
+    mkdir -p --mode=0755 `dirname $feh`
+    if [ -f "/$feh" ]; then
+        ./fatelf-glue tmp-fatelf "/$feh" "/x86/$feh"
+        chmod --reference="/$feh" tmp-fatelf
+        mv tmp-fatelf "/$feh"
+    else
+        cp -a "/x86/$feh" "/$feh"
+    fi
+done
+
+# end of merge.sh ...
+