Skip to content

Instantly share code, notes, and snippets.

@mahfuznow
Last active October 25, 2020 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahfuznow/1e525f51fe4c216da5a37e739d03988a to your computer and use it in GitHub Desktop.
Save mahfuznow/1e525f51fe4c216da5a37e739d03988a to your computer and use it in GitHub Desktop.
#!/data/data/com.termux/files/usr/bin/bash
main() {
pwd=`pwd`
echo "====Enter Installation Directory===="
read dir
installation_dir="$HOME/$dir"
mkdir $installation_dir
echo "Installing at $installation_dir"
echo "====Checking requirements===="
pkg install wget proot tar -y
echo "====Getting Architecture info===="
case `dpkg --print-architecture` in
aarch64) archurl="arm64" ;;
arm) archurl="armhf" ;;
amd64) archurl="amd64" ;;
x86_64) archurl="amd64" ;;
i*86) archurl="i386" ;;
x86) archurl="i386" ;;
*) echo "unknown architecture"; exit 1 ;;
esac
echo "You device Architecture is ${archurl}"
filename="kali-rootfs-${archurl}.tar.xz"
folder=kali-fs
echo "====Choose Installation Option===="
echo " 1) Install Offline"
echo " 2) Install Online"
read n
case $n in
1) install_offline;;
2) install_online;;
*) echo "invalid option";;
esac
extract_file
create_launch_script
echo "Do you want to delete ${filename} file?"
echo " 1) Yes"
echo " 2) No"
read n
case $n in
1) rm $filename;;
2) ;;
*) ;;
esac
echo "====Setup completed successfully==="
echo "You can now launch Kali with the command start-kali"
}
install_offline() {
echo "Installing offline.."
load_file
}
load_file() {
echo "Loading file from SDcard.."
storage_path="$HOME/storage"
if [ ! -d "$storage_path" ]; then
echo "Setting up storage"
termux-setup-storage
fi
cp /sdcard/$filename $filename
}
install_online() {
echo "Installing online"
download_file
}
download_file(){
echo "Downloading ${filename}, this may take a while base on your internet speed."
case `dpkg --print-architecture` in
aarch64) archurl="arm64" ;;
arm) archurl="armhf" ;;
amd64) archurl="amd64" ;;
x86_64) archurl="amd64" ;;
i*86) archurl="i386" ;;
x86) archurl="i386" ;;
*) echo "unknown architecture"; exit 1 ;;
esac
wget "https://github.com/AndronixApp/AndronixOrigin/blob/master/Rootfs/Kali/${archurl}/${filename}?raw=true" -O $filename
}
extract_file() {
cd "$installation_dir"
mkdir -p "$folder"
cd "$folder"
echo "Extracting, please be patient..."
proot --link2symlink tar -xJf ${pwd}/${filename}||:
cd "$pwd"
}
create_launch_script() {
echo "=== Creating local launch script===="
cd "$installation_dir"
mkdir -p kali-binds
bin=start-kali
cat > $bin <<- EOM
#!/bin/bash
cd \$(dirname \$0)
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD
command="proot"
command+=" --link2symlink"
command+=" -0"
command+=" -r $folder"
if [ -n "\$(ls -A kali-binds)" ]; then
for f in kali-binds/* ;do
. \$f
done
fi
command+=" -b /dev"
command+=" -b /proc"
command+=" -b kali-fs/root:/dev/shm"
## uncomment the following line to have access to the home directory of termux
#command+=" -b /data/data/com.termux/files/home:/root"
## uncomment the following line to mount /sdcard directly to /
#command+=" -b /sdcard"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
command+=" TERM=\$TERM"
command+=" LANG=C.UTF-8"
command+=" /bin/bash --login"
com="\$@"
if [ -z "\$1" ];then
exec \$command
else
\$command -c "\$com"
fi
EOM
echo "Fixing permission"
termux-fix-shebang $bin
chmod +x $bin
echo "====Adding Start Script to Termux bin===="
termux_bin="/data/data/com.termux/files/usr/bin/start-kali"
cat > $termux_bin <<- EOM
#!/data/data/com.termux/files/usr/bin/sh
bash ${installation_dir}/start-kali
EOM
echo "Fixing permission"
chmod +x $termux_bin
}
main "$@"; exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment