reformatted plc.d/functions
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 21 Nov 2024 14:17:42 +0000 (15:17 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 21 Nov 2024 14:27:45 +0000 (15:27 +0100)
plc.d/functions

index fa44a5c..caf1b75 100644 (file)
@@ -28,17 +28,17 @@ function action() {
 ERRORS=0
 
 # Count the exit status of the last command
-function check () {
-    ERRORS=$(($ERRORS+$?))
+function check() {
+    ERRORS=$(($ERRORS + $?))
 }
 
-function dialog () {
+function dialog() {
     echo -n "PLC: $*: " >&3
 }
 
 # Print result
-function result () {
-    if [ $ERRORS -eq 0 ] ; then
+function result() {
+    if [ $ERRORS -eq 0 ]; then
         success "$@" >&3
     else
         failure "$@" >&3
@@ -47,15 +47,15 @@ function result () {
 }
 
 # Start up a program with a plc_ prefix
-function plc_daemon () {
+function plc_daemon() {
     base=${1##*/}
 
     # See if it's already running. Look *only* at the pid file.
     if [ -f /var/run/plc_${base}.pid ]; then
         local line p
-        read line < /var/run/plc_${base}.pid
-        for p in $line ; do
-                [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
+        read line </var/run/plc_${base}.pid
+        for p in $line; do
+            [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
         done
     fi
 
@@ -71,10 +71,13 @@ function plc_daemon () {
     # #1  0x003c2e7d in ___newselect_nocancel () from /lib/libc.so.6
     # #2  0x004387b4 in main () from /usr/sbin/sshd
     # So I figured the various file descriptors used were not properly closed
-    (exec 3>&- 4>&- ; exec -a plc_${base} $*)
+    (
+        exec 3>&- 4>&-
+        exec -a plc_${base} $*
+    )
     ret=$?
 
-    if [ -f /var/run/${base}.pid ] ; then
+    if [ -f /var/run/${base}.pid ]; then
         mv /var/run/${base}.pid /var/run/plc_${base}.pid
     fi
 
@@ -82,21 +85,21 @@ function plc_daemon () {
 }
 
 # Print IP address of hostname if resolvable
-function gethostbyname () {
+function gethostbyname() {
     local host="$1"; shift
     python3 -c "import socket; import sys; print(socket.gethostbyname('${host}'))"
 }
 
 # Forcefully make a symlink
-function symlink () {
+function symlink() {
     mkdir -p $(dirname $2)
     rm -f $2
     ln -s $1 $2
 }
 
 # Argument(s) or stdin to lowercase stdout
-function lower () {
-    if [ ${#*} -ge 1 ] ; then
+function lower() {
+    if [ ${#*} -ge 1 ]; then
         tr A-Z a-z <<<$*
     else
         tr A-Z a-z
@@ -104,8 +107,8 @@ function lower () {
 }
 
 # Argument(s) or stdin to uppercase stdout
-function upper () {
-    if [ ${#*} -ge 1 ] ; then
+function upper() {
+    if [ ${#*} -ge 1 ]; then
         tr a-z A-Z <<<$*
     else
         tr a-z A-Z
@@ -113,7 +116,7 @@ function upper () {
 }
 
 # Regenerate configuration files
-function plc_reload () {
+function plc_reload() {
     force=$1
 
     # Regenerate the main configuration file from default values
@@ -124,31 +127,31 @@ function plc_reload () {
         /etc/planetlab/configs/site.xml
     )
 
-    for file in "${files[@]}" ; do
-    if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
-        tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
-        plc-config --xml "${files[@]}" >$tmp
-        if [ $? -eq 0 ] ; then
-        mv $tmp /etc/planetlab/plc_config.xml
-        chmod 444 /etc/planetlab/plc_config.xml
-        else
-        echo "PLC: Warning: Invalid configuration file(s) detected"
-        rm -f $tmp
+    for file in "${files[@]}"; do
+        if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ]; then
+            tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
+            plc-config --xml "${files[@]}" >$tmp
+            if [ $? -eq 0 ]; then
+                mv $tmp /etc/planetlab/plc_config.xml
+                chmod 444 /etc/planetlab/plc_config.xml
+            else
+                echo "PLC: Warning: Invalid configuration file(s) detected"
+                rm -f $tmp
+            fi
+            break
         fi
-        break
-    fi
     done
 
     # Convert configuration to various formats
-    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
-    plc-config --shell >/etc/planetlab/plc_config
+    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ]; then
+        plc-config --shell >/etc/planetlab/plc_config
     fi
-    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
-    plc-config --python >/etc/planetlab/plc_config.py
+    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ]; then
+        plc-config --python >/etc/planetlab/plc_config.py
     fi
-    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
-    mkdir -p /etc/planetlab/php
-    plc-config --php >/etc/planetlab/php/plc_config.php
+    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ]; then
+        mkdir -p /etc/planetlab/php
+        plc-config --php >/etc/planetlab/php/plc_config.php
     fi
 }
 
@@ -171,7 +174,7 @@ function plc_reload () {
 # Require       all granted
 # </Directory>
 
-function apache_newauth () {
+function apache_newauth() {
     # somehow in 2019 apachectl stopped answering the -V option
     # apache_version=$(apachectl -V 2> /dev/null | grep 'Server version' | cut -d ' ' -f3 | sed -e 's,^.*/,,')
     apache_version=$(rpm -q --queryformat "%{VERSION}" httpd)
@@ -179,14 +182,14 @@ function apache_newauth () {
     apache_minor=$(echo $apache_version | cut -d. -f2)
     test "$apache_minor" -ge 4
 }
-function apache_allow () {
+function apache_allow() {
     if apache_newauth; then
         echo -e "Require all granted"
     else
         echo -e "Order allow,deny\n   Allow from all"
     fi
 }
-function apache_forbid () {
+function apache_forbid() {
     if apache_newauth; then
         echo -e "Require all denied"
     else