-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.sh
133 lines (115 loc) · 2.9 KB
/
lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
cmd_stop_jack_remote=$(cat <<-EOF
for sig in 15 9; do
pkill -\$sig -f 'jackd.*-d'
pkill -\$sig -f 'jackd.*-ndefault'
pkill -\$sig jack_load
done
EOF
)
err(){
echo "$prog: error: $@"
exit 1
}
msg(){
echo "$prog: $@"
}
yesno(){
[ $1 -eq 0 ] && echo "yes" || echo "NO"
}
checkopt(){
what=$1
val=$2
[ "$what" = "$none" ] && return 1
echo "$what" | grep -q $val
return $?
}
start_jack_local(){
jackd $local_opts -P80 -d net $local_driver_opts >> $log 2>&1 &
ps aux | grep jackd >> $log 2>&1
}
stop_jack_local(){
for sig in 15 9; do
pkill -$sig -f 'jackd.*-d'
pkill -$sig -f 'jackd.*-ndefault'
done
}
# The action of stop_jack_remote is performed in the ssh below so that we don't
# need to ssh twice, which would be slower.
restart_jack_remote(){
eval "$ssh_cmd" <<-EOF
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket
(
echo "kill ..."
$cmd_stop_jack_remote
echo "start jackd ..."
jackd $remote_opts -P80 -d alsa --device $remote_device \
$remote_driver_opts &
while ! pgrep -f 'jackd.*-P.*-d.*alsa.*--device'; do
echo '\$(date) waiting for jackd ...'
sleep 0.1
done
echo "load netmanager ..."
jack_load netmanager -i -c
ps aux | grep jackd
) >> $log 2>&1
EOF
}
stop_jack_remote(){
eval "$ssh_cmd" <<-EOF
(
$cmd_stop_jack_remote
) >> $log 2>&1
EOF
}
stop_jack(){
stop_jack_local
stop_jack_remote
}
check_broken_pulse(){
if ! pactl list sinks > /dev/null 2>&1; then
err "pulseaudio broken, try '$prog -kP'"
fi
}
stop_pulse(){
systemctl --user stop pulseaudio.service pulseaudio.socket
}
restart_pulse(){
systemctl --user restart pulseaudio.service
}
start_pulse_sink(){
# This is only useful if local and remote jackds are already running in
# netjack2 mode (-rj), else a local jackd with default args is started
# (jackd -T -ndefault -T -d alsa), which is useless.
check_broken_pulse
if ! pactl list sinks | grep -q jack_out; then
pactl load-module module-jack-sink >> $log 2>&1
pactl set-sink-mute jack_out false
fi
}
stop_pulse_sink(){
check_broken_pulse
if pactl list modules | grep -q module-jack-sink; then
pactl unload-module module-jack-sink
fi
}
restart_pulse_sink(){
stop_pulse_sink
sleep 0.5
start_pulse_sink
}
do_check_status(){
check_broken_pulse
(
eval "$ssh_cmd" <<-EOF
yesno(){
[ \$1 -eq 0 ] && echo "yes" || echo "NO"
}
pgrep -f 'jackd.*-P.*-d.*alsa.*--device' > /dev/null
echo "remote jackd: \$(yesno \$?)"
EOF
pgrep -f 'jackd.*-P.*-d.*net' > /dev/null
echo "local jackd: $(yesno $?)"
pactl list sinks | grep -q jack_out
echo "jack_out sink: $(yesno $?)"
) | column -t -s:
}