]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Misc enhancements: show available ISOs at install usage, make 'boot' be an alias...
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 21 Jun 2018 15:49:16 +0000 (12:49 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 21 Jun 2018 15:49:16 +0000 (12:49 -0300)
kvmx

diff --git a/kvmx b/kvmx
index ae1a7cd143ce8fc030acb69ea031c4dd0fb3299a..6aa1ac42937ef1447b83282188f39de86b91fe6a 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -202,7 +202,8 @@ function __kvmx_initialize {
 
     if [ ! -e "$image" ] && [ "$ACTION" != "up" ]           && [ "$ACTION" != "provision" ] && [ "$ACTION" != "purge" ]   \
                          && [ "$ACTION" != "destroy" ]      && [ "$ACTION" != "install" ]   && [ "$ACTION" != "config" ]  \
-                         && [ "$ACTION" != "config_unset" ] && [ "$ACTION" != "create" ]    && [ "$ACTION" != "shell" ]; then
+                         && [ "$ACTION" != "config_unset" ] && [ "$ACTION" != "create" ]    && [ "$ACTION" != "shell" ]   \
+                         && [ "$ACTION" != "boot" ]; then
       echo "$BASENAME: file not found: $image"
       exit 1
     fi
@@ -1713,6 +1714,22 @@ function kvmx_install {
 
   if [ -z "$media" ]; then
     echo "usage: $BASENAME install $VM <installation-media>"
+
+    # Possible places to find existing ISOs
+    local candidates="/var/cache/media/distros /usr/local/share/isos"
+
+    for candidate in $candidates; do
+      if [ -d "$candidate" ]; then
+        results="`find $candidate -not -iwholename '*.git*' -name '*.iso' | sed -e 's/^/\t/'`"
+
+        if [ ! -z "$results" ]; then
+          echo "available images at $candidate:"
+          echo ""
+          echo -n "$results"
+        fi
+      fi
+    done
+
     exit 1
   elif [ ! -e "$media" ]; then
     echo "$BASENAME: file not found: $media"
@@ -1742,6 +1759,11 @@ function kvmx_install {
   kvmx_up
 }
 
+# Alias to install
+function kvmx_boot {
+  kvmx_install $*
+}
+
 # Serial console
 function kvmx_console {
   if ! kvmx_running; then
@@ -1806,12 +1828,13 @@ function kvmx_version {
 
 # Shell
 function kvmx_shell {
+  local last_exit_code="0"
   local restricted="$1"
   local restricted_actions=":status:start:stop:poweroff:suspend:resume:console:monitor"
         restricted_actions="$restricted_actions:wipe:shred:app_base:version:list_image:kill:"
 
   # While a "quit" command isn't entered, read STDIN
-  while read -rep "kvmx:/${USER}@${VM}> " STDIN; do
+  while read -rep "$last_exist_code kvmx:/${USER}@${VM}> " STDIN; do
     history -s "$STDIN"
 
     if [ "$STDIN" == "quit" ] || [ "$STDIN" == "exit" ] || [ "$STDIN" == "bye" ]; then
@@ -1829,9 +1852,11 @@ function kvmx_shell {
           echo "Allowed commands are only `echo $restricted_actions | tr ':' ' '`"
         else
           $APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1}
+          last_exit_code="$?"
         fi
       else
         $APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1}
+        last_exit_code="$?"
       fi
     fi
   done