]> gitweb.fluxo.info Git - hydra.git/commitdiff
Now bootless image can record image directly to device
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 15 Feb 2013 23:30:16 +0000 (21:30 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 15 Feb 2013 23:30:16 +0000 (21:30 -0200)
share/hydra/bootless

index 511b3174c942aa45b4108ebcc63bcb70ea926362..cc34e1f31e25cb5667618f5d7399f02ad693efae 100755 (executable)
@@ -77,20 +77,9 @@ EOF
   usbdevice=`echo ${device} | sed -e s/[0-9]\$//g`
   
   # Issue a warning
-  cat <<EOF
-
-******************
-*  ATTENTION!!!  *
-******************
-
-If you continue, all data in device "${device}" will be destroyed!
-
-EOF
-
-  echo -n "Are you sure you want to continue? Type uppercase \"YES\": "
-  read go
+  hydra_bootless_warning ${device}
   
-  if [ "${go}" != "YES" ]; then
+  if [ "$?" != "0" ]; then
     echo "Aborting..."
     exit 1
   fi
@@ -313,18 +302,48 @@ function hydra_bootless_device {
   fi
 }
 
+function hydra_bootless_warning {
+  local device=$1
+  local go
+
+  echo "******************"
+  echo "*  ATTENTION!!!  *"
+  echo "******************"
+  echo ""
+  echo "If you continue, all data in device \"${device}\" will be destroyed!"
+  echo ""
+  echo -n "Are you sure you want to continue? Type uppercase \"YES\": "
+  read go
+
+  if [ "${go}" != "YES" ]; then
+    false
+  else
+    true
+  fi
+}
+
 # Generate a bootless disk image
-# TODO: optionally copy to removable media
 function hydra_bootless_image {
   local output="$1"
+  local device="$2"
 
-  if [ -z "$output" ]; then
+  # Fix parameters
+  if echo ${output} | grep -q "/dev/"; then
+    output="bootless.img"
+    device="$1"
+  elif [ -z "$output" ]; then
     output="bootless.img"
   fi
 
   # Set folder
   hydra_bootless_folder
 
+  # Set sudo config
+  local sudo
+  if [ "`whoami`" != 'root' ]; then
+    sudo="sudo"
+  fi
+
   # Copy data
   tmpdir=`mktemp -d`
   $sudo rsync -Cav ${BOOTLESS_DIR}/ ${tmpdir}/boot/
@@ -332,9 +351,37 @@ function hydra_bootless_image {
   # Make rescue disk
   grub-mkrescue -o ${output} ${tmpdir}
 
+  # Optionally copy to removable media
+  if [ ! -z "$device" ]; then
+    # Issue a warning
+    hydra_bootless_warning ${device}
+
+    if [ "$?" != "0" ]; then
+      echo "Skipping copy of ${output} to ${device}..."
+    else
+      # Check if device is mounted
+      if [ "`mount | grep ${device}`" != "" ]; then
+        echo "Error: device \"${device}\" is mounted."
+        echo "Skipping copy of ${output} to ${device}..."
+      else
+        $sudo dd if=${output} of=${device}
+      fi
+    fi
+
+  fi
+
   # Cleanup
   rm -rf ${tmpdir}
-  echo "Image saved at ${output}"
+
+  # Finish
+  if [ -z "$device" ]; then
+    echo "Image saved at ${output}"
+  else
+    echo "Removing image ${output}..."
+    rm ${output}
+  fi
+
+  echo "Done."
 }
 
 # Usage