Skip to content

Commit 635151b

Browse files
changed script → udroid
1 parent 0732c2c commit 635151b

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed

etc/scripts/udroid/udroid.sh

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
#!/usr/bin/env bash
2+
3+
version=2
4+
5+
if [ -n "$HIPPO_BRANCH" ]; then
6+
BRANCH="$HIPPO_BRANCH"
7+
fi
8+
9+
CACHE_ROOT="${HOME}/.uoa-cache-root"
10+
TPREFIX="/data/data/com.termux/files"
11+
12+
SCRIPT_DIR="${TPREFIX}/usr/etc/proot-distro"
13+
INSTALL_FOLDER="${TPREFIX}/usr/var/lib/proot-distro/installed-rootfs"
14+
15+
HIPPO_DIR="${INSTALL_FOLDER}/udroid"
16+
HIPPO_SCRIPT_FILE="${SCRIPT_DIR}/udroid.sh"
17+
18+
SOCIAL_PLATFORM="\e[34mhttps://discord.gg/TAqaG5sEfW"
19+
20+
# HIPPO_DIR = "${INSTALL_FOLDER}/${HIPPO_DEFAULT}"
21+
# HIPPO_SCRIPT_FILE="${SCRIPT_DIR}/hippo.sh"
22+
23+
# * Usefull functions
24+
# die() exit with code 1 with printing given string
25+
# warn() like die() without exit status (used when exit is not necessary)
26+
# shout() pring messege in a good way with some lines
27+
# lshout() print messege in a standard way
28+
# msg() print's normal echo
29+
30+
die () { echo -e "${RED}Error ${*}${RST}";exit 1 ;:;}
31+
warn () { echo -e "${RED}Error ${*}${RST}";:;}
32+
shout () { echo -e "${DS}////////";echo -e "${*}";echo -e "////////${RST}";:; }
33+
lshout () { echo -e "${DC}";echo -e "${*}";echo -e "${RST}";:; }
34+
msg () { echo -e "\e[38;5;228m ${*} \e[0m" >&2 ;:; }
35+
36+
37+
function __check_for_hippo() {
38+
if [ -d ${HIPPO_DIR} ] && [ -f ${HIPPO_SCRIPT_FILE} ]; then
39+
return 0;
40+
else
41+
return 1;
42+
fi
43+
}
44+
45+
function __check_for_plugin() {
46+
47+
if [ -f ${HIPPO_SCRIPT_FILE} ]; then
48+
return 0
49+
else
50+
return 1
51+
fi
52+
53+
}
54+
55+
function __check_for_filesystem() {
56+
57+
if [ -d ${HIPPO_DIR}/bin ]; then
58+
return 0
59+
else
60+
return 1
61+
fi
62+
}
63+
64+
function __verify_bin_path()
65+
{
66+
BINPATH="${SHELL}"
67+
68+
if [ -z "$BINPATH" ]; then
69+
if [ "$BINPATH" != "/data/data/com.termux/files/*" ]; then
70+
msg "This has to be done inside termux environment"
71+
die "\$SHELL != $BINPATH"
72+
exit 1
73+
fi
74+
fi
75+
}
76+
77+
function __upgrade() {
78+
# setup downloader
79+
if ! command -v axel >> /dev/null; then
80+
apt install axel -y
81+
fi
82+
83+
mkdir -p "${CACHE_ROOT}"
84+
axel -o "${CACHE_ROOT}"/version https://raw.githubusercontent.com/RandomCoderOrg/fs-manager-hippo/main/version >> /dev/null || {
85+
die "error"
86+
}
87+
88+
origin_version=$(cat "${CACHE_ROOT}"/version)
89+
90+
rm -rf "${CACHE_ROOT}"
91+
92+
if [ "$origin_version" -gt "$version" ]; then
93+
lshout "upgrdae avalibe to \e[1;32mV${origin_version}\e[0m"
94+
elif [ "$origin_version" -eq "$version" ]; then
95+
lshout "You are on latest version \e[1;32mV${origin_version}\e[0m"
96+
exit 0
97+
else
98+
die "Upgrader hit unexpected condition..."
99+
exit 1
100+
fi
101+
102+
if start_upgrade; then
103+
bash -x "${CACHE_ROOT}"/upgrade --summary
104+
rm -rf "${CACHE_ROOT}"
105+
else
106+
die "Error"
107+
fi
108+
109+
110+
}
111+
112+
function start_upgrade() {
113+
mkdir -p "${CACHE_ROOT}"
114+
axel -o "${CACHE_ROOT}"/upgrade.sh https://raw.githubusercontent.com/RandomCoderOrg/fs-manager-hippo/main/etc/scripts/upgrade_patch/upgrade.sh >> /dev/null || {
115+
die "Error"; exit 1
116+
}
117+
bash -x upgrade.sh || {
118+
return 1
119+
}
120+
return 0
121+
}
122+
123+
124+
125+
function __force_uprade_hippo()
126+
{
127+
if [ ! -d "$CACHE_ROOT" ]; then
128+
mkdir "$CACHE_ROOT"
129+
else
130+
rm -rf "${CACHE_ROOT}/fs-manager-hippo"
131+
fi
132+
133+
FSM_URL="https://github.com/RandomCoderOrg/fs-manager-hippo"
134+
135+
if [ -z "${BRANCH}" ]; then
136+
git clone ${FSM_URL} "${CACHE_ROOT}/fs-manager-hippo" || die "failed to clone repo"
137+
else
138+
git clone -b "${BRANCH}" "${CACHE_ROOT}/fs-manager-hippo" || die "failed to clone repo"
139+
fi
140+
141+
if [ -f "${CACHE_ROOT}"/fs-manager-hippo/install.sh ]; then
142+
cd "${CACHE_ROOT}"/fs-manager-hippo || die "failed to cd ..."
143+
bash install.sh || die "failed to install manager..."
144+
fi
145+
}
146+
147+
function __help()
148+
{
149+
msg "hippo - termux Version ${version} by saicharankandukuri"
150+
msg
151+
msg "A bash script to make basic action(login, vncserver) easier for ubuntu-on-android project"
152+
msg
153+
msg "Usage ${0} [options]"
154+
msg
155+
msg "Options:"
156+
msg "--install To try installing hippo"
157+
msg "--help To display this message"
158+
msg "--enable-dbus To start terminal session with dbus enabled"
159+
msg "--force-upgrade To reinstall this script of origin"
160+
msg "startvnc To start hippo vncserver"
161+
msg "stopvnc To stop hippo vncserver"
162+
msg "--enable-dbus-startvnc To start vnc with dbus"
163+
msg "------------------"#links goes here
164+
msg "for additional documentation see: \e[1;34mhttps://github.com/RandomCoderOrg/ubuntu-on-android#basic-usage"
165+
msg "report issues and feature requests at: \e[1;34mhttps://github.com/RandomCoderOrg/ubuntu-on-android/issues"
166+
msg "Join the community at DISCORD -> $SOCIAL_PLATFORM"
167+
msg "------------------"
168+
}
169+
170+
function _lauch_or_install()
171+
{
172+
if ! __check_for_plugin; then
173+
echo -e "Plugin at ${HIPPO_SCRIPT_FILE} is missing ......"
174+
echo -e "May be this not a correct installation...."
175+
echo -e "Try to notice us at \e[34m${SOCIAL_PLATFORM}\e[0m"
176+
exit 1
177+
fi
178+
if ! __check_for_filesystem; then
179+
echo -e "Installing hippo..........."
180+
if proot-distro install hippo; then
181+
echo -e "Installation Done......\a\a" # \a triggers vibration in termux
182+
echo "Waiting..."
183+
sleep 4
184+
clear
185+
echo -e "Now You can launch your ubuntu 21.04 with command \e[1;32mhippo\e[0m"
186+
echo -e "use hippo --help for more option and comming up features"
187+
fi
188+
else
189+
#######################################################################################################
190+
# Thanks to @GxmerSam Sam Alarie, @mizzunet, @Andre-cmd-rgb for the issues randome ideas and suggestion
191+
192+
193+
pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1 >> /dev/null
194+
if [[ -f "${CACHE_ROOT}"/fs-manager-hippo/etc/scripts/vncserver/startvnc.sh ]] && [[ ! -f ${HIPPO_DIR}/bin/startvnc ]]; then
195+
DIR="${CACHE_ROOT}/fs-manager-hippo/etc/scripts/vncserver/startvnc.sh"
196+
cp "${DIR}" ${HIPPO_DIR}/bin/startvnc
197+
proot-distro login hippo -- chmod 775 /bin/startvnc
198+
fi
199+
if [ -f "${CACHE_ROOT}"/fs-manager-hippo/etc/scripts/vncserver/stopvnc.sh ] && [ ! -f ${HIPPO_DIR}/bin/stopvnc ]; then
200+
DIR="${CACHE_ROOT}/fs-manager-hippo/etc/scripts/vncserver/stopvnc.sh"
201+
cp "${DIR}" ${HIPPO_DIR}/bin/stopvnc
202+
proot-distro login hippo -- chmod 775 /bin/stopvnc
203+
fi
204+
proot-distro login hippo "$@" || warn "program exited unexpectedly..."
205+
fi
206+
}
207+
__verify_bin_path
208+
if [ $# -ge 1 ]; then
209+
case "$1" in
210+
upgrade) __upgrade;;
211+
212+
--force-upgrade) __force_uprade_hippo;;
213+
--enable-dbus) shift 1; _lauch_or_install --bind /dev/null:/proc/sys/kernel/cap_last_cap "$@" ;;
214+
"--enable-dbus-startvnc") shift 1; _lauch_or_install --bind /dev/null:/proc/sys/kernel/cap_last_cap -- startvnc "$@" ;;
215+
"--enable-dbus-stopvnc") shift 1; _lauch_or_install --bind /dev/null:/proc/sys/kernel/cap_last_cap -- stopvnc "$@" ;; # no use
216+
--install) _lauch_or_install;;
217+
--help) __help;;
218+
219+
startvnc)
220+
if __check_for_hippo; then
221+
proot-distro login hippo --no-kill-on-exit -- startvnc
222+
else
223+
echo -e "This command is supposed to run after installing hippo"
224+
echo -e "Use \e[1;32mhippo --install\e[0m install"
225+
echo -e "\e[32mError:\e[0m Hippo not found"
226+
fi
227+
;;
228+
229+
stoptvnc)
230+
if __check_for_hippo; then
231+
proot-distro login hippo --no-kill-on-exit -- stoptvnc
232+
else
233+
echo -e "This command is supposed to run after installing hippo"
234+
echo -e "Use \e[1;32mhippo --install\e[0m install"
235+
echo -e "\e[32mError:\e[0m Hippo not found"
236+
fi
237+
;;
238+
*) _lauch_or_install "$@";;
239+
esac
240+
else
241+
_lauch_or_install "$@"
242+
fi

0 commit comments

Comments
 (0)