Skip to content

Commit ba75a5e

Browse files
committed
recode udroid.sh
1 parent 95c5030 commit ba75a5e

File tree

1 file changed

+70
-161
lines changed

1 file changed

+70
-161
lines changed

scripts/udroid/udroid.sh

Lines changed: 70 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,84 @@
1-
#!/usr/bin/env bash
2-
3-
# Udroid manager to work inside proot environment
4-
#
5-
6-
version=2.1
7-
script_name='udroid-manager'
8-
DEFAULT_CONF="${HOME}/.udroid/udroid-lauch.conf"
9-
CACHE_ROOT="${HOME}/.uoa-cache-root"
10-
TPREFIX="/data/data/com.termux/files"
11-
SCRIPT_DIR="${TPREFIX}/usr/etc/proot-distro"
12-
INSTALL_FOLDER="${TPREFIX}/usr/var/lib/proot-distro/installed-rootfs"
13-
DLCACHE="${TPREFIX}/usr/var/lib/proot-distro/dlcache"
14-
15-
die() { echo -e "${RED}[E] ${*}${RST}";exit 1;:;}
16-
warn() { echo -e "${RED}[W] ${*}${RST}";:;}
17-
shout() { echo -e "${DS}[-] ${*}${RST}";:;}
18-
lshout() { echo -e "${DC}-> ${*}${RST}";:;}
19-
msg() { echo -e "${*} \e[0m" >&2;:;}
20-
21-
######
22-
trim_quotes() {
23-
# Usage: trim_quotes "string"
24-
: "${1//\'/}"
25-
printf '%s\n' "${_//\"/}"
26-
}
27-
######
28-
29-
30-
_install() {
31-
distro=$1
32-
suite="impish"
33-
# repo_root="https://raw.githubusercontent.com/RandomCoderOrg/ubuntu-on-android/modified"
34-
repo_root="https://raw.githubusercontent.com/RandomCoderOrg/ubuntu-on-android/beta"
35-
case $distro in
36-
xfce4)
37-
varient="xfce4"
38-
;;
39-
mate)
40-
varient="mate"
41-
;;
42-
raw)
43-
varient="raw"
44-
;;
45-
*)
46-
msg "avalible options: "
47-
msg "xfce4, mate, raw"
48-
;;
49-
esac
50-
shout "installing $varient"
51-
shout "trying to pull plugin from github"
52-
# get plugin
53-
54-
if [ -z "${suite}" ] || [ -z "${varient}" ]; then
55-
die "Invalid arguments"
56-
fi
57-
de="$varient"
58-
plugin_url="$repo_root/pd-plugins/udroid-$suite-$de.sh"
59-
curl \
60-
-L -o $SCRIPT_DIR/udroid-"$suite"-"$de".sh \
61-
"$plugin_url" || die "Plugin Download failed"
62-
63-
echo udroid-"$suite"-"$de" > "$DEFAULT_CONF"
64-
proot-distro install udroid-"$suite"-"$de" || lshout "installation exited with non-zero exit code"
1+
#!/bin/bash
2+
3+
TERMUX="/data/data/com.termux/files"
4+
D_SCRIPTS="${TERMUX}/usr/etc/proot-distro"
5+
D_INSTALLED_ROOTDS="${TERMUX}/usr/var/lib/proot-distro/installed-rootfs"
6+
7+
_login() {
8+
case $1 in
9+
mate) SUITE="mate" shift ;;
10+
xfce|xfce4) SUITE="xfce4" shift ;;
11+
kde) SUITE="kde" shift ;;
12+
*) l_login;;
13+
esac
14+
15+
if [ $# -gt 0 ]; then
16+
extra_args=$*
17+
fi
18+
19+
suite="udroid-impish-$SUITE"
20+
21+
if is_installed $suite; then
22+
l_cache "$suite"
23+
proot-distro login udroid \
24+
--bind /dev/null:/proc/sys/kernel/cap_last_cap \
25+
--shared-tmp \
26+
$extra_args
27+
else
28+
msg "looks like $SUITE is not installed."
29+
msg "use udroid -i $SUITE"
30+
fi
6531

6632
}
6733

68-
_lauch_or_install()
69-
{
70-
# condtions
71-
72-
# Udroid Conf-file
73-
if [ ! -f "$DEFAULT_CONF" ]; then
74-
export NO_CONF_FOUND=true
75-
else
76-
launch_suite=$( head -n1 "$DEFAULT_CONF" )
77-
fi
78-
79-
# does DE specified in conf exist?
80-
if [ ! -d $INSTALL_FOLDER/"$launch_suite" ]; then
81-
export NO_SUITE_FOUND=true
82-
fi
83-
84-
if [ $NO_CONF_FOUND ] || [ $NO_SUITE_FOUND ]; then
85-
_install
86-
else
87-
_proot_distro_dispatch '$*'
88-
fi
34+
l_login() {
35+
if [ -f "${HOME}/.udroid/logindistro_cache" ]; then
36+
if [ -s "${HOME}/.udroid/logindistro_cache" ]; then
37+
login "$(${HOME}/.udroid/logindistro_cache)"
38+
fi
39+
else
40+
_msg "login"
41+
fi
8942
}
9043

91-
_proot_distro_dispatch() {
92-
# start pulse server
93-
## ENV: PULSE SERVER LISTENER
94-
if [ -n "$PULSE_LISTENER" ]; then
95-
listener="$PULSE_LISTENER"
96-
else
97-
listener="127.0.0.1"
98-
fi
99-
msg "Starting pulse server at $listener"
100-
pulseaudio \
101-
--start \
102-
--load="module-native-protocol-tcp auth-ip-acl=$listener auth-anonymous=1" \
103-
--exit-idle-time=-1 >>/dev/null
104-
#
105-
106-
cap_last_cap='--bind /dev/null:/proc/sys/kernel/cap_last_cap'
107-
shared_tmp='--shared-tmp'
108-
109-
args="$* $cap_last_cap $shared_tmp"
110-
fargs="$(trim_quotes "$args")"
111-
distro="$( head -n1 "$DEFAULT_CONF" )"
112-
shout "starting udroid: $distro"
113-
proot-distro login "$distro" "${fargs}"
114-
}
11544

116-
run_cmd() {
117-
proot-distro login "${distro}" -- /bin/bash -c "$@"
118-
}
119-
######
120-
121-
internet_avalible()
122-
{
123-
if ping -W 4 -c 1 github.com >> /dev/null; then
124-
return 0
125-
else
126-
return 1
127-
fi
45+
_install() {
46+
SUITE=$1
47+
plugin_loation="https://raw.githubusercontent.com/RandomCoderOrg/ubuntu-on-android/beta/pd-plugins"
48+
49+
final_suite="udroid-impish-$SUITE"
50+
51+
if is_installed $final_suite; then
52+
msg "$SUITE already installed."
53+
exit 1
54+
fi
55+
56+
shout "Installing $final_suite"
57+
if [ ! -f "${D_SCRIPTS}/${final_suite}.sh" ] ; then
58+
download "${plugin_loaction}/${final_suite}.sh" $D_SCRIPTS
59+
fi
60+
shout "starting proot-distro"
61+
proot-distro install $final_suite
12862
}
12963

130-
upgrade() {
131-
if internet_avalible; then
132-
if [ -d $CACHE_ROOT/fs-manager-udroid ]; then
133-
cd fs-manager-udroid || die "failed .."
134-
git pull -v
135-
bash install.sh
136-
else
137-
git clone https://github.com/RandomCoderOrg/fs-manager-udroid "$CACHE_ROOT/fs-manager-udroid"
138-
cd fs-manager-udroid || die "failed .."
139-
bash install.sh
140-
fi
141-
fi
142-
}
64+
l_cache() {
65+
if [ ! -d ${HOME}/.udroid ]; then
66+
mkdir ${HOME}/.udroid
67+
fi
14368

144-
_reset() {
145-
:
69+
cat $1 > ${HOME}/.udroid/logindistro_cache
14670
}
14771

148-
_purge() {
149-
:
72+
download() {
73+
url=$1
74+
location=$2
75+
curl -L -o $location $url
15076
}
15177

152-
######
153-
154-
if [ $# -ge 1 ]; then
155-
case "$1" in
156-
--install|-i)
157-
shift 1
158-
_install "$@"
159-
;;
160-
--upgrade)
161-
upgrade
162-
;;
163-
-v|--version)
164-
msg "udroid fsmgr tool($version): By Team UDROID!..."
165-
;;
166-
--reset|--reinstall) _reset;;
167-
--purge|--uninstall) _purge;;
168-
--restore) restore;;
169-
*)
170-
_lauch_or_install "$*"
171-
;;
172-
esac
173-
else
174-
_lauch_or_install
78+
if [ $# -ge 0 ]; then
79+
case $1 in
80+
-l) shift _login $* ;;
81+
-i|--install) shift _install $1 ;;
82+
*) l_login;;
83+
esac
17584
fi

0 commit comments

Comments
 (0)