#!/data/data/com.termux/files/usr/bin/bash
## Linux Deploy Assistant
## Author Arie-SR91

red='\033[1;91m'
green='\033[1;92m'
yellow='\033[1;93m'
blue='\033[1;96m'
white='\033[1;97m'
crrenttime="$(date +'%r')"
crrentdatenow=$(date +'%a %d/%m/%Y')
source /data/data/ru.meefik.linuxdeploy/files/cli.conf
source /data/data/ru.meefik.linuxdeploy/files/config/$PROFILE.conf
username=$USER_NAME

function help() {
    echo "Run your Linux Deploy via Termux.

Usage: runlinux [options]

options:
    -s, --shell      Start/mount linux deploy cli from termux.
    -m, --mount      Start/mount containers from termux.
    -u, --umount     Stop/umount containers from termux.
    -v, --vnc        Start Linux Deploy and VNC app.
    -x, --x11        Start Linux Deploy and X11.
    -h, --help       Show this screen.

For more info about update visit my github.
https://github.com/ArieSR91
"
}

function login() {
    pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1
    clear
    return 0
}

function shell() {
    login
    linuxdeploy shell -u $username
    umount
    return 0
}

function mount() {
    login
    linuxdeploy start -m
    return 0
}

function umount() {
    linuxdeploy stop -u
    pulseaudio --kill
    return 0
}

function desktop() {
    login
    termux-open vnc://127.0.0.1:5900
    mount
    return 0
}

function x11() {
    login
    sudo x11
    pulseaudio --kill
    return 0
}

case $1 in
    -s | --shell)
        shell
        ;;
    -m | --mount)
        mount
        ;;
    -u | --umount)
        umount
        ;;
    -v | --vnc)
        desktop
        ;;
    -x | --x11)
        x11
        ;;
    * | -h | --help)
        help
        ;;
esac
