#!/bin/bash # Termux Prefix Switcher # This Program will switch Termux Environment from 64-bit to 32-bit # Android 5/6 isn't supported currently case "$(getprop ro.build.version.release)" in 5*|6*) echo "Android 5/6 isn't supported" exit 2 ;; *) ;; esac unset LD_PRELOAD BOOTSTRAP_ARM="https://github.com/Hamzahash/termux-bootstrap/blob/main/arm/bootstrap-arm.zip?raw=true" BOOTSTRAP_INTEL="https://github.com/Hamzahash/termux-bootstrap/blob/main/arm/bootstrap-i686.zip?raw=true" TEMPDIR="$(mktemp -d)" print-help(){ cat <<- EOM Termux Prefix Switcher: Allows to switch 32-bit termux environment on 64-bit devices Options: help - show this help switch - Switches to 32-bit Mode revert - Reverts to 64-bit Mode (This Uninstalls 32-bit prefix) NOTE: Switching to 32-bit will not install packages automatically so you have to install them again if possible Termux Prefix Switcher (version 1.3) EOM } switch(){ # Check if running as 32-bit case "$(uname -m)" in armv8*|armv7*|i*86) cat <<- EOM Cannot Switch Environment: Your device is running in 32-bit EOM exit 2 ;; *) ;; esac # Print some warning message cat <<- EOM WARNING: You are about to enter the world of 32-bit, here's what you will expect when entering to 32-bit * Inconsistency will occur when running 64-bit on 32-bit environment, in some cases with the preloaded termux-exec library, you can usually unset it * When Running Chromium in 32-bit proot'ed linux environment, expect segmentation failures (even with --no-sandbox) option, * This Script will not track what packages you've installed, so you will need to reinstall them again if possible The Installation will begin in 5 seconds, please save all your work to avoid data loss EOM sleep 5.5 echo "[*] Downloading 32-bit termux bootstrap" case "$(uname -m)" in aarch64) curl --fail --location --output $TEMPDIR/termux-bootstrap.zip.part "$BOOTSTRAP_ARM" ;; x86_64) curl --fail --location --output $TEMPDIR/termux-bootstrap.zip.part "$BOOTSTRAP_INTEL" ;; *) exit 2 esac # Check if file is downloaded properly if [ -e $TEMPDIR/termux-bootstrap.zip.part ]; then mv $TEMPDIR/termux-bootstrap.zip.part $TEMPDIR/termux-bootstrap.zip else echo "An error has occured, Aborting Installation" exit 2 fi # Unpack and remove existing installation echo "[*] Unpacking 32-bit termux bootstrap" sleep 3 chmod 755 usr -R ||: rm -rf $PREFIX/../usr32-staging unzip -d $PREFIX/../usr32-staging $TEMPDIR/termux-bootstrap.zip # Process Symlinks echo "[*] Processing Symlinks" cd $PREFIX/../usr32-staging while read s; do ln -s ${s/←/ } done $PREFIX/../secondstage-setup.sh <<- EOM #!/system/bin/sh echo "[*] Creating Backup" mv usr usr64-backup echo "[*] Switching" mv usr32-staging usr rm secondstage-setup.sh echo "[✓] Done, Please Close and Reopen the app" sleep 2 kill -KILL $PPID EOM chmod 755 $PREFIX/../secondstage-setup.sh cd $PREFIX/.. # Kill Current Process and Do Second Stage Setup exec /system/bin/env -i ./secondstage-setup.sh } revert(){ # Check if running in 64-bit mode case "$(uname -m)" in aarch64|x86_64) echo "This option is used to switching back to 64-bit, you're already 64-bit" exit 2 ;; *) ;; esac # Ask for Confirmation read -p "Do you want to switch back to 64-bit? All data in this environment will be lost [y/N] " answer case "$answer" in Y*|y*) ;; *) echo "Aborting...."; exit 2 ;; esac # Switch back to 64-bit cd $PREFIX/.. # Check if Backup File Exists if [ ! -e usr64-backup ]; then echo "[!] The Backup Directory isn't exists.. Continuing Anyway!" fi # Revert Back to 64-bit echo "[*] Purging 32-bit environment" cat > purge-prefix.sh <<- EOM #!/system/bin/sh chmod 755 usr -R ||: rm -rf usr # Restore Backup directory if possible" if [ -e usr64-backup ]; then echo "[*] Restoring 64-bit Prefix" mv usr64-backup usr fi rm -rf purge-prefix.sh echo "[✓] Done, Please Close and Reopen the app" sleep 2 kill -KILL $PPID EOM chmod 755 purge-prefix.sh # Kill Current Process and Purge 32-bit prefix exec /system/bin/env -i ./purge-prefix.sh } args="$1" if [ -z "$args" ]; then print-help exit 2 fi case "$args" in help) print-help ;; switch) switch ;; revert) revert ;; *) cat <<- EOM Unknown Argument: $args See "termux-prefix-switcher help" for more information EOM ;; esac # END OF MESSAGE EOM