Skip to content

Commit d353ad7

Browse files
revamp st1
1 parent a48b176 commit d353ad7

File tree

2 files changed

+289
-26
lines changed

2 files changed

+289
-26
lines changed

etc/proot-env/udroid/udroid.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
3+
die() {
4+
echo -e "${RED}[!!] ${*}${RST}"
5+
exit 1
6+
:
7+
}
8+
warn() {
9+
echo -e "${RED}[??] ${*}${RST}"
10+
:
11+
}
12+
shout() {
13+
echo -e "${DS}[●] ${*}${RST}"
14+
:
15+
}
16+
lshout() {
17+
echo -e "${DC}-> ${*}${RST}"
18+
:
19+
}
20+
msg() {
21+
echo -e "\e[38;5;228m ${*} \e[0m" >&2
22+
:
23+
}
24+
25+
function _backup() {
26+
# defaults
27+
default_backup_dir="/sdcard/Downloads"
28+
default_file_name=""
29+
of="/sdcard/udroid-backup.tar.gz"
30+
31+
if [ $# -ge 1 ]; then
32+
case "$1" in
33+
-h | --help)
34+
_help backup
35+
;;
36+
-o | --output)
37+
shift
38+
of="$*"
39+
;;
40+
esac
41+
fi
42+
shout "Backing up to $of/udroid-backup.tar.gz ..."
43+
of="$of/udroid-backup.tar.gz"
44+
45+
tar \
46+
--exclude=/dev/* \
47+
--exclude=/run/* \
48+
--exclude=/proc/* \
49+
--exclude=/sys/* \
50+
--exclude=/tmp/* \
51+
--exclude=/"${0}" \
52+
--exclude="/$of" \
53+
--exclude-caches-all \
54+
--one-file-system \
55+
-cpf \
56+
- "/" -P |
57+
pv -s $(($(du -skx "/" | awk '{print $1}') * 1024)) |
58+
gzip --best >"$of".tar.gz
59+
60+
}
61+
62+
_help() {
63+
# * TODO:
64+
:
65+
}
66+
67+
function service_exec() {
68+
if [ -f /usr/share/udroid/auto_start_service ]; then
69+
grep -v '^ *#' </usr/share/udroid/auto_start_service | while IFS= read -r _service; do
70+
lshout "starting service ${_service}"
71+
service start "${_service}"
72+
done
73+
fi
74+
}
75+
76+
function startvnc() {
77+
pubip=$(hostname -I)
78+
port=':1'
79+
80+
if [[ -n $PORT ]] && [[ $PORT =~ ^[0-9]+$ ]]; then
81+
port="$PORT"
82+
fi
83+
84+
if [ -f /tmp/.X11-unix/X"${port}" ]; then
85+
vnc=true
86+
else
87+
vnc=false
88+
fi
89+
90+
if [ -f /tmp/.X"${port}"-lock ]; then
91+
vnc=true
92+
else
93+
vnc=false
94+
fi
95+
96+
if ! $vnc; then
97+
vncserver -xstartup "${DEFAULT_XSTARTUP}" -localhost no -desktop "udroid Default VNC" :${port}
98+
else
99+
echo "A vncserver lock is found for port ${port}"
100+
die "try using stopvnc"
101+
fi
102+
103+
}
104+
105+
function stopvnc() {
106+
port=':1'
107+
108+
shout "stoping vnc..."
109+
if [[ -n $PORT ]] && [[ $PORT =~ ^[0-9]+$ ]]; then
110+
port="$PORT"
111+
fi
112+
113+
vncserver --kill :1 >> /dev/null
114+
115+
if [ -f /tmp/.X11-unix/X"${port}" ]; then
116+
rm -rv /tmp/.X11-unix/X"${port}"
117+
fi
118+
119+
if [ -f /tmp/.X"${port}"-lock ]; then
120+
rm -rv /tmp/.X"${port}"-lock
121+
fi
122+
123+
msg "Done..."
124+
}
125+
126+
function start_display() {
127+
:
128+
}
129+
130+
function on_startup() {
131+
service_exec
132+
}
133+
134+
function _init() {
135+
on_startup
136+
137+
}

etc/scripts/udroid/udroid-proot.sh

Lines changed: 152 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,178 @@
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

Comments
 (0)