Post by VolkerFroehlich on Feb 11, 2023 23:17:20 GMT 1
Dears,
Enjoy this automated installation and launch script for JJazzLab.
Enjoy this automated installation and launch script for JJazzLab.
It shall automatically create a basic JJazzLab installation without much headaches.
You can just copy the text/code below into a file - e.g.
jjazzlab.sh
and then make this file executable using the command
chmod a+x jjazzlab.sh
For a first run use
jjazzlab.sh -help
This will just display some information on what the script does
To install and/or run JJazzLab and all required components (such as qsynth and soundfonts) automatically use
jjazzlab.sh -action
The script has been tested on
Ubuntu 20.04.5 LTS with gnome desktop
Ubuntu 22.04.1 LTS with gnome desktop
Linux Mint 21.1 (vera) with Cinnamon desktop
Ubuntu 20.04.5 LTS with gnome desktop
Ubuntu 22.04.1 LTS with gnome desktop
Linux Mint 21.1 (vera) with Cinnamon desktop
Other Linux distros/desktops will require adaptions to e.g. use different terminal commands.
I am looking forward to any comments and/or suggestions for improvements.
Code will be maintained here: gitlab.com/-/snippets/2498521
Volker Fröhlich
#!/bin/bash
########
#
# purpose: automatically download, install and run on Linux
# the newest program version
#
# usage: run this script in a terminal with no parameters to get a help description
#
# author: Vokler Fröhlich
# created: 11-Feb-2023
LASTUPDATE="14-Feb-2023"
# tested: Ubuntu 20.04.5 LTS, Ubuntu 22.04.1 LTS, Mint 21.1 Cinnamon
#
# description:
# This script will automatically
# - download and install the newest JJazzLab program version
# - download a program icon
# - create a JJazzLab desktop launcher
# - download and install the JJazzLab-SoundFont
# - install, configure and run QSynth
# - detect and connect ports of virmidi to fluid
# - run the JJazzLab program
#
# sources:
# A) jjazzlab Linux installation instructions
# (jjazzlab.gitbook.io/user-guide/installation)
# - Unzip the package
# - Start JJazzLab using bin/jjazzlab in the installation directory.
# B) FluidSynth (Linux) set-up instructons
# (jjazzlab.gitbook.io/user-guide/configuration/jjazzlab-soundfont/fluidsynth)
# 1 Install JJazzLab-SoundFont
# (https://musical-artifacts.com/artifacts/1036)
# - download JJazzLab SoundFont.sf2
# - copy to /usr/share/sounds/sf2/
# 2 Install a virtual midi port
# - add Virtual Raw MIDI to Linux Kernel
# sudo modprobe snd-virmidi midi_devs=1
# - adding permanently to Linux Kernel
# - list ALSA connect outputs
# aconnect -lo
# 3 Install FluidSynth and its gui QSynth
# sudo apt-get install fluidsynth
# sudo apt-get install qsynth
# 4 Start QSynth
# QSynth &
# 5 Configure QSynth
# ($HOME/.config/rncbc.org/Qsynth.conf)
# QSynth->Menu:Set-up
# ->Soundfonts: Load the JJazzLab SoundFont
# ->Settings:MIDI
# Midi-Driver: alsa_seq, MIDI Bank Select mode: xg,
# ->Settings:Audio
# Audio Driver: ALSA, Buffer Size: 512
# 6 Connect the "Virtual Raw MIDI" port to FluidSynth
# - get the port numbers
# PORT_VIRMIDI=`aconnect -lo|grep "Virtual Raw MIDI"|awk '{print $2}'|head -1|cut -d':' -f 1`
# PORT_FLUID=`aconnect -lo|grep "FLUID"|awk '{print $2}'|head -1|cut -d':' -f 1`
# aconnect ${PORT_VIRMIDI}:0 ${PORT_FLUID}:0
# 7 Configure JJazzLab
# ->Options->MIDI: select the first virMIDI out device
# ->Options->output synth: Presets->JJazzLab SoundFont->With FluidSynth (Linux)
#
# TODO: testing with different Linux versions
#
# 230214: continued bugfixing/hardening, Ubuntu 22.04.1 LTS, Mint 21.1 Cinnamon
# 230213: adapted icon file extension, get_version_local()
# 230212: adapted _sudo_in_terminal(), jjazzlab_desktop_check_create()
# 230211: initial script creation
#
########
# global script parameters
G_DIR_INSTALL_JJAZZLAB=$HOME # a downloaded package zip is extracted/installed here
G_WWW_JJAZZLAB_ICON="https://yt3.googleusercontent.com/ytc/AL5GRJUBXOy0NUrUy7Qk3FXsap_60XvA-GLH65OErqxC=s88-c-k-c0x00ffffff-no-rj" # we use this app icon from the web
G_WWW_JJAZZLAB_DOWNLOAD="https://www.jjazzlab.com/en/download" # the jjazzlab download page contains the most recent package zip
G_WWW_JJAZZLAB_SF2="https://archive.org/download/jjazz-lab-sound-font/JJazzLab-SoundFont.sf2" # the sound font download file
G_WWW_SF2_ARTEFACTS="https://musical-artifacts.com/artifacts/1036" # were a package can be manually downloaded
TERMINAL_CMD=gnome-terminal # we need to open a terminal for sudo commands
# ======================================================================
_usage()
# ----------------------------------------------------------------------
# show script help text
# ======================================================================
{
progname=$(basename "$0")
echo -e "Usage: ${CLR_BLU}${progname}${CLR_NON} [${CLR_GRE}option${CLR_NON}]"
echo -e " ${CLR_GRE}-a${CLR_NON} | ${CLR_GRE}action${CLR_NON}: run program, if needed download/install"
echo -e " ${CLR_GRE}-d${CLR_NON} | ${CLR_GRE}desktop${CLR_NON}: create a desktop icon"
echo -e " ${CLR_GRE}-h${CLR_NON} | ${CLR_GRE}help${CLR_NON}: show usage instructions"
echo -e " ${CLR_GRE}-l${CLR_NON} | ${CLR_GRE}install${CLR_NON}: download/install latest package zip"
echo -e " ${CLR_GRE}-q${CLR_NON} | ${CLR_GRE}qsynth${CLR_NON}: configure qsynth"
echo -e " ${CLR_GRE}-r${CLR_NON} | ${CLR_GRE}version${CLR_NON}: check program version"
echo -e " ${CLR_GRE}-u${CLR_NON} | ${CLR_GRE}uninstall${CLR_NON}: remove an existing installation"
echo -e " ${CLR_GRE}-v${CLR_NON} | ${CLR_GRE}verbose${CLR_NON} [${CLR_GRE}n${CLR_NON}] = show details, level n=0-2"
echo -e " ${CLR_GRE}-y${CLR_NON} | ${CLR_GRE}yes${CLR_NON}: don't ask user for confirmation"
echo -e " (${CLR_BRO}script updated ${LASTUPDATE}${CLR_NON})"
}
# ======================================================================
_ask_yes_or_no()
# ----------------------------------------------------------------------
# INPUT PARAMETER
# $1: Text
# OUTPUT PARAMETER
# "yes" - if global var OPT_YES=1 return
# "yes" or "no" - user response
# ======================================================================
{
[ "$OPT_YES" = "1" ] &&\
echo "yes" && return
read -p "$1 ([y]es or [N]o): "
case $(echo $REPLY | tr '[A-Z]' '[a-z]') in
y|yes) echo "yes" ;;
*) echo "no" ;;
esac
}
# ======================================================================
_get_verbose_level()
# ----------------------------------------------------------------------
# INPUT PARAMETER
# 0 - no messages
# 1 - basic info
# 2 - debug info
# output:
# OPT_VERBOSE=<input>
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} _get_verbose_level()"
case "$1" in
"0" | "1" | "2")
OPT_VERBOSE=$1
;;
*) echo -e "${CLR_RED}ERROR:${CLR_NON} wrong verbose level $1"
usage
exit -1
;;
esac
return 0
}
# ======================================================================
#_is_internet_connected()
# ----------------------------------------------------------------------
# INPUT PARAMETER - none
# return
# 0 if internet connected
# -1 else
# ======================================================================
#{
#wget -q --spider http://google.com
#[ ${?} -eq 0 ] && return 0
#[ "$OPT_VERBOSE" -gt 0 ] &&\
# echo -e ":${CLR_BRO}WARNING:${CLR_NON}"\
# "no internet connection available!"
#return -1
#}
# ======================================================================
_sudo_in_terminal()
# ----------------------------------------------------------------------
# as we cannot sudo without a terminal, we have to open one
# ======================================================================
{
MSG="sudo $@ - v=${OPT_VERBOSE}"
# if running in a terminal
if [ "$SHLVL" -gt 1 ];then
[ "$OPT_VERBOSE" -gt 0 ] && \
echo "${MSG}"
# execute the sudo command
sudo $@
# else
else
[ "$OPT_VERBOSE" -gt 0 ] && [ ! -z "`which xmessage`" ] &&\
xmessage -buttons Ok:0 \
-default Ok -nearmouse "${MSG}" -timeout 10:
# open a new terminal to execute the sudo command
${TERMINAL_CMD} --terminal-title "${MSG}" -- sudo $@
fi
}
# ======================================================================
_bash_define_colors()
# ----------------------------------------------------------------------
# color definitions used with echo bash command
# example:
# echo -e "${CLR_RED}ERROR:${CLR_NON} file not found"
# ======================================================================
{
CLR_NON='\x1b[0m'
CLR_BLA='\x1B[1;30m'
CLR_RED='\x1B[1;31m'
CLR_GRE='\x1B[1;32m'
CLR_BRO='\x1B[1;33m'
CLR_BLU='\x1B[1;34m'
CLR_CYA='\x1B[1;36m'
CLR_WHI='\x1B[1;37m'
return 0
}
# ======================================================================
kernel_add_permanent_virtualmidi()
# ----------------------------------------------------------------------
# function is still experimental and does not work as expected yet.
# add module snd-virmidi permanently to Linux Kernel by
# creating /etc/modprobe.d/snd-virmidi.conf and
# updating /etc/modules
# jjazzlab.gitbook.io/user-guide/configuration/jjazzlab-soundfont/fluidsynth
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} kernel_add_permanent_virtualmidi()"
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BRO}WARNING:${CLR_NON} this is experimental function."\
"it is a basis to work from, but does not work as expected yet."
EXIST_VIRMIDI=`lsmod | grep virmidi`
[ ! -z "${EXIST_VIRMIDI}" ] && return 0
# create /etc/modprobe.d/snd-virmidi.conf
DIR_TARGET="/etc/modprobe.d"
FIL_TARGET="snd-virmidi.conf"
if [ ! -f "${DIR_TARGET}/${FIL_TARGET}" ];then
echo "options snd-virmidi midi_devs=1" > /tmp/${FIL_TARGET}
_sudo_in_terminal mv /tmp/${FIL_TARGET} ${DIR_TARGET}/
_sudo_in_terminal chown root:root ${DIR_TARGET}/${FIL_TARGET}
fi
if [ ! -f "${DIR_TARGET}/${FIL_TARGET}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not created:"\
">${DIR_TARGET}/${FIL_TARGET}<"
return -1
fi
# update /etc/modules
DIR_TARGET="/etc"
FIL_TARGET="modules"
if [ ! -f "${DIR_TARGET}/${FIL_TARGET}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found"\
">${DIR_TARGET}/${FIL_TARGET}<"
return -1
fi
MODULE_EXIST=`cat "${DIR_TARGET}/${FIL_TARGET}" | grep snd-virmidi`
if [ -z "${MODULE_EXIST}" ];then
cp "${DIR_TARGET}/${FIL_TARGET}" /tmp/
echo "snd-virmidi" >> /tmp/${FIL_TARGET}
_sudo_in_terminal mv /tmp/${FIL_TARGET} "${DIR_TARGET}/${FIL_TARGET}"
_sudo_in_terminal chown root:root ${DIR_TARGET}/${FIL_TARGET}
fi
MODULE_EXIST=`cat "${DIR_TARGET}/${FIL_TARGET}" | grep snd-virmidi`
if [ -z "${MODULE_EXIST}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not updated:"\
">${DIR_TARGET}/${FIL_TARGET}<"
return -1
fi
return 0
}
# ======================================================================
kernel_add_virtualmidi()
# ----------------------------------------------------------------------
# add module snd-virmidi to current kernel session
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} kernel_add_virtualmidi()"
# list ALSA connect outputs
PORT_VIRMIDI=`aconnect -lo|grep "Virtual Raw MIDI"|\
awk '{print $2}'|head -1|cut -d':' -f 1`
if [ ! -z "${PORT_VIRMIDI}" ];then
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} virtmidi port found!"
return 0
fi
# add snd-virmidi to current kernel session
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} adding the virtual midi port -"\
"sudo modprobe snd-virmidi midi_devs=1"
_sudo_in_terminal modprobe snd-virmidi midi_devs=1
while
[ -z "`lsmod | grep -o snd_virmidi | head -1`" ]
do
sleep 1
done
PORT_VIRMIDI=`aconnect -lo|grep "Virtual Raw MIDI"|\
awk '{print $2}'|head -1|cut -d':' -f 1`
if [ -z "${PORT_VIRMIDI}" ];then
echo -e "${CLR_ERR}ERROR:${CLR_NON} no virtual midi port detected"
return -1
fi
echo -e "${CLR_BLU}INFO:${CLR_NON} virtmidi port added to current session!"
return 0
}
# ======================================================================
kernel_clean()
# ----------------------------------------------------------------------
# remove snd-virmidi from kernel
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} kernel_clean()"
EXIST_VIRMIDI=`lsmod | grep virmidi`
if [ ! -z "${EXIST_VIRMIDI}" ];then
echo "removing snd-virmidi"
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} sudo modprobe -r snd-virmidi"
sudo modprobe -r snd-virmidi
fi
MOD_CONF="/etc/modprobe.d/snd-virmidi.conf"
if [ -f "${MOD_CONF}" ];then
echo -e "${CLR_BLU}INFO:${CLR_NON} please manually remove config file"
echo -e "${CLR_GRE}${MOD_CONF}${CLR_NON}"
fi
MOD_FIL="/etc/modules"
MODULE_EXIST=`cat "${MOD_FIL}" | grep snd-virmidi`
if [ ! -z "${MODULE_EXIST}" ];then
echo -e "${CLR_BLU}INFO:${CLR_NON} please manually remove snd-virmidi from modules file"
echo -e "${CLR_GRE}${MOD_FIL}${CLR_NON}"
fi
return 0
}
# ======================================================================
jjazzlab_check_install()
# ----------------------------------------------------------------------
# search with various methods (which, find)
# if not found, download and install
# A) jjazzlab Linux installation instructions
# (jjazzlab.gitbook.io/user-guide/installation):
# - Unzip the package
# if still not found show ERROR message
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_check_install()"
EXEC_PATTERN_JL="jjazzlab"
# search with various methods (which, find)
jjazzlab_find_installed
# if not found, download and install
if [ -z "${EXEC_JJAZZLAB}" ];then
jjazzlab_download_install
fi
# if still not found show ERROR message
if [ -z "${EXEC_JJAZZLAB}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >${EXEC_PATTERN_JL}< "
echo "please add the ${EXEC_PATTERN_JL} executable path to your PATH"
echo 'e.g. export PATH=$PATH:/usr/local/JJazzLab/bin'
return -1
fi
[ "$OPT_VERBOSE" -gt 0 ] && \
echo -e "${CLR_BLU}INFO:${CLR_NON} found ${EXEC_PATTERN_JL}"\
"installation:\n ${EXEC_JJAZZLAB}"
jjazzlab_desktop_check_create
return 0
}
# ======================================================================
jjazzlab_close()
# ----------------------------------------------------------------------
# close jjazzlab
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_close()"
JJAZZLAB_STARTED="`pidof jjazzlab`"
if [ ! -z "$JJAZZLAB_STARTED" ]; then
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} kill jjazzlab (${JJAZZLAB_STARTED})"
kill ${JJAZZLAB_STARTED}
sleep 1
fi
JJAZZLAB_STARTED="`pidof jjazzlab`"
if [ ! -z "$JJAZZLAB_STARTED" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} failed to kill jjazzlab!"
return -1
fi
return 0
}
# ======================================================================
jjazzlab_find_installed()
# ----------------------------------------------------------------------
# search with various methods (which, find)
# return 0: if found
# -1: else
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_find_installed()"
EXEC_PATTERN_JL="jjazzlab"
# search with various methods (which, find)
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} checking which ${EXEC_PATTERN_JL}"
EXEC_JJAZZLAB="`which ${EXEC_PATTERN_JL} 2>/dev/null`"
#if [ -z "${EXEC_JJAZZLAB}" ];then
# SEARCH_DIR="."
# [ "$OPT_VERBOSE" -gt 1 ] &&\
# echo -e "${CLR_BLU}INFO:${CLR_NON} checking find ${SEARCH_DIR}"\
# "-name ${EXEC_PATTERN_JL} -type f"
# EXEC_JJAZZLAB="`find ${SEARCH_DIR} -name ${EXEC_PATTERN_JL} -type f 2>/dev/null`"
#fi
if [ -z "${EXEC_JJAZZLAB}" ];then
SEARCH_DIR="$HOME"
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} checking find ${SEARCH_DIR}"\
"-name ${EXEC_PATTERN_JL} -type f"
EXEC_JJAZZLAB="`find ${SEARCH_DIR} -name ${EXEC_PATTERN_JL} -type f 2>/dev/null`"
fi
if [ -z "${EXEC_JJAZZLAB}" ];then
SEARCH_DIR="/usr/local"
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} checking find ${SEARCH_DIR}"\
"-name ${EXEC_PATTERN_JL} -type f"
EXEC_JJAZZLAB="`find ${SEARCH_DIR} -name ${EXEC_PATTERN_JL} -type f 2>/dev/null`"
fi
if [ -z "${EXEC_JJAZZLAB}" ];then
SEARCH_DIR="/opt"
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} checking find ${SEARCH_DIR}"\
"-name ${EXEC_PATTERN_JL} -type f"
EXEC_JJAZZLAB="`find ${SEARCH_DIR} -name ${EXEC_PATTERN_JL} -type f 2>/dev/null`"
fi
[ -z "${EXEC_JJAZZLAB}" ] && return -1
return 0
}
# ======================================================================
jjazzlab_remove_installation()
# ----------------------------------------------------------------------
# remove installation
# ======================================================================
{
jjazzlab_close
jjazzlab_find_installed
if [[ ! -z "${EXEC_JJAZZLAB}" && -f "${EXEC_JJAZZLAB}" ]];then
JJAZZLAB_ROOT_DIR=`dirname $(dirname ${EXEC_JJAZZLAB})`
if [ "yes" == $(_ask_yes_or_no "remove ${JJAZZLAB_ROOT_DIR}?") ];then
rm -r ${JJAZZLAB_ROOT_DIR}
fi
fi
return 0
}
# ======================================================================
get_jjazzlab_icon()
# ----------------------------------------------------------------------
# download/install jjazzlab icon
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_desktop_check_create()"
DESKTOP_DIR=`xdg-user-dir DESKTOP`
if [ -z "$VERSION_INSTALLED" ];then
get_version_local
fi
if [ -z "$VERSION_INSTALLED" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} jjazzlab is not installed" && \
return -1
fi
# download icon and copy to the JJazzLab home directory
HOME_JJAZZLAB=`dirname $(dirname $EXEC_JJAZZLAB)`
ICON_LOCAL_FILE=${HOME_JJAZZLAB}/jjazzlab.jpg
if [ -f "$ICON_LOCAL_FILE" ];then
file_size_kb=`du -k "$ICON_LOCAL_FILE" | cut -f1`
if [ "$file_size_kb" -gt 1 ]; then
return 0 # jjazzlab icon already installed
else
echo -e ":${CLR_BRO}WARNING:${CLR_NON} file is much too small for an icon ($ICON_LOCAL_FILE)!"
fi
fi
if [ -d ${HOME_JJAZZLAB} ];then
PATH_ICON_TMP=/tmp/jjazzlab.jpg
rm ${PATH_ICON_TMP} 2>/dev/null
wget -O ${PATH_ICON_TMP} ${G_WWW_JJAZZLAB_ICON}
if [ "${?}" != "0" ];then
echo -e ":${CLR_RED}ERROR:${CLR_NON} download failed with error (${?})!"
return -1
fi
file_size_kb=`du -k "${PATH_ICON_TMP}" | cut -f1`
if [ "$file_size_kb" -lt 2 ]; then
echo -e ":${CLR_BRO}WARNING:${CLR_NON} file is much too small for an icon (${PATH_ICON_TMP})!"
return -1
else
if [ -w ${HOME_JJAZZLAB} ];then
cp ${PATH_ICON_TMP} ${ICON_LOCAL_FILE}
else
_sudo_in_terminal cp ${PATH_ICON_TMP} ${ICON_LOCAL_FILE}
fi
fi
fi
if [ ! -f "${ICON_LOCAL_FILE}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} could not install icon (${ICON_LOCAL_FILE})"
return -1
fi
return 0
}
# ======================================================================
jjazzlab_desktop_check_create()
# ----------------------------------------------------------------------
# create jjazzlab-v<Version>.desktop launcher file.
# The desktop launcher will run this current script (i.e. pathname ${0})
# in its current directory (i.e. dirname ${0}).
# I.e. in case you move this script to anonter directory,
# you need to re-create the desktop launcher by deleting it and
# starting this script in a terminal with parameters -a or -d
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_desktop_check_create()"
DESKTOP_DIR=`xdg-user-dir DESKTOP`
if [ -z "$VERSION_INSTALLED" ];then
get_version_local
fi
if [ -z "$VERSION_INSTALLED" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} jjazzlab is not installed"
return -1
fi
DESKTOP_PATH="$DESKTOP_DIR/jjazzlab-v${VERSION_INSTALLED}.desktop"
LOCAL_APP_PATH="$HOME/.local/share/applications/jjazzlab-v${VERSION_INSTALLED}.desktop"
if [[ -f "${DESKTOP_PATH}" && -f "${LOCAL_APP_PATH}" ]];then
if [ "$OPT_VERBOSE" -gt 0 ];then
echo -e "${CLR_BLU}INFO:${CLR_NON} found jjazzlab desktop:\n"\
"=> ${DESKTOP_PATH}"\
"=> ${LOCAL_APP_PATH}"
fi
return 0 # already installed
fi
HOME_JJAZZLAB=`dirname $(dirname $EXEC_JJAZZLAB)`
ICON_LOCAL_FILE=${HOME_JJAZZLAB}/jjazzlab.jpg
PATH_INSTALL_SCRIPT="`dirname ${0}`/`basename ${0}`"
# download/install the jjazzlab icon
get_jjazzlab_icon
# ##################
# create desktopfile
cat <<EOF_JJ > $DESKTOP_PATH
[Desktop Entry]
Version=1.0
Name=JJazzLab-v${VERSION_INSTALLED}
Comment=Create dynamic backing tracks
Comment[de]=Erzeuge dynamische Begleitung
Keywords=music;composition;composing;arranging;making;software;;MIDI;playback;instrument;
Keywords[de]=Musik;Komposition;Komponieren;Arrangieren;;MIDI;Instrument;
StartupNotify=true
Categories=Audio;Midi;Music;AudioVideo;
Type=Application
MimeType=
Exec=${PATH_INSTALL_SCRIPT} -a
Path=${HOME_JJAZZLAB}
Icon=${ICON_LOCAL_FILE}
Terminal=false
EOF_JJ
[ ! -f "${DESKTOP_PATH}" ] && \
echo -e "${CLR_RED}ERROR:${CLR_NON} desktop file not created (${DESKTOP_PATH})" && \
return -1
chmod a+x ${DESKTOP_PATH}
# echo cp ${DESKTOP_PATH} ${LOCAL_APP_PATH}
cp ${DESKTOP_PATH} ${LOCAL_APP_PATH} 2>/dev/null
return 0
}
# ======================================================================
jjazzlab_desktop_remove()
# ----------------------------------------------------------------------
# remove jjazzlab-v<Version>.desktop file
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_desktop_remove()"
DESKTOP_DIR=`xdg-user-dir DESKTOP`
DESKTOP_PATH=`find ${DESKTOP_DIR} -name "jjazzlab*.desktop"|head -1`
if [ -f "${DESKTOP_PATH}" ];then
rm ${DESKTOP_PATH}
fi
}
# ======================================================================
jjazzlab_download_install()
# ----------------------------------------------------------------------
# A) jjazzlab Linux installation instructons
# (jjazzlab.gitbook.io/user-guide/installation)
# - download most recent package
# - Unzip the package
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_download_install()"
# download the jjazzlab download page
DIR_TMP_DOWNLOAD=/tmp
PATH_TMP_DOWNLOAD=${DIR_TMP_DOWNLOAD}/jazzlabpage.html
rm ${PATH_TMP_DOWNLOAD} 2>/dev/null
wget -O ${PATH_TMP_DOWNLOAD} "${G_WWW_JJAZZLAB_DOWNLOAD}/"
# check downloaded file exists
if [ ! -f "${PATH_TMP_DOWNLOAD}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >${PATH_TMP_DOWNLOAD}<"
return -1
fi
PACKAGE_FIL=`cat ${PATH_TMP_DOWNLOAD}|grep Linux|\
grep "zip"|awk '{print $4}'|\
cut -d'"' -f2`
rm "${PATH_TMP_DOWNLOAD}"
# get download path to zip package
PATH_DOWNLOAD_PCK=`dirname $(dirname ${G_WWW_JJAZZLAB_DOWNLOAD})`/${PACKAGE_FIL}
JJFILENAME_ZIP=$(basename "$PATH_DOWNLOAD_PCK")
# download the jjazzlab package zip file
PATH_TMP_ZIP="${DIR_TMP_DOWNLOAD}/${JJFILENAME_ZIP}"
rm "${PATH_TMP_ZIP}" 2>/dev/null
wget -O ${PATH_TMP_ZIP} ${PATH_DOWNLOAD_PCK}
# check downloaded file exists
if [ ! -f "${PATH_TMP_ZIP}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >${PATH_TMP_ZIP}<"
return -1
fi
# check unzip is installed
EXEC_PATTERN_UZ="unzip"
EXEC_UNZIP="`which ${EXEC_PATTERN_UZ} 2>/dev/null`"
if [ -z "${EXEC_UNZIP}" ];then
[ "$OPT_VERBOSE" -gt 0 ] && \
echo -e "${CLR_BRO}WARNING:${CLR_NON} file not found ${EXEC_PATTERN_UZ}"
# install unzip
echo -e "${CLR_BLU}INFO:${CLR_NON} installing ${EXEC_PATTERN_UZ}"
_sudo_in_terminal apt-get install ${EXEC_PATTERN_UZ} -y
EXEC_UNZIP="`which ${EXEC_PATTERN_UZ} 2>/dev/null`"
if [ -z "${EXEC_UNZIP}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >${EXEC_PATTERN_UZ}<"
return -1
fi
fi
# unzip the jjazzlab package zip file
[ ! -d ${G_DIR_INSTALL_JJAZZLAB} ] &&\
echo -e "${CLR_RED}ERROR:${CLR_NON} install directory not found"\
">${G_DIR_INSTALL_JJAZZLAB}<"
if [ -w ${G_DIR_INSTALL_JJAZZLAB} ];then
unzip ${PATH_TMP_ZIP} -d ${G_DIR_INSTALL_JJAZZLAB}
else
_sudo_in_terminal unzip ${PATH_TMP_ZIP} -d ${G_DIR_INSTALL_JJAZZLAB}
fi
EXEC_JJAZZLAB="`find ${G_DIR_INSTALL_JJAZZLAB} -name ${EXEC_PATTERN_JL} -type f 2>/dev/null`"
return 0
}
# ======================================================================
jjazzlab_soundfont_check_install()
# ----------------------------------------------------------------------
# search recommended sound font in /usr/share/sounds/sf2/
# if not found
# - download from
# "archive.org/download/jjazz-lab-sound-font/JJazzLab-SoundFont.sf2"
# - and install
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON}"\
"jjazzlab_soundfont_check_install()"
FIL_SOUNDFONT="JJazzLab-SoundFont.sf2"
DIR_SOUNDFONT="/usr/share/sounds/sf2"
PATH_SOUNDFONT="${DIR_SOUNDFONT}/${FIL_SOUNDFONT}"
if [ ! -f "${PATH_SOUNDFONT}" ]; then
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} installing recommended sound font:\n"\
"${FIL_SOUNDFONT}"
_sudo_in_terminal wget -O ${PATH_SOUNDFONT} ${G_WWW_JJAZZLAB_SF2}
fi
if [ ! -f "${PATH_SOUNDFONT}" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} not found recommended sound font:\n"\
"${FIL_SOUNDFONT}"
echo "please install from ${G_WWW_SF2_ARTEFACTS}"
return -1
fi
[ "$OPT_VERBOSE" -gt 0 ] && \
echo -e "${CLR_BLU}INFO:${CLR_NON} found ${FIL_SOUNDFONT}:\n"\
"${PATH_SOUNDFONT}"
return 0
}
# ======================================================================
jjazzlab_soundfont_remove()
# ----------------------------------------------------------------------
# remove /usr/share/sounds/sf2/JJazzLab-SoundFont.sf2
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON}"\
"jjazzlab_soundfont_remove()"
TARGET_FIL="/usr/share/sounds/sf2/JJazzLab-SoundFont.sf2"
if [ -f "${TARGET_FIL}" ];then
if [ "yes" == $(_ask_yes_or_no "remove ${TARGET_FIL}?") ];then
sudo rm ${TARGET_FIL}
fi
fi
return 0
}
# ======================================================================
jjazzlab_start()
# ----------------------------------------------------------------------
# launch jjazzlab
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} jjazzlab_start()"
[ -z "${EXEC_JJAZZLAB}" ] &&\
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >jjazzlab<" &&\
exit -1
[ "$OPT_VERBOSE" -gt 0 ] && echo -e "${CLR_BLU}INFO:${CLR_NON} ${EXEC_JJAZZLAB}"
${EXEC_JJAZZLAB} 2>/dev/null
[ "$OPT_VERBOSE" -gt 0 ] && echo -e "${CLR_BLU}INFO:${CLR_NON} start_jjazzlab ends"
return 0
}
# ======================================================================
qsynth_check_install()
# ----------------------------------------------------------------------
# search executable in $PATH (which), install if not found
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth_check_install()"
EXEC_PATTERN_QS="qsynth"
[ "$OPT_VERBOSE" -gt 1 ] && \
echo -e "${CLR_BLU}INFO:${CLR_NON} checking which ${EXEC_PATTERN_QS}"
EXEC_QSYNTH="`which ${EXEC_PATTERN_QS} 2>/dev/null`"
if [ -z "${EXEC_QSYNTH}" ];then
[ "$OPT_VERBOSE" -gt 0 ] && \
echo -e "${CLR_BRO}WARNING:${CLR_NON} file not found ${EXEC_PATTERN_QS}"
echo -e "${CLR_BLU}INFO:${CLR_NON} installing ${EXEC_PATTERN_QS}"
_sudo_in_terminal apt-get install ${EXEC_PATTERN_QS} -y
EXEC_QSYNTH="`which ${EXEC_PATTERN_QS} 2>/dev/null`"
fi
if [ -z "${EXEC_QSYNTH}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >${EXEC_PATTERN_QS}<"
return -1
fi
[ "$OPT_VERBOSE" -gt 0 ] && \
echo -e "${CLR_BLU}INFO:${CLR_NON} found ${EXEC_PATTERN_QS}"\
"installation:\n ${EXEC_QSYNTH}"
return 0
}
# ======================================================================
qsynth_close()
# ----------------------------------------------------------------------
# close qsynth
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth_close()"
QSYNTH_STARTED="`pidof qsynth`"
if [ ! -z "$QSYNTH_STARTED" ]; then
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} kill qsynth (${QSYNTH_STARTED})"
kill ${QSYNTH_STARTED}
sleep 1
fi
num=1
while
[[ ! -z "${QSYNTH_STARTED}" && $num -le 10 ]]
do
sleep 1
num=$(($num+1))
QSYNTH_STARTED="`pidof qsynth`"
done
if [ ! -z "$QSYNTH_STARTED" ]; then
echo -e "${CLR_BLU}INFO:${CLR_NON} force kill qsynth!"
pkill -9 qsynth
sleep 1
fi
if [ ! -z "$QSYNTH_STARTED" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} failed to kill qsynth!"
return -1
fi
return 0
}
# ======================================================================
qsynth_remove()
# ----------------------------------------------------------------------
# remove qsynth the GUI front-end for Fluid Synth
# while installing qsynth already adds some libfulidsynth,
# the libfluidsynth needs to be explicitely removed using dpkg
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth_remove()"
qsynth_close
EXEC_PATTERN_QS=qsynth
EXEC_QSYNTH="`which ${EXEC_PATTERN_QS}`"
if [ ! -z "${EXEC_QSYNTH}" ];then
echo removing ${EXEC_QSYNTH}
sudo apt-get remove ${EXEC_PATTERN_QS}
fi
LIB_FLUID="`dpkg -l libfluidsynth* | grep synth|awk '{print $2}'`"
if [ ! -z "${LIB_FLUID}" ];then
echo removing ${LIB_FLUID}
sudo dpkg -r "${LIB_FLUID}"
fi
return 0
}
# ======================================================================
qsynth_configure()
# ----------------------------------------------------------------------
# update $HOME/.config/rncbc.org/Qsynth.conf
# AudioBufSize=512
# AudioDriver=alsa
# MidiDriver=alsa_seq
# MidiBankSelect=xg
# SoundFont1=/usr/share/sounds/sf2/JJazzLab-SoundFont.sf2
#
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth_config()"
QSYNTH_CHANGED=0
QSYNTH_CONF="$HOME/.config/rncbc.org/Qsynth.conf"
[ ! -f "${QSYNTH_CONF}" ] && return 0
# update AudioBufSize=512
AB_OK=`cat ${QSYNTH_CONF} | grep "AudioBufSize="`
if [ ! -z "${AB_OK}" ];then # found AudioBufSize=
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "found ${AB_OK}"
AB_OK=`cat ${QSYNTH_CONF} | grep "AudioBufSize=512"`
if [ -z "${AB_OK}" ];then # not found AudioBufSize=512
AB_OK=`cat ${QSYNTH_CONF} | grep "AudioBufSize="`
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "replacing found ${AB_OK}"
sed --in-place "s/${AB_OK}/AudioBufSize=512/" ${QSYNTH_CONF}
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth config: changed ${AB_OK}"
QSYNTH_CHANGED=1
fi
fi
# update AudioDriver=alsa
AD_OK=`cat ${QSYNTH_CONF} | grep "AudioDriver="`
if [ ! -z "${AD_OK}" ];then # found AudioDriver=
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "found ${AD_OK}"
AD_OK=`cat ${QSYNTH_CONF} | grep "AudioDriver=alsa"`
if [ -z "${AD_OK}" ];then # not found AudioDriver=alsa
AD_OK=`cat ${QSYNTH_CONF} | grep "AudioDriver="`
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "replacing found ${AD_OK}"
sed --in-place "s/${AD_OK}/AudioDriver=alsa/" ${QSYNTH_CONF}
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth config: changed ${AD_OK}"
QSYNTH_CHANGED=1
fi
fi
# update MidiDriver=alsa_seq
MDA_OK=`cat ${QSYNTH_CONF} | grep "MidiDriver="`
if [ ! -z "${MDA_OK}" ];then # found MidiDriver=
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "found ${MDA_OK}"
MDA_OK=`cat ${QSYNTH_CONF} | grep "MidiDriver=alsa_seq"`
if [ -z "${MDA_OK}" ];then # not found MidiDriver=alsa_seq
MDA_OK=`cat ${QSYNTH_CONF} | grep "MidiDriver="`
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "replacing found ${MDA_OK}"
sed --in-place "s/${MDA_OK}/MidiDriver=alsa_seq/" ${QSYNTH_CONF}
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth config: changed ${MDA_OK}"
QSYNTH_CHANGED=1
fi
fi
# update MidiBankSelect=xg
MBANKSEL_OK=`cat ${QSYNTH_CONF} | grep "MidiBankSelect="`
if [ ! -z "${MBANKSEL_OK}" ];then # found MidiBankSelect=
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "found ${MBANKSEL_OK}"
MBANKSEL_OK=`cat ${QSYNTH_CONF} | grep "MidiBankSelect=xg"`
if [ -z "${MBANKSEL_OK}" ];then # not found MidiBankSelect=xg
MBANKSEL_OK=`cat ${QSYNTH_CONF} | grep "MidiBankSelect="`
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "replacing found ${MBANKSEL_OK}"
sed --in-place "s/${MBANKSEL_OK}/MidiBankSelect=xg/" ${QSYNTH_CONF}
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth config: changed ${MBANKSEL_OK}"
QSYNTH_CHANGED=1
fi
fi
# add JJazzLab-SoundFont
SOUNDFONT_JL="/usr/share/sounds/sf2/JJazzLab-SoundFont.sf2"
SOUNDFONT_OK=`cat ${QSYNTH_CONF} | grep "[SoundFonts]"`
if [ -z "${SOUNDFONT_OK}" ];then # not found [SoundFonts]
echo "\[SoundFonts\]" >> ${QSYNTH_CONF}
echo "BankOffset1=0" >> ${QSYNTH_CONF}
echo -n "SoundFont1=${SOUNDFONT_JL}" >> ${QSYNTH_CONF}
else
SOUNDFONT_OK=`cat ${QSYNTH_CONF} | grep "SoundFont1="`
if [ ! -z "${SOUNDFONT_OK}" ];then # found SoundFont1=
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "found ${SOUNDFONT_OK}"
SOUNDFONT_OK=`cat ${QSYNTH_CONF} | grep "SoundFont1=${SOUNDFONT_JL}"`
if [ -z "${SOUNDFONT_OK}" ];then
SOUNDFONT_OK=`cat ${QSYNTH_CONF} | grep "SoundFont1="`
sed --in-place "s%${SOUNDFONT_OK}%SoundFont1=${SOUNDFONT_JL}%" ${QSYNTH_CONF}
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth config: changed JJazzLab-SoundFont"
QSYNTH_CHANGED=1
fi
else
echo -n "SoundFont1=${SOUNDFONT_JL}" >> ${QSYNTH_CONF}
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth config: added JJazzLab-SoundFont"
QSYNTH_CHANGED=1
fi
fi
return 0
}
# ======================================================================
qsynth_start()
# ----------------------------------------------------------------------
# launch qsynth the GUI front-end for Fluid Synth
# qsynth -m=alsa_seq -a=alsa -z=512 &
# configure $HOME/.config/rncbc.org/Qsynth.conf
# SoundFont1=/usr/share/sounds/sf2/JJazzLab-SoundFont.sf2
# AudioBufSize=512
# AudioDriver=alsa
# MidiDriver=alsa_seq
# MidiBankSelect=xg
#
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth_start()"
#QSYNTH_STARTED="`ps -m | grep qsynth`"
QSYNTH_STARTED="`pidof qsynth`"
if [ -z "$QSYNTH_STARTED" ]; then
[ "$OPT_VERBOSE" -gt 0 ] && echo -e "${CLR_BLU}INFO:${CLR_NON} qsynth &"
qsynth \
-m=alsa_seq \
-a=alsa \
-z=512 \
--option synth.midi-bank-select="xg" \
/usr/share/sounds/sf2/JJazzLab-SoundFont.sf2 &
while true
do
sleep 1
QSYNTH_STARTED=`pidof qsynth`
if [ ! -z "${QSYNTH_STARTED}" ];then
break
fi
done
fi
QSYNTH_STARTED="`pidof qsynth`"
if [ -z "$QSYNTH_STARTED" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} failed to start qsynth!"
return -1
fi
return 0
}
# ======================================================================
connect_virmidi_to_fluid()
# ----------------------------------------------------------------------
# 6 - Connect the "Virtual Raw MIDI" port to FluidSynth
# PORT_VIRMIDI=`aconnect -lo|grep "Virtual Raw MIDI"|awk '{print $2}'|head -1|cut -d':' -f 1`
# PORT_FLUID=`aconnect -lo|grep "FLUID"|awk '{print $2}'|head -1|cut -d':' -f 1`
# aconnect ${PORT_VIRMIDI}:0 ${PORT_FLUID}:0
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} connect_virmidi_to_fluid()"
# check qsynth was started before
QSYNTH_STARTED="`pidof qsynth`"
if [ -z "$QSYNTH_STARTED" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} process not started >qsynth<!"
return -1
fi
# check virtual midi port
PORT_VIRMIDI=`aconnect -lo|grep "Virtual Raw MIDI"|\
awk '{print $2}'|head -1|cut -d':' -f 1`
if [ -z "$PORT_VIRMIDI" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} port not found >Virtual Raw MIDI<!"
return -1
fi
# check fluid synth port
while true
do
PORT_FLUID=`aconnect -lo|grep "FLUID Synth"|\
awk '{print $2}'|head -1|cut -d':' -f 1`
if [ ! -z "${PORT_FLUID}" ]
then
break
fi
sleep 1
done
PORT_FLUID=`aconnect -lo|grep "FLUID Synth"|\
awk '{print $2}'|head -1|cut -d':' -f 1`
if [ -z "$PORT_FLUID" ]; then
echo -e "${CLR_RED}ERROR:${CLR_NON} port not found >FLUID Synth<!"
return -1
fi
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} aconnect"\
"${PORT_VIRMIDI}:0 ${PORT_FLUID}:0"
aconnect ${PORT_VIRMIDI}:0 ${PORT_FLUID}:0
return 0
}
# ======================================================================
get_version_local()
# ----------------------------------------------------------------------
# get local version
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} get_version_local()"
# verify programs are installed
if [ -z "${EXEC_JJAZZLAB}" ];then
# verify programs are installed
jjazzlab_find_installed
fi
if [ -z "${EXEC_JJAZZLAB}" ];then
# program not installed
echo -e "${CLR_BRO}WARNING:${CLR_NON} JJazzLab installation not found"
return -1
fi
DIR_CONFIG=`dirname \
$(echo ${EXEC_JJAZZLAB})`"/../etc"
FIL_CONFIG="${DIR_CONFIG}/jjazzlab.conf"
if [ -f "${FIL_CONFIG}" ];then
VERSION_INSTALLED=`cat ${FIL_CONFIG}|grep -o 'version=.*'|\
cut -d'"' -f1|cut -d'=' -f2`
else
# as JL is installed, this is before the first program run
echo -e "${CLR_BRO}WARNING:${CLR_NON} jjazzLab.conf not found\nwe assume before first run and continue..."
VERSION_INSTALLED=`dirname $(dirname ${EXEC_JJAZZLAB})|cut -d'-' -f2`
fi
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "VERSION_INSTALLED=${VERSION_INSTALLED}"
return 0
}
# ======================================================================
get_version_remote()
# ----------------------------------------------------------------------
# get remote version
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} get_version_remote()"
# download the jjazzlab download page
PATH_TMP_DOWNLOAD=/tmp/jazzlabpage.html
rm ${PATH_TMP_DOWNLOAD} 2>/dev/null
wget -O ${PATH_TMP_DOWNLOAD} ${G_WWW_JJAZZLAB_DOWNLOAD}
# check downloaded file exists
if [ ! -f "${PATH_TMP_DOWNLOAD}" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} file not found >${PATH_TMP_DOWNLOAD}<"
return -1
fi
VERSION_REMOTE=`cat ${PATH_TMP_DOWNLOAD}|grep Linux|\
grep "zip"|awk '{print $4}'|\
cut -d'"' -f2|cut -d'-' -f2`
rm "${PATH_TMP_DOWNLOAD}"
[ "$OPT_VERBOSE" -gt 0 ] &&\
echo "VERSION_REMOTE=${VERSION_REMOTE}"
return 0
}
# ======================================================================
opt_action()
# ----------------------------------------------------------------------
# check,install,run,close
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} opt_action()"
# verify programs are installed
jjazzlab_check_install
[ ! "$?" -eq "0" ] && exit -1
qsynth_check_install
[ ! "$?" -eq "0" ] && exit -1
jjazzlab_soundfont_check_install
[ ! "$?" -eq "0" ] && exit -1
# verify kernel set-up
kernel_add_virtualmidi
[ ! "$?" -eq "0" ] && exit -1
# start the programs
qsynth_start
[ ! "$?" -eq "0" ] && exit -1
connect_virmidi_to_fluid
[ ! "$?" -eq "0" ] && exit -1
jjazzlab_start
qsynth_close
return 0
}
# ======================================================================
opt_desktop()
# ----------------------------------------------------------------------
# create a desktop file
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} opt_desktop()"
jjazzlab_desktop_check_create
[ ! "$?" -eq "0" ] && return -1
return 0
}
# ======================================================================
opt_install()
# ----------------------------------------------------------------------
# check,install,run,close
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} opt_install()"
# verify programs are installed
jjazzlab_check_install
[ ! "$?" -eq "0" ] && exit -1
qsynth_check_install
[ ! "$?" -eq "0" ] && exit -1
jjazzlab_soundfont_check_install
[ ! "$?" -eq "0" ] && exit -1
# verify kernel set-up
kernel_add_virtualmidi
[ ! "$?" -eq "0" ] && exit -1
opt_version
return 0
}
# ======================================================================
opt_qsynth()
# ----------------------------------------------------------------------
# update qsynth config
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} opt_qsynth()"
qsynth_configure
return 0
}
# ======================================================================
opt_uninstall()
# ----------------------------------------------------------------------
# close,uninstall
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} opt_uninstall()"
jjazzlab_desktop_remove
qsynth_remove
jjazzlab_remove_installation
jjazzlab_soundfont_remove
kernel_clean
return 0
}
# ======================================================================
opt_version()
# ----------------------------------------------------------------------
# get local version
# ======================================================================
{
[ "$OPT_VERBOSE" -gt 1 ] &&\
echo -e "${CLR_BLU}INFO:${CLR_NON} opt_version()"
get_version_local
[ ! "$?" -eq "0" ] &&\
echo -e "${CLR_RED}ERROR:${CLR_NON} program version not detected" &&\
exit -1
get_version_remote
if [ ! "$?" -eq "0" ];then
echo -e "${CLR_RED}ERROR:${CLR_NON} version on webpage not detected"
VERSION_REMOTE="?"
fi
#VERSION_REMOTE="3.2.2"
if [ "${VERSION_INSTALLED}" == "${VERSION_REMOTE}" ];then
echo -e "installed version is up-to-date"\
"(${CLR_GRE}jazzlab ${VERSION_INSTALLED}${CLR_NON})"
else
echo -e "local version :"\
"${CLR_GRE}jazzlab ${VERSION_INSTALLED}${CLR_NON}"
echo -e "remote version:"\
"${CLR_GRE}jazzlab ${VERSION_REMOTE}${CLR_NON}"
fi
return 0
}
# ######################################################################
# main
# ######################################################################
# beautify messages for bash shell
_bash_define_colors
# check script parameters
[ $# -lt 1 ] && _usage && exit 0
OPT_VERBOSE=0 # 0=off, 1=simple, 2=debug
OPT_ACTION=0
OPT_DESKTOP=0
OPT_HELP=0
OPT_INSTALL=0
OPT_QSYNTH=0
OPT_UNINSTALL=0
OPT_VERSION=0
OPT_YES=0
while [ ! -z "$1" ];do
case "$1" in
"-a" | "-action") OPT_ACTION=1
;;
"-d" | "-desktop") OPT_DESKTOP=1
;;
"-h" | "-help") OPT_HELP=1
;;
"-l" | "-download") OPT_INSTALL=1
;;
"-q" | "-qsynth") OPT_QSYNTH=1
;;
"-r" | "-version") OPT_VERSION=1
;;
"-u" | "-uninstall") OPT_UNINSTALL=1
;;
"-v" | "-verbose") OPT_VERBOSE=1 # default
[ ! -z "$2" ] && [[ $2 =~ ^[0-9]+$ ]] && shift && _get_verbose_level $1
;;
"-y" | "-yes") OPT_YES=1
;;
*) echo -e "${CLR_RED}ERROR:${CLR_NON} wrong parameter $1" && _usage && exit -1;
break;;
esac
shift
done
[ "$OPT_ACTION" = "1" ] && opt_action && exit 0
[ "$OPT_HELP" = "1" ] && _usage && exit 0
[ "$OPT_INSTALL" = "1" ] && opt_install && exit 0
[ "$OPT_QSYNTH" = "1" ] && opt_qsynth && exit 0
[ "$OPT_UNINSTALL" = "1" ] && opt_uninstall && exit 0
[ "$OPT_VERSION" = "1" ] && opt_version && exit 0
[ "$OPT_DESKTOP" = "1" ] && opt_desktop && exit 0
exit 0
# END of script
########