Skip to content

Instantly share code, notes, and snippets.

@nonchip
Last active February 28, 2016 15:15
Show Gist options
  • Save nonchip/ba7ef0222ec2ec08b49a to your computer and use it in GitHub Desktop.
Save nonchip/ba7ef0222ec2ec08b49a to your computer and use it in GitHub Desktop.
#!/bin/bash
# selfrun.sh <executable>
# creates "<executable>.standalone" containing "." and extracting&running itself.
export _ROOT="/tmp/.nc.selfrun.$(uuidgen)-$(uuidgen)"
cat > "${1}.standalone" <<END
#!/bin/bash
export self="\$(readlink -f "\$0")"
if test -e $_ROOT
then cd $_ROOT
else
mkdir $_ROOT
cd $_ROOT
tail -n +11 "\$self" | tar xj
fi
exec ./${1} "\$@"
END
tar cj * >> "${1}.standalone"
chmod +rx "${1}.standalone"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment