Hi :)
some users on that list seems to be fine with writing shell scripts. I'm
still not fine with it and endeavour to avoid non-POSIX style while
learning how to write those scripts.
Today "Obsession - Open Busy Session Handler version 0.5" come into
being, it's my second shell script :).
It already is able to detect running audio applications, to store this
information to a file and restore those audio applications. Restore does
mean that it will launch the applications by reading the info from the
file. Restoring JACK audio client connections will be the next step.
Hints how to use "grep" are welcome, e.g. if a PID has got 5 instead of
4 numbers, the script will display absurd messages.
I'm a little bit confused about the separation between user and root on
the Ubuntu based 64 Studio. Does anybody know how I can launch an
application as user by my shell script, even if the script was started
as root?
This is needed, because when running the script by "sudo sh
obsession0.5" a jack_snapshot installer will appear and I would like to
have an option to browse to the homepage of jack_snapshot, but by doing
this as user and not as root.
When running the script by "sh obsession0.5" the session handler will
appear, running "sh obsession0.5 help" will display a help page.
Does anybody know how to get the information about ALSA and or JACK MIDI
connections?
Cheers,
Ralf
PS: If anybody like to test the script, copy "obsession.conf" to
"/home/your_user_dir/.config" and the test files to
"/home/your_user_dir" or just let Obsession generate your own test
files. Anyway, the script at any rate needs the configuration file, but
not the user (test) files.
PPS: I had and still have got trouble with my monitor, if there should
be any emails addressed to me since Oct 7, I'll try to read and reply
them this week.
#!/bin/sh
#######################################
# Obsession - Open Busy Session Handler
# 2009 Ralf Mardorf
#######################################
obs_version="0.5"
#######
# Start
#######
obs_tmp="obsession."$$
obs_quit_msg_flag=1
clear
echo "Obsession - Open Busy Session Handler version "$obs_version
echo "2009 Ralf Mardorf"
echo
echo
echo "Hallo "$USER" :)!"
echo
if [ "$1" != "" ]
then
if [ "$1" = "help" ]
then
#############
# Help option
#############
obs_quit_msg_flag=0
echo "Obsession is a Bourne Shell script, written to learn how to write
shell"
echo "scripts. It's a simple but easy to use audio and MIDI session
handler,"
echo "that detects audio and MIDI applications you launched for your actual"
echo "session. Next time you'll continue your session Obsession can launch"
echo "those applications for you and restore JACK audio client connections."
echo
echo "To restore JACK audio client connections the script needs
jack_snapshot."
echo
echo "If you run Obsession as root it will download, extract, compile and"
echo "install jack_snapshot for you, run"
echo
echo "sudo sh "$0
echo
echo "After doing this Obsession will ask you to execute or cancel the"
echo "installation, but it only is able to compile jack_snapshot when all"
echo "dependencies are fine. The libjack development files, gcc < version
4.3,"
echo "make and perhaps some other dependencies are needed."
echo
echo "When running Obsession as user, it can handle audio and MIDI sessions"
echo "for you, run"
echo
echo "sh "$0
echo
echo "There are no options for the script, but help."
echo
echo "sh "$0" help"
echo
echo "or"
echo
echo "sudo sh "$0" help"
else
################
# Invalid option
################
obs_quit_msg_flag=0
echo "Please run"
echo
echo "sh "$0" help"
fi
else
if [ $USER = "root" ]
then
#######################################
# jack_snapshot version 0.0.3 installer
#######################################
echo "jack_snapshot is copyright by Florian Schmidt and covered by the GPL
2"
echo
echo "For further information visit"
echo "http://tapas.affenbande.org/wordpress/?page_id=14"
echo
echo "After Obsession has installed jack_snapshot there's a license file"
echo "/tmp/"$obs_tmp"/license_jack_snapshot-0.0.3"
echo
echo
echo "What can I do for you?"
echo
echo "Type inst and enter to install jack_snapshot."
echo "Type rm and enter to remove jack_snapshot."
#echo "Type www and enter to browse tapas.affenbande.org, notice that"
#echo " you only can browse if Firefox is installed, but not
running."
echo "Type anything elese and enter or just push enter to quit obsession."
echo
echo "Command:" ; read obs_answer0
case $obs_answer0 in
inst*)
########################
# Command: inst/ install
########################
obs_quit_msg_flag=0
clear ; echo "Command:" ; echo $obs_answer0 ; echo
echo $0": Checking if jack_snapshot already is installed."
echo
echo
echo "# jack_snapshot"
jack_snapshot ; obs_rtncode0=$?
echo
echo
echo $0": jack_snapshot: return code:" $obs_rtncode0
if [ $obs_rtncode0 != 1 ]
then
#######################
# Install jack_snapshot
#######################
echo
echo "# mkdir /tmp/"$obs_tmp
mkdir /tmp/$obs_tmp
echo "# cd /tmp/"$obs_tmp
cd /tmp/$obs_tmp
echo "# wget
http://tapas.affenbande.org/jack_snapshot/jack_snapshot-0.0.3.tgz"
wget http://tapas.affenbande.org/jack_snapshot/jack_snapshot-0.0.3.tgz
echo "# tar xfz jack_snapshot-0.0.3.tgz"
tar xfz jack_snapshot-0.0.3.tgz
echo "# rm jack_snapshot-0.0.3.tgz"
rm jack_snapshot-0.0.3.tgz
echo "# cd jack_snapshot-0.0.3"
cd jack_snapshot-0.0.3
echo "# make"
make
echo "# cp -p /tmp/"$obs_tmp"/jack_snapshot-0.0.3/LICENSE
/tmp/"$obs_tmp"/license_jack_snapshot-0.0.3"
cp -p /tmp/"$obs_tmp"/jack_snapshot-0.0.3/LICENSE
/tmp/"$obs_tmp"/license_jack_snapshot-0.0.3
echo "# cp /tmp/"$obs_tmp"/jack_snapshot-0.0.3/jack_snapshot /usr/bin"
cp /tmp/"$obs_tmp"/jack_snapshot-0.0.3/jack_snapshot /usr/bin
echo "# cd .."
cd ..
echo "# rm -r jack_snapshot-0.0.3"
rm -r jack_snapshot-0.0.3
echo
echo "See /tmp/"$obs_tmp"/license_jack_snapshot-0.0.3 for the license."
else
#############################
# Don't install jack_snapshot
#############################
echo $0": A version of jack_snapshot already is installed."
fi
;;
rm*)
#####################
# Command: rm/ remove
#####################
obs_quit_msg_flag=0
clear ; echo "Command:" ; echo $obs_answer0 ; echo ; echo
echo "Obsession only tries to remove a version of jack_snapshort in
/usr/bin."
echo "Doing this jack_snapshot installed by Obsession will be completely
removed."
echo "Any other jack_snapshot in /usr/bin also will be removed, but
nothing"
echo "more will be done."
echo
echo "# rm /usr/bin/jack_snapshot"
rm /usr/bin/jack_snapshot
if [ $? = 0 ] ; then echo $0": rm: removed /usr/bin/jack_snapshot" ; fi
;;
# www*)
######################
# Command: www/ browse
######################
#clear ; echo "Command:" ; echo $obs_answer0 ; echo ; echo
#obs_answer0="root"
#while [ $obs_answer0 = "root" ]
#do
# echo "Type your username, root isn't allowed:" ; read obs_answer0
#done
#sudo -u $obs_answer0
#sudo -u 1000
#echo
#echo "Close Firefox to exit Obsession."
#firefox http://tapas.affenbande.org/wordpress/?page_id=14
#;;
esac
else
######################################################################
# Session handler
######################################################################
obs_quit_msg_flag=1
echo
echo "Type store and enter to detect and store running applications."
echo "Type restore and enter to load and restore running applications."
echo "Type anything else and enter or just push enter to quit obsession."
echo
echo "Command:" ; read obs_answer0 ; echo
. ~/.config/obsession.conf # Get all
variables from obsession.conf
obs_apps_and_jack="applications and no jack audio connections by this
version of Obsession"
# Dummy text,
should depend to obs_jack_snapshot
obs_rst_app=1 # Initialize
obs_rst_app
case $obs_answer0 in
store*)
##################
# Command: store
##################
obs_user_file_inf="obs_user_file_inf=\"Obsession $obs_version user file\""
# Generating user file info
obs_conf_file_inf=`ls -l ~/.config | grep obsession.conf$` #
Get config file info
#
Still buggy, because it e.g. would prefer
#
an item named "aobsession.conf"
i=${#obs_conf_file_inf} ; i=`expr $i - 30` #
Check string length of ls | grep output
obs_conf_file_inf="obs_conf_file_inf=\"`expr substr "$obs_conf_file_inf"
$i 31`\"" # Generating config file info
obs_actual_app=$obs_first_app #
Initialize obs_actual_app
echo "$0: Detecting $obs_apps_and_jack to store info to:"
echo $obs_user_dir
echo
echo "obs_jack_snapshot of the configuration file is set to
$obs_jack_snapshot."
echo "This version of Obsession still ignores jack_snapshot for storage
and restore."
echo "The obs_run arguments in obsession.conf also will be ignored."
echo
echo "Type a filename without path and extension and enter:"
read obs_answer0 ; obs_answer0="$obs_user_dir/$obs_answer0"
obs_filename=""
jsnap_filename=""
obs_filename="$obs_answer0.obs"
jsnap_filename="$obs_answer0.jsnap" ; echo
echo "/paths/filenames will be: $obs_filename and $jsnap_filename" ;
echo
#####################
# Output to user file
#####################
echo $obs_user_file_inf ; echo $obs_user_file_inf > $obs_filename
echo $obs_conf_file_inf ; echo $obs_conf_file_inf >> $obs_filename
echo
echo "obs_delay=$obs_delay" ; echo "obs_delay=$obs_delay" >> $obs_filename
echo
while [ $obs_actual_app -le $obs_last_app ] ## Loop to get all
apps from obsession.conf
do #|
#eval echo \${obs_app${obs_actual_app}} \${obs_run${obs_actual_app}}
eval obs_space_detection=\${obs_app${obs_actual_app}} #| Copy actual
obs_app to obs_space_detection
obs_pid_detection="" #| Clear
obs_pid_detection
i=1 #| Initialize
counter
obs_str=`expr substr "$obs_space_detection" $i 1` #| String becomes
first single char
until [ -z $obs_str ] #|# Do loop until
char is ""
do #||
obs_pid_detection=$obs_pid_detection$obs_str #||Add char by char
to obs_pid_detection
i=`expr $i + 1` #||Increment counter
obs_str=`expr substr "$obs_space_detection" $i 1` #||String becomes
next single char
done #|# When
obs_pid_detection is complete, then ...
obs_pid_actual_app=`pidof $obs_pid_detection` #| ... check if app
is running
if [ $? = 0 ] ; then #| If return code
is fine ...
eval obs_str="\${obs_app${obs_actual_app}}" #|
echo "You run $obs_pid_detection like this:" #|
redirect_output=`ps x | grep ^.$obs_pid_actual_app` #|
if [ $? != 0 ]
then
echo $obs_pid_detection has got more than one PID.
echo The PIDs are: $obs_pid_actual_app
echo "Obsession would restore one $obs_pid_detection like this:"
else
echo $redirect_output
echo "Obsession would restore $obs_pid_detection like this:"
fi
echo "obs_rst${obs_rst_app}="\"$obs_str\" #| Display:
variable="command to be restored" ...
echo "obs_rst${obs_rst_app}="\"$obs_str\" >> $obs_filename #
... and save to /path/filename
#........1.........2.........3.........4.........5.........6..output should
have a limit of 72 chars a line
echo "obs_inf give you info about the number the app has got in
obsession.conf"
eval echo "obs_inf${obs_rst_app}=$obs_actual_app" #| Display original
number of command in obsession.conf ...
eval echo "obs_inf${obs_rst_app}=$obs_actual_app" >> $obs_filename #
... and save to /path/filename
echo #|
obs_rst_app=`expr $obs_rst_app + 1` #| Increment
counter for next command to be saved for restore
fi #| If 'then' is
done or if then is ignored ...
obs_actual_app=`expr $obs_actual_app + 1` #| ... increment
counter for next app from obsession.conf
done ##
obs_rst_app=`expr $obs_rst_app - 1`
echo "obs_number_of_apps_to_be_restored=$obs_rst_app"
echo "obs_number_of_apps_to_be_restored=$obs_rst_app" >> $obs_filename
echo "obs_jack_snapshot=$obs_jack_snapshot"
echo "obs_jack_snapshot=$obs_jack_snapshot" >> $obs_filename
echo
echo "/paths/filenames are: $obs_filename and $jsnap_filename"
obs_quit_msg_flag=0
;;
restore*)
##################
# Command: restore
##################
echo "$0: Loading from $obs_user_dir and restoring $obs_apps_and_jack."
echo
ls $obs_user_dir -l | grep obs$
echo
echo "Type a filename without path and extension and enter:"
read obs_answer0 ; obs_answer0="$obs_user_dir/$obs_answer0"
obs_filename="$obs_answer0.obs"
jsnap_filename="$obs_answer0.jsnap"
. $obs_filename
echo
echo "$obs_filename is a $obs_user_file_inf generated by using
$obs_conf_file_inf."
echo "Apps will be launched with a delay of $obs_delay seconds between
each app."
echo "obs_jack_snapshot of the userfile is set to $obs_jack_snapshot."
echo "This version of Obsession still ignores jack_snapshot for storage
and restore."
echo "The obs_run arguments in obsession.conf also will be ignored."
# Restore
obs_rst_app=1
while [ $obs_rst_app -le $obs_number_of_apps_to_be_restored ]
do
echo "Launching app number $obs_rst_app of
$obs_number_of_apps_to_be_restored apps to be restored."
eval run="\${obs_rst${obs_rst_app}}"
`$run` &
sleep $obs_delay
obs_rst_app=`expr $obs_rst_app + 1`
done
#
obs_quit_msg_flag=0
;;
esac
fi
fi
if [ $obs_quit_msg_flag = 1 ] ; then echo "quit "$0 ; fi
echo
exit 0
######################################################################################################################
#
# Obsession configuration file ~/.config/obsession.conf
#
# obs_user_dir=<user's directory for store and restore settings>
# directory where Obsession stores "filename.obs" for Obsession
and "filename.jsnap" for jack_snapshot
#
# obs_first_app=<number of first application to handle> any previous apps will
be ignored
#
# obs_delay=<pause for x.y seconds between launching apps>
#
# obs_app<number>=<"command for launching application in quotes">
# obs_run<number>=<argument>
# arguments are:
# yes | at restore always
# launch app even if it isn't running while
Obsession detects running apps for restore
# no | at restore never
# launch app even if it is running while
Obsession detects running apps for restore
# auto | at restore only
# launch app when it is running while
Obsession detects running apps for restore
# ignore | never check if app is or isn't running while
Obsession detects running apps for restore
# this will skip apps in this list
#
# obs_last_app=<number of last application to handle> any following apps will
be ignored
#
# obs_jack_snapshot=<argument>
# arguments are:
# yes | Obsession should store or restore
JACK audio connections
# no | Obsession shouldn't store or restore
JACK audio connections
# noclear | Obsession should store or restore connections
but not clear existing once at restore
# noreset | Obsession should store but shouldn't restore
JACK audio connections
#
# NOT SUPPORTED YET:
#
# Example: obs_app8="jack-rack -s OBS_AUTO-NUMBER"
#
# Obsession does detect running applications, but not the arguments. For
jack-rack e.g. use "jack-rack -n" to enable
# the usage of jack_snapshot and add all arguments also to the list.
# Even apps that will give constant "auto-numbers" them self for JACK audio,
MIDI and ALSA MIDI clients only will be
# launched one time when a session is restored by Obsession. If you need one
app several times, you need to do it
# manually.
#
# Obsession can't detect and restore JACK MIDI and ALSA MIDI connections, but
e.g. Qtractor is able to restore
# ALSA MIDI connections.
#
# NOTE:
#
# Feel free to handle non-audio sessions by Obsession too.
# Feel free to write an independent app that can store and restore MIDI
connections :).
# Of course Obsession only will detect apps listed in this file, anyway you can
add apps to your .obs files too.
#
# Hints how to write shell scripts are welcome, Obsession is my second
inexperienced written shell script.
#
# You can add or delete apps from the list, change the sequence, because they
will be launched by the order of the
# given number. Keep jackd on top of the apps. Keep the numbers for obs_app and
obs_run numerically sorted without
# gaps.
#
######################################################################################################################
obs_user_dir=$HOME
obs_first_app=1
obs_delay=0.0
obs_app1="jackd -Rdalsa -dhw:0 -r96000 -p512 -n2"
obs_run1=auto
obs_app2="qjackctl"
obs_run2=auto
obs_app3="aeolus"
obs_run3=auto
obs_app4="ardour"
obs_run4=auto
obs_app5="audacity"
obs_run5=auto
obs_app6="envy24control"
obs_run6=auto
obs_app7="hydrogen"
obs_run7=auto
obs_app8="jackeq"
obs_run8=auto
obs_app9="jack-rack -n"
obs_run9=auto
obs_app10="jamin"
obs_run10=auto
obs_app11="jkmeter -C"
obs_run11=auto
obs_app12="phasex"
obs_run12=auto
obs_app13="qsampler"
obs_run13=auto
obs_app14="qsynth"
obs_run14=auto
obs_app15="qtractor"
obs_run15=auto
obs_app16="rosegarden"
obs_run16=auto
obs_app17="swami"
obs_run17=auto
obs_app18="vkeybd"
obs_run18=auto
obs_app19="zynaddsubfx"
obs_run19=auto
obs_app20="firefox http://www.64studio.com/"
obs_run20=yes
obs_last_app=20
obs_jack_snapshot=yes
obs_user_file_inf="Obsession 0.5 user file"
obs_conf_file_inf="2009-10-12 14:12 obsession.conf"
obs_delay=3.5
obs_rst1="jackd -Rdalsa -dhw:0 -r96000 -p512 -n2"
obs_inf1=1
obs_rst2="qjackctl"
obs_inf2=2
obs_rst3="jack-rack -n"
obs_inf3=9
obs_rst4="firefox http://www.64studio.com/"
obs_inf4=20
obs_number_of_apps_to_be_restored=4
obs_jack_snapshot=yes
obs_user_file_inf="Obsession 0.5 user file"
obs_conf_file_inf="2009-10-12 14:12 obsession.conf"
obs_delay=0.0
obs_rst1="jackd -Rdalsa -dhw:0 -r96000 -p512 -n2"
obs_inf1=1
obs_rst2="qjackctl"
obs_inf2=2
obs_rst3="qsampler"
obs_inf3=13
obs_rst4="qsynth"
obs_inf4=14
obs_rst5="firefox http://www.64studio.com/"
obs_inf5=20
obs_number_of_apps_to_be_restored=5
obs_jack_snapshot=yes
_______________________________________________
64studio-users mailing list
[email protected]
http://lists.64studio.com/mailman/listinfo/64studio-users