From cfd7d528e2e06805f1e3ba55ef9ce59786aa98eb Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Mon, 12 Aug 2019 15:46:29 +0200 Subject: [PATCH] Actually do something on upgradeAll --- registry/scripts/upgrade_all.sh | 40 +++++++++++++++++++++++++++++---- wol/scripts/actions.sh | 6 +---- wol/scripts/wakeonlanservice.sh | 6 +++-- wol/www/index.php | 8 ++----- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/registry/scripts/upgrade_all.sh b/registry/scripts/upgrade_all.sh index a3b8eb8..cdf3224 100755 --- a/registry/scripts/upgrade_all.sh +++ b/registry/scripts/upgrade_all.sh @@ -45,12 +45,44 @@ broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | cut -d / -f 1) wait_time=120 wait_step=5 -cmd="cd /opt/primtux-eole/; export HTTPS_PROXY='http://dnsproxy:3128'; git pull; ./upgrade-session.sh $1" +if [ ! -z "$2" ] +then + # $1 == Apt, $2 == hostname or $@ == command + if [ "$1" == "Apt" ] + then + arg="apt" + host="$2" + else + arg="$@" + fi +elif [ ! -z "$1" ] +then + # $1 == Apt, hostname or $@ == command + if [ "$1" == "Apt" ] + then + arg="apt" + elif [ ! -z "$(grep $1 /etc/registry/hosts)" ] + then + host="$1" + else + arg="$@" + fi +fi + +cmd="cd /opt/primtux-eole/; export HTTPS_PROXY='http://dnsproxy:3128'; git pull; ./upgrade-session.sh $arg" +echo $cmd declare -A HOSTS declare -A IPTOMACS declare -A DOWNS -while read date mac name +if [ -z "$host" ] +then + catcmd="cat $conf_file" +else + catcmd="grep $host $conf_file" +fi + +while read date mac name endline do # Boot machine if [ ! -z "$date" ] @@ -62,9 +94,9 @@ do wakeonlan -i $broadcast "$mac" done sleep 5 - MACS+=" $mac" + MACS="$MACS $mac" fi -done < $conf_file +done < <($catcmd) # Wait for boot log "Wakeonlan sent, waiting" diff --git a/wol/scripts/actions.sh b/wol/scripts/actions.sh index 630027d..308a936 100755 --- a/wol/scripts/actions.sh +++ b/wol/scripts/actions.sh @@ -27,8 +27,4 @@ host=$subnet.52 echo $@ | netcat $host $port -# If action is "get" something, read answer -if [[ "$1" =~ "get" ]] -then - stdbuf -i0 -o0 -e0 $netcat -fi +stdbuf -i0 -o0 -e0 $netcat diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh index 4c824f3..678c66a 100755 --- a/wol/scripts/wakeonlanservice.sh +++ b/wol/scripts/wakeonlanservice.sh @@ -88,7 +88,9 @@ do fi elif [[ "$LINE" =~ "upgrade" ]] then - #TODO call directly upgrade script - false + DIR="$(realpath $(dirname $0))/../../registry/scripts/" + subactions="$(echo $LINE | sed -e 's/^upgrade//' -e 's/All//')" + nohup $DIR/upgrade_all.sh $subactions & + echo "Started 'upgrade_all.sh $subactions' in background on $(date)" | answer fi done diff --git a/wol/www/index.php b/wol/www/index.php index 1a77e9c..258e75e 100644 --- a/wol/www/index.php +++ b/wol/www/index.php @@ -232,7 +232,7 @@ if(!isset($action)){ }else{ if(in_array($action, $allowedActions)){ $lines = array(); - exec("../scripts/actions.sh .".escapeshellarg($action)." " + exec("../scripts/actions.sh ".escapeshellarg($action)." " .escapeshellarg($name), $lines, $code); echo "<p>Action effectuée, code : $code</p>"; if(!empty($lines)){ @@ -242,11 +242,7 @@ if(!isset($action)){ } echo "</pre>"; }else{ - if(preg_match('/^getLog/', $action)){ - echo "<p>Pas de log globaux disponibles</p>"; - }else{ - echo "<p>Not implemented yet</p><p>Cette action n'affiche pas de message.<br />Vous pouvez demander les logs depuis <a href='/wol/'>la page principale<a></p>"; - } + echo "<p>Erreur : pas de réponse</p>"; } } } -- GitLab