33# Udroid manager to work inside proot environment
44#
55
6- _init ()
7- {
8- :
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 () {
16+ echo -e " ${RED} [!!] ${* }${RST} "
17+ exit 1
18+ :
919}
10- # #####
11- _set ()
12- {
20+ warn () {
21+ echo -e " ${RED} [??] ${* }${RST} "
1322 :
1423}
15-
16- _enable ()
17- {
24+ shout () {
25+ echo -e " ${DS} [●] ${* }${RST} "
1826 :
1927}
20-
21- _start ()
22- {
28+ lshout () {
29+ echo -e " ${DC} -> ${* }${RST} "
2330 :
2431}
25-
26- _createuser ()
27- {
32+ msg () {
33+ echo -e " \e[38;5;228m ${* } \e[0m" >&2
2834 :
2935}
36+
37+ # #####
38+ trim_quotes () {
39+ # Usage: trim_quotes "string"
40+ : " ${1// \' / } "
41+ printf ' %s\n' " ${_// \" / } "
42+ }
3043# #####
3144
32- _start_vnc ()
33- {
34- :
45+ _download_plugin () {
46+
47+ shout " trying to pull plugin from github"
48+ # get plugin
49+ repo_root=" https://raw.githubusercontent.com/RandomCoderOrg/ubuntu-on-android/modified"
50+ suite=$1
51+ de=$2
52+ plugin_url=" $repo_root /pd-plugins/udroid-$suite -$de .sh"
53+
54+ if [ -z " ${suite} " ] || [ -z " ${varient} " ]; then
55+ die " Invalid arguments"
56+ fi
57+
58+ curl \
59+ -L -o $SCRIPT_DIR /udroid-" $suite " -" $de " .sh \
60+ " $plugin_url " || die " Plugin Download failed"
61+
62+ echo udroid-" $suite " -" $de " > " $DEFAULT_CONF "
63+ proot-distro install udroid-" $suite " -" $de " || lshout " installation exited with non-zero exit code"
3564}
3665
37- _stop_vnc ()
66+ _install () {
67+
68+ git clone https://github.com/RandomCoderOrg/udroid-loader.git " $CACHE_ROOT "
69+ cd udroid-loader || exit 1
70+ option=$( bash launch.sh)
71+ distro=$( cut -d " " -f 1 " $option " )
72+ de=$( cut -d " " -f 2 " $option " )
73+ case $distro in
74+ " 2" | " ubuntu21_04" ) suite=' udroid-hirsute' ;;
75+ " 1" | " ubuntu21_10" ) suite=' udroid-impish' ;;
76+ esac
77+ case $de in
78+ " 1" ) de=' xfce4' ;;
79+ " 2" ) de=' mate' ;;
80+ # "3") export de='kde';;
81+ # "4") export de='no_DE' ;;
82+ * ) die " udroid-loader failed" ;;
83+ esac
84+
85+ _download_plugin $suite $de
86+ }
87+
88+ _lauch_or_install ()
3889{
39- :
90+ # condtions
91+
92+ # Udroid Conf-file
93+ if [ ! -f " $DEFAULT_CONF " ]; then
94+ export NO_CONF_FOUND=true
95+ else
96+ launch_suite=$( head -n1 " $DEFAULT_CONF " )
97+ fi
98+
99+ # does DE specified in conf exist?
100+ if [ ! -d $INSTALL_FOLDER /" $launch_suite " ]; then
101+ export NO_SUITE_FOUND=true
102+ fi
103+
104+ if [ $NO_CONF_FOUND ] || [ $NO_SUITE_FOUND ]; then
105+ _install
106+ else
107+ _proot_distro_dispatch ' $*'
108+ fi
109+ }
110+
111+ _proot_distro_dispatch () {
112+ # start pulse server
113+
114+ shout " Starting pulse over 127.0.0.1"
115+ pulseaudio \
116+ --start \
117+ --load=" module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" \
118+ --exit-idle-time=-1 >> /dev/null
119+
120+ cap_last_cap=' --bind /dev/null:/proc/sys/kernel/cap_last_cap'
121+ shared_tmp=' --shared-tmp'
122+
123+ args=" $* $cap_last_cap $shared_tmp "
124+ fargs=" $( trim_quotes " $args " ) "
125+ distro=" $( head -n1 " $DEFAULT_CONF " ) "
126+ shout " starting udroid: $distro "
127+ proot-distro login " $distro " " ${fargs} "
40128}
41129
130+ run_cmd () {
131+ proot-distro login " ${distro} " -- /bin/bash -c " $@ "
132+ }
42133# #####
43134
44- _start_services ()
135+ internet_avalible ()
45136{
46- :
137+ if ping -W 4 -c 1 github.com >> /dev/null; then
138+ return 0
139+ else
140+ return 1
141+ fi
47142}
48143
49- _stop_services ()
50- {
51- :
144+ upgrade () {
145+ if internet_avalible; then
146+ if [ -d $CACHE_ROOT /fs-manager-udroid ]; then
147+ cd fs-manager-udroid || die " failed .."
148+ git pull -v
149+ bash install.sh
150+ else
151+ git clone https://github.com/RandomCoderOrg/fs-manager-udroid " $CACHE_ROOT /fs-manager-udroid"
152+ cd fs-manager-udroid || die " failed .."
153+ bash install.sh
154+ fi
155+ fi
52156}
53157
54- # #####
158+ # #####
159+
160+ if [ $# -ge 1 ]; then
161+ case " $1 " in
162+ --install)
163+ shift 1
164+ _install
165+ ;;
166+ --upgrade)
167+ upgrade
168+ ;;
169+ -v|--version)
170+ msg " udroid fsmgr tool($version ): By SaicharanKandukuri, AnninoDr4"
171+ msg " a tool to launch or manage DE varients without heavy commands"
172+ ;;
173+
174+ * )
175+ _lauch_or_install " $* "
176+ ;;
177+ esac
178+ else
179+ :
180+ fi
0 commit comments