]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Move scripts to separate chunks
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 15 Mar 2018 23:22:38 +0000 (00:22 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 16 Mar 2018 17:08:12 +0000 (18:08 +0100)
bin/install_script_ovh_cloud_instance.sh
bin/install_script_ovh_vps_ssd.sh
modules/base_installation/templates/puppet/host_ldap.info.erb
scripts/arch_install_script.sh [new file with mode: 0755]
scripts/arch_puppet_configuration_script.sh [new file with mode: 0755]
scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh [new file with mode: 0755]
scripts/ovh_cloud_instance/arch_host_script.sh [new file with mode: 0755]
scripts/ovh_vps_ssd/arch_chroot_script.sh [new file with mode: 0755]
scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh [new file with mode: 0755]
scripts/ovh_vps_ssd/arch_host_script.sh [new file with mode: 0755]
scripts/send_and_run.tcl [new file with mode: 0755]

index 26e410e214d921dcf1be7bdf679533172ecf22d3..e1c8a5418f9aee3a5c063f846b723706e179f5f0 100755 (executable)
@@ -62,6 +62,7 @@ done
 
 DIRECTORY=$(cd `dirname $0` && pwd)
 PYTHON_DIRECTORY="$DIRECTORY/../python"
+SCRIPTS="$DIRECTORY/../scripts"
 
 if [ -z "$instance_id" ]; then
   read -p "Id de l'instance : " instance_id
@@ -82,10 +83,10 @@ if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
 fi
 
 ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
-ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
-ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
+ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
+ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
+ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
+ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
 ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
 
 trap "rm -rf $ARCH_DIR" EXIT
@@ -94,86 +95,17 @@ trap "rm -rf $ARCH_DIR" EXIT
 python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
 host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
 
-cat > $ARCH_HOST_SCRIPT <<EOF
-#!/bin/bash
-
-sudo haveged &
-sudo pacman -Sy --noconfirm arch-install-scripts
-
-DEVICE=/dev/vdb1
-MOUNTPOINT=/mnt
-
-UUID=\$(lsblk -rno UUID "\$DEVICE")
-PART="/dev/disk/by-uuid/\$UUID"
-
-# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
-sudo mount "\$DEVICE" /mnt
-
-##### FIXME: mkfs.ext4 would be better ####
-for i in /mnt/*; do
-  if [ "\$i" = "/mnt/boot" ]; then
-    # keep /boot/grub
-    sudo rm -f \$i/*
-  else
-    sudo rm -rf \$i
-  fi
-done
-##### /FIXME ####
-
-sudo pacstrap /mnt base git puppet
-
-echo "\$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab
+dest="$host_user@$host_address"
+files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
 
-sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
-sudo cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
-
-sudo arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
-EOF
-
-cat > $ARCH_INSTALL_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-rm -rf \$CODE_PATH
-git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-# The password seed requires puppet to be run twice
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-chmod a+x $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT $host_user@$host_address:/tmp
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_script.sh
-expect eof
-EOF
+$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
 
 ### Role specific stage
 read -p "Press key when LDAP is configured" i
 
-cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
-MOUNTPOINT=/mnt
+files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
 
-sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
-
-sudo arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
-EOF
-
-chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $host_user@$host_address:/tmp
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_puppet_configuration_script.sh
-expect eof
-EOF
+$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
 
 ### Installation finished
 if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
index 6b1aa39cc2d9a0153f666894f75df17155a41603..b5b0efbbc9978b34dca092155e10a55e5ed0b1b4 100755 (executable)
@@ -67,6 +67,7 @@ done
 
 DIRECTORY=$(cd `dirname $0` && pwd)
 PYTHON_DIRECTORY="$DIRECTORY/../python"
+SCRIPTS="$DIRECTORY/../scripts"
 
 if [ -z "$vps_name" ]; then
   read -p "Nom du vps : " vps_name
@@ -91,11 +92,11 @@ if [ -z "$password" ]; then
 fi
 
 ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
-ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh"
-ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
-ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
+ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh"
+ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh"
+ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
+ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh"
+ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
 ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
 
 trap "rm -rf $ARCH_DIR" EXIT
@@ -103,132 +104,17 @@ trap "rm -rf $ARCH_DIR" EXIT
 #### Base installation stage
 python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
 
-cat > $ARCH_HOST_SCRIPT <<EOF
-#!/bin/bash
-
-apt-get update
-apt-get install -y haveged
-haveged &
-
-cd /tmp
-
-LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
-SHA1=\$(echo "\$LATEST" | cut -d' ' -f1)
-NAME=\$(echo "\$LATEST" | cut -d' ' -f3)
-
-curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME"
-
-tar -xzf "\$NAME"
-
-echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
-
-DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
-DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
-MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
-
-umount "\$DEVICE"
-UUID=\$(lsblk -rno UUID "\$DEVICE")
-
-echo "\$UUID" > /tmp/root.x86_64/device_uuid
-
-cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
-
-/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
-
-mount "\$DEVICE"
-
-cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
-cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
-
-/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
-EOF
-
-
-cat > $ARCH_CHROOT_SCRIPT <<EOF
-#!/bin/bash
+dest="$host_user@$vps_name"
+files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
 
-pacman-key --init
-pacman-key --populate archlinux
-
-UUID=\$(cat /device_uuid)
-PART="/dev/disk/by-uuid/\$UUID"
-DEVICE=\$(realpath "\$PART")
-
-# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
-mount "\$DEVICE" /mnt
-
-##### FIXME: mkfs.ext4 would be better ####
-for i in /mnt/*; do
-  if [ "\$i" = "/mnt/boot" ]; then
-    # keep /boot/grub
-    rm -f \$i/*
-  else
-    rm -rf \$i
-  fi
-done
-##### /FIXME ####
-
-pacstrap /mnt base git puppet
-
-echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab
-
-umount /mnt
-EOF
-
-cat > $ARCH_INSTALL_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-rm -rf \$CODE_PATH
-git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-# The password seed requires puppet to be run twice
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT $host_user@$vps_name:/tmp
-expect "assword:"
-send "$password\n"
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh
-expect "assword:"
-send "$password\r"
-expect eof
-EOF
+$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
 
 ### Role specific stage
 read -p "Press key when LDAP is configured" i
 
-cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
-DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
-DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
-MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
+files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
 
-cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
-
-/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
-EOF
-
-chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $host_user@$vps_name:/tmp
-expect "assword:"
-send "$password\n"
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh
-expect "assword:"
-send "$password\r"
-expect eof
-EOF
+$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
 
 ### Installation finished
 if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
index a71c6f361de36d1ee752b262c52d8d34c25b914b..9c79d3c8480bd6675c91d74bd495e3a08f64ac8e 100644 (file)
@@ -1,4 +1,4 @@
-#### Please add this node to LDAP:
+\e[0;35m#### Please add this node to LDAP:\e[0m
 ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
 dn: <%= @ldap_dn %>
 cn: <%= @ldap_cn %>
@@ -14,12 +14,13 @@ objectclass: ipHost
 environment: <%= @environment %>
 userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %>
 EOF
-#### Or modify an existing entry:
+\e[0;35m#### Or modify an existing entry:\e[0m
 ldapmodify -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
 dn: <%= @ldap_dn %>
 changetype: modify
 replace: userPassword
 userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %>
+-
 replace: environment
 environment: <%= @environment %>
 <%- unless @ips.empty? -%>
diff --git a/scripts/arch_install_script.sh b/scripts/arch_install_script.sh
new file mode 100755 (executable)
index 0000000..21e202f
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+CODE_PATH="/etc/puppetlabs/code"
+
+rm -rf $CODE_PATH
+
+git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git $CODE_PATH
+puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
+# The password seed requires puppet to be run twice
+puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
+
diff --git a/scripts/arch_puppet_configuration_script.sh b/scripts/arch_puppet_configuration_script.sh
new file mode 100755 (executable)
index 0000000..caf8987
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+CODE_PATH="/etc/puppetlabs/code"
+
+puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
+
diff --git a/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh b/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh
new file mode 100755 (executable)
index 0000000..b58e255
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+
+MOUNTPOINT=/mnt
+
+sudo cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/"
+
+sudo arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment"
+
diff --git a/scripts/ovh_cloud_instance/arch_host_script.sh b/scripts/ovh_cloud_instance/arch_host_script.sh
new file mode 100755 (executable)
index 0000000..c188514
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+set -e
+
+git_branch="$1"
+environment="$2"
+
+# Randomizer
+sudo haveged &
+# /Randomizer
+
+# Prepare an arch chroot
+sudo pacman -Sy --noconfirm arch-install-scripts
+# /Prepare an arch chroot
+
+# Prepare device information
+DEVICE=/dev/vdb1
+MOUNTPOINT=/mnt
+
+UUID=$(lsblk -rno UUID "$DEVICE")
+PART="/dev/disk/by-uuid/$UUID"
+# /Prepare device information
+
+# Install very basic system (base git puppet)
+# mkfs.ext4 -F -U "$UUID" "$DEVICE"
+sudo mount "$DEVICE" /mnt
+
+##### FIXME: mkfs.ext4 would be better ####
+for i in /mnt/*; do
+  if [ "$i" = "/mnt/boot" ]; then
+    # keep /boot/grub
+    sudo rm -f $i/*
+  else
+    sudo rm -rf $i
+  fi
+done
+##### /FIXME ####
+
+sudo pacstrap /mnt base git puppet
+
+echo "$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab
+# /Install very basic system
+
+# Install rest of system (via puppet)
+sudo cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/"
+sudo cp /tmp/puppet_variables.json "$MOUNTPOINT/root/"
+
+sudo arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment"
+# /Install rest of system
+
diff --git a/scripts/ovh_vps_ssd/arch_chroot_script.sh b/scripts/ovh_vps_ssd/arch_chroot_script.sh
new file mode 100755 (executable)
index 0000000..9dc5c46
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+pacman-key --init
+pacman-key --populate archlinux
+
+UUID=$(cat /device_uuid)
+PART="/dev/disk/by-uuid/$UUID"
+DEVICE=$(realpath "$PART")
+
+# mkfs.ext4 -F -U "$UUID" "$DEVICE"
+mount "$DEVICE" /mnt
+
+##### FIXME: mkfs.ext4 would be better ####
+for i in /mnt/*; do
+  if [ "$i" = "/mnt/boot" ]; then
+    # keep /boot/grub
+    rm -f $i/*
+  else
+    rm -rf $i
+  fi
+done
+##### /FIXME ####
+
+pacstrap /mnt base git puppet
+
+echo "$PART / auto defaults 0 1" > /mnt/etc/fstab
+
+umount /mnt
+
diff --git a/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh b/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh
new file mode 100755 (executable)
index 0000000..dab8fac
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+
+DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
+DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1)
+MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2)
+
+cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/"
+
+/tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment"
+
diff --git a/scripts/ovh_vps_ssd/arch_host_script.sh b/scripts/ovh_vps_ssd/arch_host_script.sh
new file mode 100755 (executable)
index 0000000..8eecae4
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+set -e
+
+git_branch="$1"
+environment="$2"
+
+# Randomizer
+apt-get update
+apt-get install -y haveged
+haveged &
+# /Randomizer
+
+# Prepare an arch chroot
+cd /tmp
+
+LATEST=$(curl -L https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
+SHA1=$(echo "$LATEST" | cut -d' ' -f1)
+NAME=$(echo "$LATEST" | cut -d' ' -f3)
+
+curl -L -O "https://mirrors.kernel.org/archlinux/iso/latest/$NAME"
+
+tar -xzf "$NAME"
+
+echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/$repo/os/$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
+# /Prepare an arch chroot
+
+# Prepare device information (not available in chroot)
+DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
+DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1)
+MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2)
+
+umount "$DEVICE"
+UUID=$(lsblk -rno UUID "$DEVICE")
+
+echo "$UUID" > /tmp/root.x86_64/device_uuid
+# /Prepare device information
+
+# Install very basic system via chroot (base git puppet)
+cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
+
+/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
+# /Install very basic system via chroot
+
+# Mount and install rest of system (via puppet)
+mount "$DEVICE"
+
+cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/"
+cp /tmp/puppet_variables.json "$MOUNTPOINT/root/"
+
+/tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment"
+# /Mount and install rest of system
+
diff --git a/scripts/send_and_run.tcl b/scripts/send_and_run.tcl
new file mode 100755 (executable)
index 0000000..a087a2d
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/expect -f
+set dest [lindex $argv 0]
+set password [lindex $argv 1]
+set git_branch [lindex $argv 2]
+set environment [lindex $argv 3]
+set script [lindex $argv 4]
+set files [lrange $argv 4 end]
+
+if {$password == ""} {
+  set ask_password 0
+} else {
+  set ask_password 1
+}
+
+set scriptname [file tail $script]
+
+set sshopts [split "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no"]
+
+set timeout -1
+spawn scp {*}$sshopts {*}$files $dest:/tmp
+if {$ask_password} {
+  expect "assword:"
+  send "$password\n"
+}
+expect eof
+spawn ssh {*}$sshopts $dest /tmp/$scriptname $git_branch $environment
+if {$ask_password} {
+  expect "assword:"
+  send "$password\n"
+}
+expect eof