From 6ceb97648be68ace529e19ed871f64e4d46539e4 Mon Sep 17 00:00:00 2001 From: Bert Maher Date: Wed, 11 Jan 2017 09:49:53 -0800 Subject: [PATCH] Produce a single-file self-extracting script for OSS Summary: For the benefit of Buck, homebrew, and all the users who have no idea what redex-all is, we'll now build redex as a magic self-extracting script. The script contains a bash extraction preamble followed by a tar file containing redex-all and the python wrapper (and libraries). When `redex` is invoked it untars this payload to a temp location, executes redex with the specified parameters, and then deletes the untarred payload. Differential Revision: D4401602 fbshipit-source-id: 94fa04d7a966be55ab86720c4d426ea566b562bb --- Makefile.am | 16 +++++++++------- bundle-redex.sh | 5 +++++ redex.py | 9 ++++++--- selfextract.sh | 12 ++++++++++++ 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100755 bundle-redex.sh create mode 100644 selfextract.sh diff --git a/Makefile.am b/Makefile.am index 6d251da0c66..dc945473e95 100644 --- a/Makefile.am +++ b/Makefile.am @@ -112,7 +112,8 @@ libredex_la_LIBADD = \ # # redex-all: the main executable # -bin_PROGRAMS = redex-all redexdump +bin_PROGRAMS = redexdump +noinst_PROGRAMS = redex-all redex_all_SOURCES = \ opt/annoclasskill/AnnoClassKill.cpp \ @@ -177,11 +178,12 @@ redexdump_LDADD = \ # bin_SCRIPTS = redex apkutil CLEANFILES = redex -EXTRA_DIST = redex.py -redex: redex.py Makefile - cp $(srcdir)/redex.py redex - chmod +x redex +PYTHON_SRCS := redex.py \ + pyredex/__init__.py \ + pyredex/log.py \ + pyredex/unpacker.py \ + pyredex/utils.py -install-exec-hook: - cp -r $(srcdir)/pyredex $(DESTDIR)$(bindir) +redex: redex-all $(PYTHON_SRCS) + $(srcdir)/bundle-redex.sh diff --git a/bundle-redex.sh b/bundle-redex.sh new file mode 100755 index 00000000000..08c8893d789 --- /dev/null +++ b/bundle-redex.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +tar czf redex.tar.gz redex-all redex.py pyredex/*.py +cat selfextract.sh redex.tar.gz > redex +chmod +x redex diff --git a/redex.py b/redex.py index e40771a6346..84cd46fb7ac 100755 --- a/redex.py +++ b/redex.py @@ -66,9 +66,12 @@ def run_pass( ): if executable_path is None: - executable_path = subprocess.check_output(['which', 'redex-all']).rstrip() - if executable_path is None: - executable_path = join(dirname(abspath(__file__)), 'redex-all') + try: + executable_path = subprocess.check_output(['which', 'redex-all']).rstrip() + except subprocess.CalledProcessError: + pass + if executable_path is None: + executable_path = join(dirname(abspath(__file__)), 'redex-all') if not isfile(executable_path) or not os.access(executable_path, os.X_OK): sys.exit('redex-all is not found or is not executable') log('Running redex binary at ' + executable_path) diff --git a/selfextract.sh b/selfextract.sh new file mode 100644 index 00000000000..e694876441b --- /dev/null +++ b/selfextract.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export TMPDIR=`mktemp -d /tmp/redex.XXXXXX` +ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ { print NR + 1; exit 0 }' $0` +tail -n+$ARCHIVE $0 | tar xz -C $TMPDIR + +$TMPDIR/redex.py $@ + +rm -rf $TMPDIR +exit 0 + +__ARCHIVE_BELOW__