]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Make kvmx-supervise work for regular users
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 28 Jan 2018 12:50:23 +0000 (10:50 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 28 Jan 2018 12:50:23 +0000 (10:50 -0200)
kvmx-status
kvmx-supervise

index eabfed7ce54ce08a1ec3d04c1f8f4870fe28beda..6a90997229da44017bb0a9425fb1919c8d8b7d55 100755 (executable)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-# Get instances
-instances="`kvmx list`"
+# Parameters
+DIRNAME="`dirname $0`"
 
-# Kill old instances
-for vm in $instances; do
-  kvmx status $vm
-done
+# Dispatch to kvmx-supervise
+$DIRNAME/kvmx-supervise status
+
+# Old implementation
+## Get instances
+#instances="`kvmx list`"
+#
+## Kill old instances
+#for vm in $instances; do
+#  kvmx status $vm
+#done
index 72c2cdca659d44697cb172f3d69336fd8a34c523..aa0002a2d915b56d9814983834fbb010878a4524 100755 (executable)
@@ -33,10 +33,13 @@ VERSION="`$APP_BASE/kvmx version`"
 
 # Initialize
 function __kvmx_supervise_initialize {
-  if [ "`whoami`" != "root" ]; then
-    echo "$BASENAME: needs root privileges"
-    exit 1
-  fi
+  #if [ "`whoami`" != "root" ]; then
+  #  echo "$BASENAME: needs root privileges"
+  #  exit 1
+  #fi
+
+  # Put startup code here
+  true
 }
 
 # Display usage
@@ -83,13 +86,23 @@ function kvmx_supervise_call {
     exit 1
   fi
 
-  # Operate only with VMs configured with supervise_manage=1
+  # When running as root, operate only with VMs configured with supervise_manage=1
   # Specify /bin/bash to avoid restricted shells like kvmx-shell
-  supervise_manage="`su $user -s /bin/bash -c "kvmx config $vm supervise_manage"`"
+  if [ "`whoami`" == "root" ]; then
+    supervise_manage="`su $user -s /bin/bash -c "kvmx config $vm supervise_manage"`"
+  else
+    supervise_manage="1"
+  fi
 
   # Dispatch
   if [ "$supervise_manage" == "1" ]; then
-    su $user -s /bin/bash -c "kvmx ${params[0]} $vm ${params[@]:1}"
+    if [ "`whoami`" == "root" ]; then
+      su $user -s /bin/bash -c "kvmx ${params[0]} $vm ${params[@]:1}"
+    else
+      if [ "`whoami`" == "$user" ]; then
+        kvmx ${params[0]} $vm ${params[@]:1}
+      fi
+    fi
   fi
 }