Skip to content

Commit

Permalink
Produce a single-file self-extracting script for OSS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bertmaher authored and facebook-github-bot committed Jan 11, 2017
1 parent b47750b commit 6ceb976
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
16 changes: 9 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions bundle-redex.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions redex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions selfextract.sh
Original file line number Diff line number Diff line change
@@ -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__

0 comments on commit 6ceb976

Please sign in to comment.