Skip to content

Commit bbef846

Browse files
add pulseaudio
1 parent 2f635b1 commit bbef846

File tree

1 file changed

+78
-40
lines changed

1 file changed

+78
-40
lines changed

scripts/udroid/udroid.sh

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ msg() { echo -e "${*} \e[0m" >&2;:;}
2121

2222
_satisfy_deps() {
2323
### Deps
24-
for deb in {proot-distro,proot,tar}; do
25-
if ! command -v $deb >> /dev/null; then
24+
for deb in {proot-distro,proot,tar,pulseaudio}; do
25+
if ! command -v $deb >>/dev/null; then
2626
missing_debs="$deb $missing_debs"
2727
fi
2828
done
@@ -35,28 +35,40 @@ _satisfy_deps() {
3535

3636
_login() {
3737

38-
varient=$1; shift
38+
varient=$1
39+
shift
3940
extra_args=$*
4041

4142
cd "$D_INSTALLED_ROOTFS" || die "$D_INSTALLED_ROOTFS Not Found.."
4243
avalible_distros=$(find $D_INSTALLED_ROOTFS -maxdepth 1 -type d | grep udroid)
4344
cd "$OLDPWD" || exit
4445

45-
if [ -z "$UDROID_SUITE" ] && [ -z "$_SUITE" ] ; then
46+
if [ -z "$UDROID_SUITE" ] && [ -z "$_SUITE" ]; then
4647
suite="udroid-focal"
4748
else
4849
[[ -n "$UDROID_SUITE" ]] && suite="$UDROID_SUITE"
4950
[[ -n "$_SUITE" ]] && suite="$_SUITE"
5051
msg "udroid suite is set to ${_SUITE}"
5152
fi
5253

53-
distro="$suite-$varient"
54+
distro="udroid-$_suite-$varient"
5455
if [[ $avalible_distros =~ $distro ]]; then
55-
# store distro aliases in cache
56-
echo "$distro" > "$LOGIN_CACHE_FILE"
57-
58-
# start distro
59-
start "$distro" $extra_args
56+
if is_installed "$distro"; then
57+
# store distro aliases in cache
58+
echo "$distro" >"$LOGIN_CACHE_FILE"
59+
# start distro
60+
start "$distro" $extra_args
61+
else
62+
msg "${_c_blue} ${distro} is either not installed.."
63+
msg "${_c_blue}Available distros to login:"
64+
for distro in $avalible_distros; do
65+
msg " ${_c_magneta}$(basename $distro)${RST}"
66+
done
67+
msg
68+
69+
msg "${_c_blue}use ${_c_magneta}udroid -l <distro>${RST} to login"
70+
msg "ex: ${_c_magneta}udroid -l xfce4${RST}"
71+
fi
6072
else
6173
# TODO: ADD SUGGESTIONS
6274
warn "$distro not found..."
@@ -65,7 +77,8 @@ _login() {
6577

6678
start() {
6779

68-
distro=$1; shift
80+
distro=$1
81+
shift
6982
extra_args=$*
7083

7184
# start Pulse Audio tcp receiver
@@ -76,12 +89,12 @@ start() {
7689
pulseaudio \
7790
--start \
7891
--load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" \
79-
--exit-idle-time=-1 >> /dev/null
92+
--exit-idle-time=-1 >>/dev/null
8093

8194
imsg "Starting $distro.. with args\n--bind /dev/null:/proc/sys/kernel/cap_last_cap\n--shared-tmp "
8295
proot-distro login "$distro" --bind /dev/null:/proc/sys/kernel/cap_last_cap \
83-
--shared-tmp \
84-
$extra_args
96+
--shared-tmp \
97+
$extra_args
8598
}
8699

87100
l_login() {
@@ -103,10 +116,9 @@ l_login() {
103116
fi
104117
}
105118

106-
107119
_install() {
108120
SUITE=$1
109-
121+
110122
# make sure to satisy old docs
111123
if [ -z "$SUITE" ]; then
112124
imsg "falling back to defaults"
@@ -116,10 +128,10 @@ _install() {
116128
# relative path of plugins with respect to pd-plugins dir
117129
# set this when you need to install another suite
118130
if [ -n "$OVERRIDE_REMOTE_PLUGIN_DIR" ] || [ -n "$_SUITE" ]; then
119-
131+
120132
[[ -n "$OVERRIDE_REMOTE_PLUGIN_DIR" ]] && REMOTE_PLUGIN_DIR="$OVERRIDE_REMOTE_PLUGIN_DIR"
121133
[[ -n "$_SUITE" ]] && REMOTE_PLUGIN_DIR="$_SUITE"
122-
134+
123135
warn "overriding remote plugin dir with $REMOTE_PLUGIN_DIR"
124136
else
125137
REMOTE_PLUGIN_DIR="default"
@@ -139,13 +151,13 @@ _install() {
139151
download $plugin_location/plugins.prop "$D_CACHCE"/plugins.prop
140152

141153
source $D_CACHCE/plugins.prop || die "failed to parse plugin data..?"
142-
154+
143155
for v in "${avalibe_varients[@]}"; do
144156
if [ "$v" == "$SUITE" ]; then
145157
varient=$SUITE
146158
fi
147159
done
148-
160+
149161
if [ -z "$varient" ]; then
150162
warn "unknown varient: $SUITE"
151163
msg "varients founds: ${avalibe_varients[*]}"
@@ -161,18 +173,19 @@ _install() {
161173
fi
162174

163175
shout "Installing $final_suite"
164-
if [ ! -f "${D_SCRIPTS}/${final_suite}.sh" ] ; then
165-
download "${plugin_location}/${final_suite}.sh" $local_target
176+
if [ ! -f "${D_SCRIPTS}/${final_suite}.sh" ]; then
177+
download "${plugin_location}/${final_suite}.sh" $local_target
166178
fi
167179
shout "starting proot-distro"
168180
proot-distro install $final_suite
169181
}
182+
170183
_reset() {
171184

172185
avalible_distros=$(find $D_INSTALLED_ROOTFS -maxdepth 1 -type d | grep udroid)
173186
varient=$1
174187

175-
if [ -z "$UDROID_SUITE" ] && [ -z "$_SUITE" ] ; then
188+
if [ -z "$UDROID_SUITE" ] && [ -z "$_SUITE" ]; then
176189
_suite="udroid-focal"
177190
else
178191
[[ -n "$UDROID_SUITE" ]] && _suite="$UDROID_SUITE"
@@ -192,7 +205,7 @@ _remove() {
192205
avalible_distros=$(find $D_INSTALLED_ROOTFS -maxdepth 1 -type d | grep udroid)
193206
varient=$1
194207

195-
if [ -z "$UDROID_SUITE" ] && [ -z "$_SUITE" ] ; then
208+
if [ -z "$UDROID_SUITE" ] && [ -z "$_SUITE" ]; then
196209
_suite="udroid-focal"
197210
else
198211
[[ -n "$UDROID_SUITE" ]] && _suite="$UDROID_SUITE"
@@ -201,19 +214,19 @@ _remove() {
201214
fi
202215
suite="${_suite}-$varient"
203216

204-
if is_installed "$suite"; then
205-
proot-distro remove $suite
206-
else
207-
warn "$SUITE is not installed."
208-
fi
217+
if is_installed "$suite"; then
218+
proot-distro remove $suite
219+
else
220+
warn "$SUITE is not installed."
221+
fi
209222
}
210223

211224
upgrade() {
212225
shout "Upgrade.."
213226
url_host="https://raw.githubusercontent.com"
214227
url_org="/RandomCoderOrg"
215228
repo="/fs-manager-udroid"
216-
229+
217230
if [ -n "$OVERRIDE_BRANCH" ]; then
218231
BRANCH=$OVERRIDE_BRANCH
219232
else
@@ -226,7 +239,7 @@ upgrade() {
226239
if [ -f "$TERMUX/usr/bin/udroid" ]; then
227240
rm -rf "$TERMUX/usr/bin/udroid"
228241
fi
229-
242+
230243
download "$url" "$TERMUX/usr/bin/udroid" || {
231244
warn "failed to sync tool with GitHub"
232245
exit 1
@@ -237,7 +250,7 @@ upgrade() {
237250

238251
is_installed() {
239252
target_suite=$1
240-
253+
241254
if [ ! -f "${D_SCRIPTS}/${target_suite}.sh" ]; then
242255
return 1
243256
fi
@@ -267,13 +280,38 @@ _satisfy_deps
267280

268281
while [ $# -gt 0 ]; do
269282
case $1 in
270-
--suite) shift; _SUITE="$1"; shift ;;
271-
-l) shift; _login $*; break ;;
272-
-i|--install) shift;_install $1; exit 0 ;;
273-
-re|--reset) shift ; _reset $1; exit 0 ;;
274-
-r|--remove) shift ; _remove $1; exit 0 ;;
275-
-S|--sync|--upgrade) upgrade; exit 0 ;;
276-
*) l_login $*; break;;
283+
--suite)
284+
shift
285+
_SUITE="$1"
286+
shift
287+
;;
288+
-l)
289+
shift
290+
_login $*
291+
break
292+
;;
293+
-i | --install)
294+
shift
295+
_install $1
296+
exit 0
297+
;;
298+
-re | --reset)
299+
shift
300+
_reset $1
301+
exit 0
302+
;;
303+
-r | --remove)
304+
shift
305+
_remove $1
306+
exit 0
307+
;;
308+
-S | --sync | --upgrade)
309+
upgrade
310+
exit 0
311+
;;
312+
*)
313+
l_login $*
314+
break
315+
;;
277316
esac
278317
done
279-

0 commit comments

Comments
 (0)