#!/data/data/com.termux/files/usr/bin/env bash

# Setups a Termux system the way I like it

if [ ! -d /data/data/com.termux/files ]; then
    echo "This is not a Termux system (or pacman isn't installed)"
    return 1
fi

# Configuration
function prompt { # text
    while true; do
        read -p "$1 [yn] " yn
        case $yn in
            [Yy]* ) return 1;;
            [Nn]* ) return 0;;
            * ) echo "Please answer yes or no.";;
        esac
    done
}

if [ -z $ROOT ]; then
    prompt "Is this device rooted and BusyBox installed in /system/xbin/?"
    ROOT=$?
fi

# Update
apt update
apt upgrade

# (needed for install-prefs)
apt install coreutils
apt install grep

# Config
touch ~/.hushlogin

if [ $ROOT == 1 ]; then
    apt install tsu
    echo '/system/xbin/mount -o remount,rw /; ln -s /data/data/com.termux/files/usr /usr; /system/xbin/mount -o remount,ro /' | tsu
fi