Skip to content

Commit

Permalink
Merge pull request #1 from F-i-f/master
Browse files Browse the repository at this point in the history
Security fixes and others
  • Loading branch information
brummer10 committed Mar 23, 2020
2 parents 9957610 + 1ab2f91 commit a163b5f
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions pajackconnect
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#
# in the field labelled “Execute script after Shutdown”.
#
# for use jack without pulseaudio, add in Qjackctl setting window
# in the serverpath field 'pasuspender -- ' before 'jackd', save settings
# as "No Pulse" for example. Remove 'pasuspender -- ',
# and save settings as 'Pulse'. Now you can select from the
# for use jack without pulseaudio, add in Qjackctl setting window
# in the serverpath field 'pasuspender -- ' before 'jackd', save settings
# as "No Pulse" for example. Remove 'pasuspender -- ',
# and save settings as 'Pulse'. Now you can select from the
# Qjackctl setting window, if you would start jack with or without pulse.
#
# References:
Expand All @@ -39,13 +39,20 @@
# overall script formating by Hermann Meyer
# added possibility to run jack with suspend pulse by Hermann Meyer
# added save and restore previous used pulseaudio ports by Hermann Meyer
# added reload pulse jack modules after resume from suspend
# added reload pulse jack modules after resume from suspend
# (needs to be called by a systemd.service file) by Hermann Meyer
#-


# variable to fetch pasuspender status
p=`ps ax | grep pasuspender`
# variable to fetch pasuspender status
p=`ps ax | grep '[p]asuspender'`
if [ "${XDG_RUNTIME_DIR-}" != "" ]
then
pajack_dir="$XDG_RUNTIME_DIR/pulse"
else
pajack_dir="/tmp/pajackconnect-${LOGNAME-${USER-}}"
fi
mkdir -m 700 -p "$pajack_dir"

function restart() {
# reload pulse jack module after resume from suspend.
Expand All @@ -59,23 +66,23 @@ function restart() {
#echo "pasuspender is active"
exit 0
else
# check if pulse jack modules are loaded
jc=`pacmd list | grep jack-sink`
# check if jack is running
ja=`pidof jackd | wc -w`
# check if pulseaudio is running
pa=`pidof pulseaudio | wc -w`
# write results to log file
`date +%H:%M:%S >>/tmp/pajack.log`
`echo 'jack-sink =' $jc >>/tmp/pajack.log`
`echo 'jack =' $ja >>/tmp/pajack.log`
`echo 'pulse =' $pa >>/tmp/pajack.log`
# check if pulse jack modules are loaded
jc=`pacmd list | grep jack-sink`
# check if jack is running
ja=`pidof jackd | wc -w`
# check if pulseaudio is running
pa=`pidof pulseaudio | wc -w`
# write results to log file
date +%H:%M:%S >>"$pajack_dir/pajack.log"
echo 'jack-sink =' $jc >>"$pajack_dir/pajack.log"
echo 'jack =' $ja >>"$pajack_dir/pajack.log"
echo 'pulse =' $pa >>"$pajack_dir/pajack.log"
if [[ ! "$jc" =~ "jack" ]] && [[ "$ja" == "1" ]]; then
# if pulseaudio didn't run, let's try start it
if [[ ! "$pa" == "1" ]]; then
sleep 5
`pulseaudio -D`
`echo reload pulseaudio >>/tmp/pajack.log`
pulseaudio -D
echo reload pulseaudio >>"$pajack_dir/pajack.log"
sleep 10
fi
# if jack is running and pulse jack modules aren't loaded,
Expand All @@ -87,16 +94,16 @@ function restart() {
# move around source port, seems to make pulseaudio work with jack
# otherwise it seems that pulseaudio is connected, but it didn't work.
pacmd set-default-source jack_in && sleep 1
source=`cat /tmp/pasourcej`
source=`cat "$pajack_dir"/pasourcej`
pacmd set-default-source $source && sleep 1
pacmd set-default-source jack_in
# echo "pa source switched"
`echo reloaded jack modules >>/tmp/pajack.log`
echo reloaded jack modules >>"$pajack_dir/pajack.log"
else
`echo already run >>/tmp/pajack.log`
echo already run >>"$pajack_dir/pajack.log"
fi
fi
}
}

function start() {
# if command-line option start is given
Expand All @@ -107,12 +114,12 @@ function start() {
exit 0
else
# if pasuspender isn't waiting for jack, let's fetch the current
# ports, pulseaudio use, save them to /tmp, for later use.
# ports, pulseaudio use, save them to "$pajack_dir", for later use.
#echo "pasuspender is NOT active"
sink=`pacmd list short sinks | sed -n "/Default sink name/p"| sed "s/Default sink name://"`
`echo $sink >/tmp/pasinkj`
echo $sink >"$pajack_dir"/pasinkj
source=`pacmd list short sinks | sed -n "/Default source name/p"| sed "s/Default source name://"`
`echo $source >/tmp/pasourcej`
echo $source >"$pajack_dir"/pasourcej
# load the pulseaudio jack module and set them as default ports
pacmd load-module module-jack-sink channels=2
pacmd load-module module-jack-source channels=2
Expand All @@ -130,15 +137,15 @@ function start() {
function stop() {
# if command-line option stop is given
# again, check if pasuspender waiting for jack, if not, unload the pulse
# jack module and reload the module-suspend-on-idle.
# jack module and reload the module-suspend-on-idle.
if [[ ! "$p" =~ "jackd" ]]; then
#echo "pasuspender is NOT active"
pacmd unload-module module-jack-sink
pacmd unload-module module-jack-source
pacmd load-module module-suspend-on-idle
else
# if pasuspender waiting for jack, add a timeout to pasuspender
# to allow a smooth reset action afterward.
# to allow a smooth reset action afterward.
#echo "pasuspender is active"
pasuspender -- sleep 5 &
fi
Expand All @@ -151,12 +158,12 @@ function reset() {
#echo "pasuspender is active"
exit 0
else
# fetch the previous saved pulse audio ports and set them back
# fetch the previous saved pulse audio ports and set them back
# as default ports for pulseaudio. Done.
sink=`cat /tmp/pasinkj`
source=`cat /tmp/pasourcej`
pacmd set-default-sink $sink
pacmd set-default-source $source
sink=`cat "$pajack_dir"/pasinkj`
source=`cat "$pajack_dir"/pasourcej`
pacmd set-default-sink $sink
pacmd set-default-source $source
#echo "pasuspender is NOT active"
fi
}
Expand Down

0 comments on commit a163b5f

Please sign in to comment.