#!/bin/bash
# script de gestion de configuration pour Qsynth
#	Daniel Génon 15 12 2015  Revin
#
#	Ce script remplace le fichier de configuration qsynth par un fichier de configuration personnelle
#	Pour utiliser ce script :
#		Dans un terminal taper la commande :
#			DemQsynth <parametre1>
#
#		parametre1 = chemin + nom du fichier + extension (c'est vous qui décidez de l'extension)
#
#echo "Ce script permet d'activer une configuration personnelle pour Qsynth"
##########################################################
# paramètres
##########################################################
nomconfig=
if [ -n "$1" ];
	then
		nomconfig=$1
fi
##########################################################
# Déclaration des variables pour info
##########################################################
# chemin où est stocké le fichier configuration de Qsynth
	conforigine=~/.config/rncbc.org/Qsynth.conf
	confcopie=~/.config/rncbc.org/Qsynth.cvix
#####################################
#
#	Démarrage du shell
#
#####################################
#test qsynth en cours de process
ps -C qsynth >fictest
{
	read nomtest
	read nomtest
}<fictest

if [ -n "$nomtest" ];
	then
		echo "Qsynth est déjà lancé"
		echo -n "Détruire le process Qsynth"
		echo -n "(la config en cours ne sera pas sauvée) O/N : "
		read nomtest
		if [ "$nomtest" = "O" ];
			then
				killall qsynth
			else
				exit 1
		fi
fi
rm -f fictest

#tester l'existence du fichier config perso
if [ -n "$nomconfig" ];
	then
		if [ -e "$nomconfig" ];			
			then
#sauvegarde de la config de la dernière sortie de qsynth
				cp -T $conforigine $confcopie
#copie de la config perso en config qsynth
				cp -T $nomconfig $conforigine
			else
				echo "La configuration personnelle n'est pas trouvée"
		fi
fi

# démarrage de qsynth
/usr/bin/qsynth
# 2 ligne pour tester le shell
#echo "entrez pour sortir : "
#read dehors
#sauvegarde de la config qsynth en config perso pour récupérer les modifications
if [ -n "$nomconfig" ];
	then
		cp -T $conforigine $nomconfig
fi

exit 0

