diff options
Diffstat (limited to 'share/hydractl/provision')
-rwxr-xr-x | share/hydractl/provision | 115 |
1 files changed, 59 insertions, 56 deletions
diff --git a/share/hydractl/provision b/share/hydractl/provision index bafc8b6..b15c768 100755 --- a/share/hydractl/provision +++ b/share/hydractl/provision @@ -137,6 +137,9 @@ if [ ! -z "$1" ]; then fi fi +# Parameters +WORK="/tmp/debootstrap" + # Get config parameters. hydra_provision_config @@ -219,15 +222,15 @@ if [ "$garbage" == "y" ]; then fi # Make sure that the mountpoint exists -hydra_sudo_run mkdir -p /tmp/debootstrap +hydra_sudo_run mkdir -p $WORK # Setup mountpoint and make sure it's not mounted due to a failed install. -if cat /proc/mounts | cut -d ' ' -f 2 | grep -q "^/tmp/debootstrap$"; then - hydra_sudo_run umount /tmp/debootstrap +if cat /proc/mounts | cut -d ' ' -f 2 | grep -q "^$WORK$"; then + hydra_sudo_run umount $WORK for folder in proc dev home var boot sys; do - if cat /proc/mounts | cut -d ' ' -f 2 | grep -q "^/tmp/debootstrap/$folder$"; then - hydra_sudo_run umount /tmp/debootstrap/$folder + if cat /proc/mounts | cut -d ' ' -f 2 | grep -q "^$WORK/$folder$"; then + hydra_sudo_run umount $WORK/$folder fi done fi @@ -253,120 +256,120 @@ if [ "$var_size" != "0" ]; then fi # Mount root volume. -hydra_sudo_run mount $install_device /tmp/debootstrap/ +hydra_sudo_run mount $install_device $WORK/ # Mount additional volumes. if [ "$home_size" != "0" ]; then - mkdir /tmp/debootstrap/home + mkdir $WORK/home if [ "$encrypt" == "y" ]; then - hydra_sudo_run mount /dev/mapper/provision-home /tmp/debootstrap/home + hydra_sudo_run mount /dev/mapper/provision-home $WORK/home else - hydra_sudo_run mount /dev/mapper/$vg-home /tmp/debootstrap/home + hydra_sudo_run mount /dev/mapper/$vg-home $WORK/home fi fi if [ "$var_size" != "0" ]; then - hydra_sudo_run mkdir /tmp/debootstrap/var + hydra_sudo_run mkdir $WORK/var if [ "$encrypt" == "y" ]; then - hydra_sudo_run mount /dev/mapper/provision-var /tmp/debootstrap/var + hydra_sudo_run mount /dev/mapper/provision-var $WORK/var else - hydra_sudo_run mount /dev/mapper/$vg-var /tmp/debootstrap/var + hydra_sudo_run mount /dev/mapper/$vg-var $WORK/var fi fi # Initial system install. echo "Installing base system..." -hydra_sudo_run debootstrap --arch=$arch $version /tmp/debootstrap/ $mirror +hydra_sudo_run debootstrap --arch=$arch $version $WORK/ $mirror # Initial configuration. echo "Applying initial configuration..." -hydra_sudo_run mount none -t proc /tmp/debootstrap/proc -hydra_sudo_run mount none -t sysfs /tmp/debootstrap/sys -hydra_sudo_run mount -o bind /dev/ /tmp/debootstrap/dev -echo LANG=C | $SUDO tee /tmp/debootstrap/etc/default/locale +hydra_sudo_run mount none -t proc $WORK/proc +hydra_sudo_run mount none -t sysfs $WORK/sys +hydra_sudo_run mount -o bind /dev/ $WORK/dev +echo LANG=C | $SUDO tee $WORK/etc/default/locale # Resolver configuration. -echo "domain $domain" | $SUDO tee /tmp/debootstrap/etc/resolv.conf -echo "search $hostname.$domain" | $SUDO tee -a /tmp/debootstrap/etc/resolv.conf -grep nameserver /etc/resolv.conf | $SUDO tee -a /tmp/debootstrap/etc/resolv.conf +echo "domain $domain" | $SUDO tee $WORK/etc/resolv.conf +echo "search $hostname.$domain" | $SUDO tee -a $WORK/etc/resolv.conf +grep nameserver /etc/resolv.conf | $SUDO tee -a $WORK/etc/resolv.conf # Hostname configuration. -echo $hostname.$domain | $SUDO tee /tmp/debootstrap/etc/hostname -echo "127.0.0.1 localhost" | $SUDO tee -a /tmp/debootstrap/etc/hosts -echo "127.0.0.1 $hostname $hostname.$domain" | $SUDO tee -a /tmp/debootstrap/etc/hosts +echo $hostname.$domain | $SUDO tee $WORK/etc/hostname +echo "127.0.0.1 localhost" | $SUDO tee -a $WORK/etc/hosts +echo "127.0.0.1 $hostname $hostname.$domain" | $SUDO tee -a $WORK/etc/hosts # Invert hostname contents to avoid http://projects.puppetlabs.com/issues/2533 -tac /tmp/debootstrap/etc/hosts | $SUDO tee /tmp/debootstrap/etc/hosts.new -hydra_sudo_run mv /tmp/debootstrap/etc/hosts.new /tmp/debootstrap/etc/hosts +tac $WORK/etc/hosts | $SUDO tee $WORK/etc/hosts.new +hydra_sudo_run mv $WORK/etc/hosts.new $WORK/etc/hosts # Initial upgrade. echo "Applying initial upgrades..." -hydra_sudo_run chroot /tmp/debootstrap/ apt-get update -hydra_sudo_run chroot /tmp/debootstrap/ apt-get upgrade -y -hydra_sudo_run chroot /tmp/debootstrap/ apt-get install locales cryptsetup lvm2 initramfs-tools -y +hydra_sudo_run chroot $WORK/ apt-get update +hydra_sudo_run chroot $WORK/ apt-get upgrade -y +hydra_sudo_run chroot $WORK/ apt-get install locales cryptsetup lvm2 initramfs-tools -y # Crypttab. echo "Configuring crypttab..." -echo "# <target name> <source device> <key file> <options>" > /tmp/debootstrap/etc/crypttab +echo "# <target name> <source device> <key file> <options>" > $WORK/etc/crypttab if [ "$encrypt" == "y" ]; then - cat <<-EOF | $SUDO tee /tmp/debootstrap/etc/crypttab + cat <<-EOF | $SUDO tee $WORK/etc/crypttab root /dev/mapper/$vg-root none luks EOF fi if [ "$home_size" != "0" ] && [ "$encrypt" == "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/crypttab + cat <<-EOF | $SUDO tee -a $WORK/etc/crypttab home /dev/mapper/$vg-home none luks EOF fi if [ "$var_size" != "0" ] && [ "$encrypt" == "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/crypttab + cat <<-EOF | $SUDO tee -a $WORK/etc/crypttab var /dev/mapper/$vg-var none luks EOF fi if [ "$swap_size" != "0" ] && [ "$random_swap" == "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/crypttab + cat <<-EOF | $SUDO tee -a $WORK/etc/crypttab swap /dev/mapper/$vg-swap /dev/random swap,cipher=aes-xts-plain64:sha256 EOF fi if [ "$swap_size" != "0" ] && [ "$random_swap" != "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/crypttab + cat <<-EOF | $SUDO tee -a $WORK/etc/crypttab swap /dev/mapper/$vg-swap none luks,swap EOF fi # Fstab. echo "Configuring fstab..." -echo "" | hydra_safe_run tee /tmp/debootstrap/etc/fstab +echo "" | $SUDO tee $WORK/etc/fstab if [ "$swap_size" != "0" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/swap none swap sw 0 0 EOF fi if [ "$encrypt" == "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/root / ext4 defaults,errors=remount-ro 0 1 EOF else - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/$vg-root / ext4 defaults,errors=remount-ro 0 1 EOF fi if [ "$home_size" != "0" ]; then if [ "$encrypt" == "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/home /home ext4 defaults,errors=remount-ro 0 2 EOF else - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/$vg-home /home ext4 defaults,errors=remount-ro 0 2 EOF fi @@ -374,11 +377,11 @@ fi if [ "$var_size" != "0" ]; then if [ "$encrypt" == "y" ]; then - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/var /var ext4 defaults,errors=remount-ro 0 2 EOF else - cat <<-EOF | $SUDO tee -a /tmp/debootstrap/etc/fstab + cat <<-EOF | $SUDO tee -a $WORK/etc/fstab /dev/mapper/$vg-var /var ext4 defaults,errors=remount-ro 0 2 EOF fi @@ -388,16 +391,16 @@ fi if [ "$grub" == "y" ]; then echo "Boot device setup..." hydra_sudo_run mkfs.ext4 $boot_device - hydra_sudo_run mount $boot_device /tmp/debootstrap/boot - echo "$reboot_device /boot ext4 defaults,errors=remount-ro 0 2" | hydra_safe_run tee -a /tmp/debootstrap/etc/fstab + hydra_sudo_run mount $boot_device $WORK/boot + echo "$reboot_device /boot ext4 defaults,errors=remount-ro 0 2" | $SUDO tee -a $WORK/etc/fstab echo "Setting up GRUB..." - hydra_sudo_run chroot /tmp/debootstrap/ apt-get install grub-pc -y + hydra_sudo_run chroot $WORK/ apt-get install grub-pc -y fi # Kernel. echo "Installing kernel..." -cat <<-EOF | $SUDO tee /tmp/debootstrap/etc/initramfs-tools/modules +cat <<-EOF | $SUDO tee $WORK/etc/initramfs-tools/modules dm-mod dm-crypt dm-raid @@ -406,7 +409,7 @@ twofish sha256 EOF -cat <<-EOF | $SUDO tee /tmp/debootstrap/etc/kernel-img.conf +cat <<-EOF | $SUDO tee $WORK/etc/kernel-img.conf do_initrd = Yes EOF @@ -417,33 +420,33 @@ else fi if [ "$version" == "squeeze" ]; then - hydra_sudo_run chroot /tmp/debootstrap apt-get install linux-image-2.6-vserver-$kernel_arch -y + hydra_sudo_run chroot $WORK apt-get install linux-image-2.6-vserver-$kernel_arch -y else - hydra_sudo_run chroot /tmp/debootstrap apt-get install linux-image-$kernel_arch -y + hydra_sudo_run chroot $WORK apt-get install linux-image-$kernel_arch -y fi # Initramfs. echo "Creating initramfs..." -hydra_sudo_run chroot /tmp/debootstrap update-initramfs -v -u +hydra_sudo_run chroot $WORK update-initramfs -v -u # Utils. echo "Installing basic utilities..." -hydra_sudo_run chroot /tmp/debootstrap apt-get install screen cron lsb-release openssl -y +hydra_sudo_run chroot $WORK apt-get install screen cron lsb-release openssl -y # Ssh. echo "Installing OpenSSH daemon..." -hydra_sudo_run chroot /tmp/debootstrap apt-get install openssh-server -y +hydra_sudo_run chroot $WORK apt-get install openssh-server -y echo "OpenSSH fingerprints:" -hydra_sudo_run chroot /tmp/debootstrap ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub -hydra_sudo_run chroot /tmp/debootstrap ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub +hydra_sudo_run chroot $WORK ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub +hydra_sudo_run chroot $WORK ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub # Accounts. echo "Installing sudo..." -hydra_sudo_run chroot /tmp/debootstrap apt-get install sudo -y +hydra_sudo_run chroot $WORK apt-get install sudo -y echo "Choose a root password." -hydra_sudo_run chroot /tmp/debootstrap passwd root +hydra_sudo_run chroot $WORK passwd root cat <<-EOF |