Skip to content

Instantly share code, notes, and snippets.

@scarf005
Last active June 14, 2023 02:16
Show Gist options
  • Save scarf005/81241e36e0a2a2b84306f23933ba652a to your computer and use it in GitHub Desktop.
Save scarf005/81241e36e0a2a2b84306f23933ba652a to your computer and use it in GitHub Desktop.
Bash in a jar
#!/usr/bin/env bash
readonly GREEN='\033[32m'
readonly NC='\033[0m'
header() { printf "${GREEN}$@${NC}"; }
readonly LOCATION=$(pwd)/bash-in-a-jar
header "installation location:\n"
echo ${LOCATION}
header "\ncreating directories:\n"
echo ${LOCATION}/{bin,lib,lib64}
mkdir -p ${LOCATION}/{bin,lib,lib64}
cd ${LOCATION}
for NAME in /bin/{bash,echo,ls}
do
header '\ncopying binary: '
cp -v ${NAME} ${LOCATION}/bin
header '\ncopying shared object:\n'
ldd ${NAME} | egrep -o '/lib.*\.[0-9]' | xargs -i cp -v --parents {} .
echo
done
header 'now run: '
echo 'sudo chroot .' /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment