]> gitweb.fluxo.info Git - hydra.git/commitdiff
Adding update subcommand and --rsync option at bootless
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 31 Dec 2012 20:20:51 +0000 (18:20 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 31 Dec 2012 20:20:51 +0000 (18:20 -0200)
share/hydra/bootless

index 19400d37b7853f4c9dc8df75520fa2bd5f6d05d3..86fd928f90845e0c1279b178efe9422b6be8133b 100755 (executable)
@@ -135,10 +135,14 @@ EOF
   fi
   
   # Copy data
-  $sudo git clone --depth=1 ${BOOTLESS_DIR} ${tmpdir}/boot
-  if [ $? != 0 ]; then
-    echo "Error: failed to clone repository \"${BOOTLESS_DIR}\" in \"${tmpdir}\" (errno: $?)."
-    exit 1
+  if [ "$2" == "--rsync" ]; then
+    $sudo rsync -Cav ${BOOTLESS_DIR}/ ${tmpdir}/boot/
+  else
+    $sudo git clone --depth=1 ${BOOTLESS_DIR} ${tmpdir}/boot
+    if [ $? != 0 ]; then
+      echo "Error: failed to clone repository \"${BOOTLESS_DIR}\" in \"${tmpdir}\" (errno: $?)."
+      exit 1
+    fi
   fi
   
   # Grub legacy
@@ -160,6 +164,45 @@ EOF
   $sudo rm -rf ${tmpdir}
 }
 
+# Update a boot device
+function hydra_bootless_update {
+  # Set folder
+  hydra_bootless_folder
+
+  # Set sudo config
+  local sudo
+  if [ "`whoami`" != 'root' ]; then
+    sudo="sudo"
+  fi
+
+  # Target device consistency check
+  if [ ! -b ${device} ]; then
+    echo "Error: device \"${device}\" not found."
+    exit 1
+  elif [ ! -d "${tmpdir}/boot" ]; then
+    echo "Error: bootless repository not found at ${device}."
+    exit 1
+  fi
+
+  tmpdir=`mktemp -d`
+  $sudo mount ${device} ${tmpdir}
+  if [ $? != 0 ]; then
+    echo "Error: failed to mount \"${device}\" filesystem in \"${tmpdir}\" (errno: $?)."
+    exit 1
+  fi
+
+  # Copy data
+  if [ -d "${tmpdir}/boot/.git" ]; then
+    ( cd ${tmpdir}/boot && $sudo git pull origin master )
+  else
+    $sudo rsync -Cav ${BOOTLESS_DIR}/ ${tmpdir}/boot/
+  fi
+
+  # Finalize
+  $sudo umount ${tmpdir}
+  $sudo rm -rf ${tmpdir}
+}
+
 # Repository initiator
 function hydra_bootless_init {
   mkdir -p $HYDRA_FOLDER
@@ -262,6 +305,9 @@ elif [ "$1" == "make" ]; then
 elif [ "$1" == "init" ]; then
   shift
   hydra_bootless_init $*
+elif [ "$1" == "update" ]; then
+  shift
+  hydra_bootless_update $*
 elif [ "$1" == "git" ]; then
   shift
   hydra_bootless_git $*