un outil de sondage - retour accueil
git clone git://bebou.netlib.re/kun
Log | Files | Refs | README |
commit 8daca2f9bbceaf317d0b81360478b24643639962 parent 2d5c16965d711af49825923743308a0133b8db95 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Tue, 19 Nov 2024 11:26:02 +0100 Possibilité de piper des commandes dans kun L'idée est de pouvoir écrire des scripts dans un fichier texte et faire < script.kun | ssh kun Voir ssh kun getlog id | ssh kun Diffstat:
M | kun.sh | | | 45 | ++++++++++++++++++++++++++++++--------------- |
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/kun.sh b/kun.sh @@ -12,32 +12,45 @@ _help() { echo "Les commandes dispos : \n" grep -E -B3 "^[a-zA-Z]+ *\(\) *{ *$" ./commands.sh | grep -v ^$ - exit 0 } -[ -n "$SSH_ORIGINAL_COMMAND" ] && set -- $SSH_ORIGINAL_COMMAND +kunscript=$(mktemp) +trap "rm -rf $kunscript" EXIT TERM QUIT INT + +if [ -n "$SSH_ORIGINAL_COMMAND" ];then + echo "$SSH_ORIGINAL_COMMAND" > $kunscript +elif [ -n "$1" ];then + echo "$@" > $kunscript +elif [ ! -t 0 ];then + cat > $kunscript +fi # Probablement safe mais fastidieux -if [ -n "$1" ];then +while read cmd;do + set -- $cmd case "$1" in - (create) create "$2" && exit 0 || exit 1;; - (addanswer) addanswer "$2" "$3" "$4" && exit 0 || exit 1;; - (modifyanswer) modifyanswer "$2" "$3" "$4" && exit 0 || exit 1;; - (deletequestion) deletequestion "$2" && exit 0 || exit 1;; - (deleteanswer) deleteanswer "$2" "$3" && exit 0 || exit 1;; - (results) results "$2" && exit 0 || exit 1;; - (getpeople) getpeople "$2" && exit 0 || exit 1;; - (getanswer) getanswer "$2" "$3" && exit 0 || exit 1;; - (getlog) getlog "$2" && exit 0 || exit 1;; - (-h) _help;; + (create) create "$2" || exit 1;; + (addanswer) addanswer "$2" "$3" "$4" || exit 1;; + (modifyanswer) modifyanswer "$2" "$3" "$4" || exit 1;; + (deletequestion) deletequestion "$2" || exit 1;; + (deleteanswer) deleteanswer "$2" "$3" || exit 1;; + (results) results "$2" || exit 1;; + (getpeople) getpeople "$2" || exit 1;; + (getanswer) getanswer "$2" "$3" || exit 1;; + (getlog) getlog "$2" || exit 1;; + (-h) _help;exit 0;; (*) _die "Commande n'existe pas";exit 1;; esac -fi +done < $kunscript +# Si on lit pas depuis un term on termine ici +[ ! -t 0 ] && exit 0 +# Sinon on créé le fichier de log logfile=$(mktemp /tmp/kun.XXX.log) exec 3> $logfile +# Et on lance la TUI while [ ! "$k" = "quitter" ];do t="";l=""; @@ -111,4 +124,6 @@ while [ ! "$k" = "quitter" ];do done chmod +x $logfile -printf "Fichier de log : %s\n" $logfile +[ -s "$logfile" ] \ + && printf "Fichier de log : %s\n" $logfile \ + || rm "$logfile"