From 027bc34aed273df6faeab22ad920737d663302ac Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 4 Oct 2009 14:59:34 -0400 Subject: [PATCH] First shot at a script to merge two file systems into one FatELF install. --- misc/iself.c | 43 +++++++++++++++++++++++++++++++++++++++++++ misc/merge.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 misc/iself.c create mode 100755 misc/merge.sh diff --git a/misc/iself.c b/misc/iself.c new file mode 100644 index 0000000..8d4cbd8 --- /dev/null +++ b/misc/iself.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +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 ... + + diff --git a/misc/merge.sh b/misc/merge.sh new file mode 100755 index 0000000..792f9bc --- /dev/null +++ b/misc/merge.sh @@ -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 ... +