]> gitweb.fluxo.info Git - hydra.git/commitdiff
Using hydra_safe_run on provision
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 13 Apr 2012 02:59:27 +0000 (23:59 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 13 Apr 2012 02:59:27 +0000 (23:59 -0300)
lib/hydra/misc
share/hydractl/provision

index 34abf1a6f6248989f08fc50120fc40fc6a10c505..eb0a9aa0163a6f3381d377d200b54bdf0e595d1c 100644 (file)
@@ -81,3 +81,17 @@ function hydra_check_group {
 
   grep -qe "^$1:" /etc/group
 }
+
+# Abort on error
+function hydra_exit_on_error {
+  if [ "$?" != "0" ]; then
+    echo "Error: $*"
+    exit 1
+  fi
+}
+
+# Run a command or abort
+function hydra_safe_run {
+  $*
+  hydra_exit_on_error $*
+}
index b77c4d7dc6f7f01322ec247566a8555d4684d42a..ef60edf72d8765a0fa601ef42ab4bbe0c05cb0dc 100755 (executable)
@@ -48,23 +48,23 @@ read answer
 
 # Disk partitioning.
 if [ "$swap" == "y" ]; then
-  parted -s -- $device mklabel msdos
-  parted -s -- $device unit MB mkpart primary linux-swap 0     2000
-  parted -s -- $device unit MB mkpart primary ext2       2000  2200
-  parted -s -- $device unit MB mkpart primary ext2       2200 -1
-  parted -s -- $device set 2 boot on
-  parted -s -- $device set 3 lvm  on
+  hydra_safe_run parted -s -- $device mklabel msdos
+  hydra_safe_run parted -s -- $device unit MB mkpart primary linux-swap 0     2000
+  hydra_safe_run parted -s -- $device unit MB mkpart primary ext2       2000  2200
+  hydra_safe_run parted -s -- $device unit MB mkpart primary ext2       2200 -1
+  hydra_safe_run parted -s -- $device set 2 boot on
+  hydra_safe_run parted -s -- $device set 3 lvm  on
 
   # Change devices to absolute path names.
   swap_device="$device"1
   boot_device="$device"2
   syst_device="$device"3
 else
-  parted -s -- $device mklabel msdos
-  parted -s -- $device unit MB mkpart primary ext2 0    200
-  parted -s -- $device unit MB mkpart primary ext2 200 -1
-  parted -s -- $device set 1 boot on
-  parted -s -- $device set 2 lvm  on
+  hydra_safe_run parted -s -- $device mklabel msdos
+  hydra_safe_run parted -s -- $device unit MB mkpart primary ext2 0    200
+  hydra_safe_run parted -s -- $device unit MB mkpart primary ext2 200 -1
+  hydra_safe_run parted -s -- $device set 1 boot on
+  hydra_safe_run parted -s -- $device set 2 lvm  on
 
   # Change devices to absolute path names.
   boot_device="$device"1
@@ -76,20 +76,20 @@ echo "Creating the needed disk volumes..."
 
 if ! pvdisplay $syst_device &> /dev/null; then
   echo "Creating physical volume..."
-  pvcreate $syst_device
+  hydra_safe_run pvcreate $syst_device
 fi
 
 if ! vgdisplay $vg &> /dev/null; then
   echo "Creating volume group..."
-  vgcreate $vg $syst_device
+  hydra_safe_run vgcreate $vg $syst_device
 fi
 
 if ! lvdisplay $vg/root &> /dev/null; then
   echo "Creating logical volume..."
-  lvcreate -L$root_size -n root $vg
+  hydra_safe_run lvcreate -L$root_size -n root $vg
 fi
 
-vgchange -a y $vg
+hydra_safe_run vgchange -a y $vg
 
 # Garbage.
 if [ "$garbage" == "y" ]; then
@@ -108,9 +108,9 @@ umount /tmp/debootstrap/dev  &> /dev/null
 # Create root device.
 if [ "$encrypt" == "y" ]; then
   echo "Creating encrypted root device..."
-  cryptsetup -h sha256 -c aes-cbc-essiv:sha256 -s 256 luksFormat /dev/$vg/root
-  cryptsetup luksOpen /dev/$vg/root debootstrap
-  mkfs.ext3 /dev/mapper/debootstrap
+  hydra_safe_run cryptsetup -h sha256 -c aes-cbc-essiv:sha256 -s 256 luksFormat /dev/$vg/root
+  hydra_safe_run cryptsetup luksOpen /dev/$vg/root debootstrap
+  hydra_safe_run mkfs.ext3 /dev/mapper/debootstrap
   install_device="/dev/mapper/debootstrap"
 else
   echo "Creating root device..."
@@ -120,8 +120,8 @@ fi
 
 # Initial system install.
 echo "Installing base system..."
-mount $install_device /tmp/debootstrap/
-debootstrap --arch=$arch $version /tmp/debootstrap/ $mirror
+hydra_safe_run mount $install_device /tmp/debootstrap/
+hydra_safe_run debootstrap --arch=$arch $version /tmp/debootstrap/ $mirror
 
 # Initial configuration.
 echo "Applying initial configuration..."