Skip to content

Commit b7195b5

Browse files
update login functionality
1 parent d1606fa commit b7195b5

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

scripts/udroid/udroid.sh

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ TERMUX="/data/data/com.termux/files"
44
D_SCRIPTS="${TERMUX}/usr/etc/proot-distro"
55
D_INSTALLED_ROOTFS="${TERMUX}/usr/var/lib/proot-distro/installed-rootfs"
66
D_CACHCE="${HOME}/.udroid-cache-root"
7+
LOGIN_CACHE_FILE="${D_CACHCE}/login_rec.cache"
78

89
_c_magneta="\e[95m"
910
_c_green="\e[32m"
@@ -15,51 +16,65 @@ die() { echo -e "${_c_red}[E] ${*}${RST}";exit 1;:;}
1516
warn() { echo -e "${_c_red}[W] ${*}${RST}";:;}
1617
shout() { echo -e "${_c_blue}[-] ${*}${RST}";:;}
1718
lshout() { echo -e "${_c_blue}-> ${*}${RST}";:;}
19+
imsg() { if $UDROID_VERBOSE; then echo -e ": ${*} \e[0m" >&2;fi;:;}
1820
msg() { echo -e "${*} \e[0m" >&2;:;}
1921

2022
_login() {
21-
case $1 in
22-
mate) SUITE="mate" shift ;;
23-
xfce|xfce4) SUITE="xfce4" shift ;;
24-
kde) SUITE="kde" shift ;;
25-
*) l_login $*;;
26-
esac
2723

28-
if [ $# -gt 0 ]; then
29-
extra_args=$*
24+
varient=$1; shift
25+
extra_args=$*
26+
27+
cd "$D_INSTALLED_ROOTFS" || die "$D_INSTALLED_ROOTFS Not Found.."
28+
avalible_distros=$(find $D_INSTALLED_ROOTFS -maxdepth 1 -type d | grep udroid)
29+
cd "$OLDPWD" || exit
30+
31+
if [ -n "$UDROID_SUITE" ]; then
32+
default_suite="impish"
33+
else
34+
msg "udroid suite [\$UDROID_SUITE] is set to ${UDROID_SUITE}"
3035
fi
3136

32-
suite="udroid-impish-$SUITE"
37+
distro="${default_suite}-${varient}"
38+
if [[ $avalible_distros =~ $distro ]]; then
39+
# store distro aliases in cache
40+
echo "$distro" > "$LOGIN_CACHE_FILE"
3341

34-
if is_installed $suite; then
35-
l_cache "$suite"
36-
37-
pulseaudio \
38-
--start \
39-
--load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" \
40-
--exit-idle-time=-1 >> /dev/null
41-
42-
proot-distro login udroid \
43-
--bind /dev/null:/proc/sys/kernel/cap_last_cap \
44-
--shared-tmp \
45-
$extra_args
42+
# start distro
43+
start "${default_suite}-${varient}" $extra_args
4644
else
47-
msg "looks like $SUITE is not installed."
48-
msg "use udroid -i $SUITE"
45+
# TODO: ADD SUGGESTIONS
46+
lwarn "$distro not found..."
4947
fi
48+
}
49+
50+
start() {
51+
52+
distro=$1; shift
53+
extra_args="--bind /dev/null:/proc/sys/kernel/cap_last_cap \
54+
--shared-tmp \
55+
$extra_args"
5056

57+
# start Pulse Audio tcp receiver
58+
59+
imsg "Starting pulseaudio"
60+
61+
# TODO: CHECK IS Pulseaudio RUNNING BEFORE EXECUTING
62+
pulseaudio \
63+
--start \
64+
--load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" \
65+
--exit-idle-time=-1 >> /dev/null
66+
67+
imsg "Starting $distro.."
68+
proot-distro login "$distro" "$extra_args"
5169
}
5270

5371
l_login() {
54-
if [ -f "${HOME}/.udroid/logindistro_cache" ]; then
55-
if [ -s "${HOME}/.udroid/logindistro_cache" ]; then
56-
login "$(${HOME}/.udroid/logindistro_cache)" $*
57-
fi
58-
else
59-
_msg "login"
72+
if [ -f "$LOGIN_CACHE_FILE" ]; then
73+
start "$(cat LOGIN_CACHE_FILE)"
6074
fi
6175
}
6276

77+
6378
_install() {
6479
SUITE=$1
6580

@@ -159,14 +174,6 @@ is_installed() {
159174
return 0
160175
}
161176

162-
l_cache() {
163-
if [ ! -d ${HOME}/.udroid ]; then
164-
mkdir ${HOME}/.udroid
165-
fi
166-
167-
cat $1 > ${HOME}/.udroid/logindistro_cache
168-
}
169-
170177
download() {
171178
url=$1
172179
location=$2

0 commit comments

Comments
 (0)