# gzexe: compressor for Unix executables.
# Use this only for binaries that you do not use frequently.
# The compressed version is a shell script which decompresses itself after
# skipping $skip lines of shell commands. We try invoking the compressed
# executable with the original name (for programs looking at their name).
# We also try to retain the original file permissions on the compressed file.
# For safety reasons, gzexe will not create setuid or setgid shell scripts.
# WARNING: the first line of this file must be either : or #!/bin/sh
# The : is required for some old versions of csh.
# On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5
echo compress executables. original file foo is renamed to foo~
echo usage: ${x} [-d] files...
echo " -d decompress the executables"
trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15
test "$x" = "ungzexe" && decomp=1
if test "x$1" = "x-d"; then
if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then
IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:"
if test -f $dir/tail; then
if test $decomp -eq 0; then
if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then
echo "${x}: $i is already gzexe'd"
if ls -l "$i" | grep '^...[sS]' > /dev/null; then
echo "${x}: $i has setuid permission, unchanged"
if ls -l "$i" | grep '^......[sS]' > /dev/null; then
echo "${x}: $i has setgid permission, unchanged"
gzip | tail | chmod | ln | sleep | rm)
echo "${x}: $i would depend on itself"; continue ;;
if test -z "$cpmod"; then
cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp
if test -w $tmp 2>/dev/null; then
chmod u+w $tmp 2>/dev/null
if test $decomp -eq 0; then
sed "s|^if tail|if $tail|" >> $tmp <<'EOF'
if tail +$skip $0 | "BINDIR"/gzip -cd > /tmp/gztmp$$; then
/bin/chmod 700 /tmp/gztmp$$
prog="`echo $0 | /bin/sed 's|^.*/||`"
if /bin/ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then
trap '/bin/rm -f /tmp/gztmp$$ "/tmp/$prog"; exit $res' 0
(/bin/sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null &
/tmp/"$prog" ${1+"$@"}; res=$?
trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0
(/bin/sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null &
/tmp/gztmp$$ ${1+"$@"}; res=$?
echo Cannot decompress $0; exit 1
"BINDIR"/gzip -cv9 "$i" >> $tmp || {
echo ${x}: compression not possible for $i, file unchanged.
if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then
eval `sed -e 1d -e 2q "$i"`
if tail +$skip "$i" | "BINDIR"/gzip -cd > $tmp; then
echo ${x}: $i probably not in gzexe format, file unchanged.
echo ${x}: cannot backup $i as $i~
mv $tmp "$i" || cp -p $tmp "$i" 2>/dev/null || cp $tmp "$i" || {
echo ${x}: cannot create $i
if test -n "$cpmod"; then
$cpmod "$i~" "$i" 2>/dev/null
elif test $writable -eq 0; then