diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2012-04-12 23:59:27 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2012-04-12 23:59:27 -0300 |
commit | 73d17146d0d5fd71d4f4aa54a374a87d4577dd36 (patch) | |
tree | 6ea9ca681ff1efe65547c0d8ac9623ac42c233f4 | |
parent | be3642b12f752622166428a79a3466c533fc79ec (diff) | |
download | hydra-73d17146d0d5fd71d4f4aa54a374a87d4577dd36.tar.gz hydra-73d17146d0d5fd71d4f4aa54a374a87d4577dd36.tar.bz2 |
Using hydra_safe_run on provision
-rw-r--r-- | lib/hydra/misc | 14 | ||||
-rwxr-xr-x | share/hydractl/provision | 40 |
2 files changed, 34 insertions, 20 deletions
diff --git a/lib/hydra/misc b/lib/hydra/misc index 34abf1a..eb0a9aa 100644 --- a/lib/hydra/misc +++ b/lib/hydra/misc @@ -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 $* +} diff --git a/share/hydractl/provision b/share/hydractl/provision index b77c4d7..ef60edf 100755 --- a/share/hydractl/provision +++ b/share/hydractl/provision @@ -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..." |