aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/install_script_ovh_cloud_instance.sh88
-rwxr-xr-xbin/install_script_ovh_vps_ssd.sh136
-rw-r--r--modules/base_installation/templates/puppet/host_ldap.info.erb5
-rwxr-xr-xscripts/arch_install_script.sh13
-rwxr-xr-xscripts/arch_puppet_configuration_script.sh8
-rwxr-xr-xscripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh11
-rwxr-xr-xscripts/ovh_cloud_instance/arch_host_script.sh50
-rwxr-xr-xscripts/ovh_vps_ssd/arch_chroot_script.sh29
-rwxr-xr-xscripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh13
-rwxr-xr-xscripts/ovh_vps_ssd/arch_host_script.sh53
-rwxr-xr-xscripts/send_and_run.tcl31
11 files changed, 232 insertions, 205 deletions
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh
index 26e410e..e1c8a54 100755
--- a/bin/install_script_ovh_cloud_instance.sh
+++ b/bin/install_script_ovh_cloud_instance.sh
@@ -62,6 +62,7 @@ done
62 62
63DIRECTORY=$(cd `dirname $0` && pwd) 63DIRECTORY=$(cd `dirname $0` && pwd)
64PYTHON_DIRECTORY="$DIRECTORY/../python" 64PYTHON_DIRECTORY="$DIRECTORY/../python"
65SCRIPTS="$DIRECTORY/../scripts"
65 66
66if [ -z "$instance_id" ]; then 67if [ -z "$instance_id" ]; then
67 read -p "Id de l'instance : " instance_id 68 read -p "Id de l'instance : " instance_id
@@ -82,10 +83,10 @@ if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
82fi 83fi
83 84
84ARCH_DIR=`mktemp -d` 85ARCH_DIR=`mktemp -d`
85ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" 86ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
86ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" 87ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
87ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" 88ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
88ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" 89ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
89ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" 90ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
90 91
91trap "rm -rf $ARCH_DIR" EXIT 92trap "rm -rf $ARCH_DIR" EXIT
@@ -94,86 +95,17 @@ trap "rm -rf $ARCH_DIR" EXIT
94python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION 95python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
95host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress') 96host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
96 97
97cat > $ARCH_HOST_SCRIPT <<EOF 98dest="$host_user@$host_address"
98#!/bin/bash 99files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
99
100sudo haveged &
101sudo pacman -Sy --noconfirm arch-install-scripts
102
103DEVICE=/dev/vdb1
104MOUNTPOINT=/mnt
105
106UUID=\$(lsblk -rno UUID "\$DEVICE")
107PART="/dev/disk/by-uuid/\$UUID"
108
109# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
110sudo mount "\$DEVICE" /mnt
111
112##### FIXME: mkfs.ext4 would be better ####
113for i in /mnt/*; do
114 if [ "\$i" = "/mnt/boot" ]; then
115 # keep /boot/grub
116 sudo rm -f \$i/*
117 else
118 sudo rm -rf \$i
119 fi
120done
121##### /FIXME ####
122
123sudo pacstrap /mnt base git puppet
124
125echo "\$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab
126 100
127sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" 101$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
128sudo cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
129
130sudo arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
131EOF
132
133cat > $ARCH_INSTALL_SCRIPT <<EOF
134CODE_PATH="/etc/puppetlabs/code"
135rm -rf \$CODE_PATH
136git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
137puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
138# The password seed requires puppet to be run twice
139puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
140EOF
141
142chmod a+x $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT
143
144expect -f - <<EOF
145set timeout -1
146spawn 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
147expect eof
148spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_script.sh
149expect eof
150EOF
151 102
152### Role specific stage 103### Role specific stage
153read -p "Press key when LDAP is configured" i 104read -p "Press key when LDAP is configured" i
154 105
155cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF 106files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
156CODE_PATH="/etc/puppetlabs/code"
157puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
158EOF
159
160cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
161MOUNTPOINT=/mnt
162 107
163sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/" 108$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
164
165sudo arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
166EOF
167
168chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
169
170expect -f - <<EOF
171set timeout -1
172spawn 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
173expect eof
174spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_puppet_configuration_script.sh
175expect eof
176EOF
177 109
178### Installation finished 110### Installation finished
179if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then 111if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
diff --git a/bin/install_script_ovh_vps_ssd.sh b/bin/install_script_ovh_vps_ssd.sh
index 6b1aa39..b5b0efb 100755
--- a/bin/install_script_ovh_vps_ssd.sh
+++ b/bin/install_script_ovh_vps_ssd.sh
@@ -67,6 +67,7 @@ done
67 67
68DIRECTORY=$(cd `dirname $0` && pwd) 68DIRECTORY=$(cd `dirname $0` && pwd)
69PYTHON_DIRECTORY="$DIRECTORY/../python" 69PYTHON_DIRECTORY="$DIRECTORY/../python"
70SCRIPTS="$DIRECTORY/../scripts"
70 71
71if [ -z "$vps_name" ]; then 72if [ -z "$vps_name" ]; then
72 read -p "Nom du vps : " vps_name 73 read -p "Nom du vps : " vps_name
@@ -91,11 +92,11 @@ if [ -z "$password" ]; then
91fi 92fi
92 93
93ARCH_DIR=`mktemp -d` 94ARCH_DIR=`mktemp -d`
94ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" 95ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh"
95ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh" 96ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh"
96ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" 97ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
97ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" 98ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh"
98ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" 99ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
99ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" 100ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
100 101
101trap "rm -rf $ARCH_DIR" EXIT 102trap "rm -rf $ARCH_DIR" EXIT
@@ -103,132 +104,17 @@ trap "rm -rf $ARCH_DIR" EXIT
103#### Base installation stage 104#### Base installation stage
104python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION 105python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
105 106
106cat > $ARCH_HOST_SCRIPT <<EOF 107dest="$host_user@$vps_name"
107#!/bin/bash 108files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
108
109apt-get update
110apt-get install -y haveged
111haveged &
112
113cd /tmp
114
115LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
116SHA1=\$(echo "\$LATEST" | cut -d' ' -f1)
117NAME=\$(echo "\$LATEST" | cut -d' ' -f3)
118
119curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME"
120
121tar -xzf "\$NAME"
122
123echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
124
125DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
126DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
127MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
128
129umount "\$DEVICE"
130UUID=\$(lsblk -rno UUID "\$DEVICE")
131
132echo "\$UUID" > /tmp/root.x86_64/device_uuid
133
134cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
135
136/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
137
138mount "\$DEVICE"
139
140cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
141cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
142
143/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
144EOF
145
146
147cat > $ARCH_CHROOT_SCRIPT <<EOF
148#!/bin/bash
149 109
150pacman-key --init 110$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
151pacman-key --populate archlinux
152
153UUID=\$(cat /device_uuid)
154PART="/dev/disk/by-uuid/\$UUID"
155DEVICE=\$(realpath "\$PART")
156
157# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
158mount "\$DEVICE" /mnt
159
160##### FIXME: mkfs.ext4 would be better ####
161for i in /mnt/*; do
162 if [ "\$i" = "/mnt/boot" ]; then
163 # keep /boot/grub
164 rm -f \$i/*
165 else
166 rm -rf \$i
167 fi
168done
169##### /FIXME ####
170
171pacstrap /mnt base git puppet
172
173echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab
174
175umount /mnt
176EOF
177
178cat > $ARCH_INSTALL_SCRIPT <<EOF
179CODE_PATH="/etc/puppetlabs/code"
180rm -rf \$CODE_PATH
181git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
182puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
183# The password seed requires puppet to be run twice
184puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
185EOF
186
187chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT
188
189expect -f - <<EOF
190set timeout -1
191spawn 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
192expect "assword:"
193send "$password\n"
194expect eof
195spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh
196expect "assword:"
197send "$password\r"
198expect eof
199EOF
200 111
201### Role specific stage 112### Role specific stage
202read -p "Press key when LDAP is configured" i 113read -p "Press key when LDAP is configured" i
203 114
204cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF 115files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
205CODE_PATH="/etc/puppetlabs/code"
206puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
207EOF
208
209cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
210DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
211DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
212MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
213 116
214cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/" 117$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
215
216/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
217EOF
218
219chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
220
221expect -f - <<EOF
222set timeout -1
223spawn 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
224expect "assword:"
225send "$password\n"
226expect eof
227spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh
228expect "assword:"
229send "$password\r"
230expect eof
231EOF
232 118
233### Installation finished 119### Installation finished
234if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then 120if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
diff --git a/modules/base_installation/templates/puppet/host_ldap.info.erb b/modules/base_installation/templates/puppet/host_ldap.info.erb
index a71c6f3..9c79d3c 100644
--- a/modules/base_installation/templates/puppet/host_ldap.info.erb
+++ b/modules/base_installation/templates/puppet/host_ldap.info.erb
@@ -1,4 +1,4 @@
1#### Please add this node to LDAP: 1#### Please add this node to LDAP:
2ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF' 2ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
3dn: <%= @ldap_dn %> 3dn: <%= @ldap_dn %>
4cn: <%= @ldap_cn %> 4cn: <%= @ldap_cn %>
@@ -14,12 +14,13 @@ objectclass: ipHost
14environment: <%= @environment %> 14environment: <%= @environment %>
15userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> 15userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %>
16EOF 16EOF
17#### Or modify an existing entry: 17#### Or modify an existing entry:
18ldapmodify -D "cn=root,<%= @ldap_base %>" -W << 'EOF' 18ldapmodify -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
19dn: <%= @ldap_dn %> 19dn: <%= @ldap_dn %>
20changetype: modify 20changetype: modify
21replace: userPassword 21replace: userPassword
22userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> 22userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %>
23-
23replace: environment 24replace: environment
24environment: <%= @environment %> 25environment: <%= @environment %>
25<%- unless @ips.empty? -%> 26<%- unless @ips.empty? -%>
diff --git a/scripts/arch_install_script.sh b/scripts/arch_install_script.sh
new file mode 100755
index 0000000..21e202f
--- /dev/null
+++ b/scripts/arch_install_script.sh
@@ -0,0 +1,13 @@
1#!/bin/bash
2
3git_branch="$1"
4environment="$2"
5CODE_PATH="/etc/puppetlabs/code"
6
7rm -rf $CODE_PATH
8
9git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git $CODE_PATH
10puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
11# The password seed requires puppet to be run twice
12puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
13
diff --git a/scripts/arch_puppet_configuration_script.sh b/scripts/arch_puppet_configuration_script.sh
new file mode 100755
index 0000000..caf8987
--- /dev/null
+++ b/scripts/arch_puppet_configuration_script.sh
@@ -0,0 +1,8 @@
1#!/bin/bash
2
3git_branch="$1"
4environment="$2"
5CODE_PATH="/etc/puppetlabs/code"
6
7puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
8
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
index 0000000..b58e255
--- /dev/null
+++ b/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh
@@ -0,0 +1,11 @@
1#!/bin/bash
2
3git_branch="$1"
4environment="$2"
5
6MOUNTPOINT=/mnt
7
8sudo cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/"
9
10sudo arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment"
11
diff --git a/scripts/ovh_cloud_instance/arch_host_script.sh b/scripts/ovh_cloud_instance/arch_host_script.sh
new file mode 100755
index 0000000..c188514
--- /dev/null
+++ b/scripts/ovh_cloud_instance/arch_host_script.sh
@@ -0,0 +1,50 @@
1#!/bin/bash
2
3set -e
4
5git_branch="$1"
6environment="$2"
7
8# Randomizer
9sudo haveged &
10# /Randomizer
11
12# Prepare an arch chroot
13sudo pacman -Sy --noconfirm arch-install-scripts
14# /Prepare an arch chroot
15
16# Prepare device information
17DEVICE=/dev/vdb1
18MOUNTPOINT=/mnt
19
20UUID=$(lsblk -rno UUID "$DEVICE")
21PART="/dev/disk/by-uuid/$UUID"
22# /Prepare device information
23
24# Install very basic system (base git puppet)
25# mkfs.ext4 -F -U "$UUID" "$DEVICE"
26sudo mount "$DEVICE" /mnt
27
28##### FIXME: mkfs.ext4 would be better ####
29for i in /mnt/*; do
30 if [ "$i" = "/mnt/boot" ]; then
31 # keep /boot/grub
32 sudo rm -f $i/*
33 else
34 sudo rm -rf $i
35 fi
36done
37##### /FIXME ####
38
39sudo pacstrap /mnt base git puppet
40
41echo "$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab
42# /Install very basic system
43
44# Install rest of system (via puppet)
45sudo cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/"
46sudo cp /tmp/puppet_variables.json "$MOUNTPOINT/root/"
47
48sudo arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment"
49# /Install rest of system
50
diff --git a/scripts/ovh_vps_ssd/arch_chroot_script.sh b/scripts/ovh_vps_ssd/arch_chroot_script.sh
new file mode 100755
index 0000000..9dc5c46
--- /dev/null
+++ b/scripts/ovh_vps_ssd/arch_chroot_script.sh
@@ -0,0 +1,29 @@
1#!/bin/bash
2
3pacman-key --init
4pacman-key --populate archlinux
5
6UUID=$(cat /device_uuid)
7PART="/dev/disk/by-uuid/$UUID"
8DEVICE=$(realpath "$PART")
9
10# mkfs.ext4 -F -U "$UUID" "$DEVICE"
11mount "$DEVICE" /mnt
12
13##### FIXME: mkfs.ext4 would be better ####
14for i in /mnt/*; do
15 if [ "$i" = "/mnt/boot" ]; then
16 # keep /boot/grub
17 rm -f $i/*
18 else
19 rm -rf $i
20 fi
21done
22##### /FIXME ####
23
24pacstrap /mnt base git puppet
25
26echo "$PART / auto defaults 0 1" > /mnt/etc/fstab
27
28umount /mnt
29
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
index 0000000..dab8fac
--- /dev/null
+++ b/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh
@@ -0,0 +1,13 @@
1#!/bin/bash
2
3git_branch="$1"
4environment="$2"
5
6DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
7DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1)
8MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2)
9
10cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/"
11
12/tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment"
13
diff --git a/scripts/ovh_vps_ssd/arch_host_script.sh b/scripts/ovh_vps_ssd/arch_host_script.sh
new file mode 100755
index 0000000..8eecae4
--- /dev/null
+++ b/scripts/ovh_vps_ssd/arch_host_script.sh
@@ -0,0 +1,53 @@
1#!/bin/bash
2
3set -e
4
5git_branch="$1"
6environment="$2"
7
8# Randomizer
9apt-get update
10apt-get install -y haveged
11haveged &
12# /Randomizer
13
14# Prepare an arch chroot
15cd /tmp
16
17LATEST=$(curl -L https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
18SHA1=$(echo "$LATEST" | cut -d' ' -f1)
19NAME=$(echo "$LATEST" | cut -d' ' -f3)
20
21curl -L -O "https://mirrors.kernel.org/archlinux/iso/latest/$NAME"
22
23tar -xzf "$NAME"
24
25echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/$repo/os/$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
26# /Prepare an arch chroot
27
28# Prepare device information (not available in chroot)
29DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
30DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1)
31MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2)
32
33umount "$DEVICE"
34UUID=$(lsblk -rno UUID "$DEVICE")
35
36echo "$UUID" > /tmp/root.x86_64/device_uuid
37# /Prepare device information
38
39# Install very basic system via chroot (base git puppet)
40cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
41
42/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
43# /Install very basic system via chroot
44
45# Mount and install rest of system (via puppet)
46mount "$DEVICE"
47
48cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/"
49cp /tmp/puppet_variables.json "$MOUNTPOINT/root/"
50
51/tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment"
52# /Mount and install rest of system
53
diff --git a/scripts/send_and_run.tcl b/scripts/send_and_run.tcl
new file mode 100755
index 0000000..a087a2d
--- /dev/null
+++ b/scripts/send_and_run.tcl
@@ -0,0 +1,31 @@
1#!/usr/bin/expect -f
2set dest [lindex $argv 0]
3set password [lindex $argv 1]
4set git_branch [lindex $argv 2]
5set environment [lindex $argv 3]
6set script [lindex $argv 4]
7set files [lrange $argv 4 end]
8
9if {$password == ""} {
10 set ask_password 0
11} else {
12 set ask_password 1
13}
14
15set scriptname [file tail $script]
16
17set sshopts [split "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no"]
18
19set timeout -1
20spawn scp {*}$sshopts {*}$files $dest:/tmp
21if {$ask_password} {
22 expect "assword:"
23 send "$password\n"
24}
25expect eof
26spawn ssh {*}$sshopts $dest /tmp/$scriptname $git_branch $environment
27if {$ask_password} {
28 expect "assword:"
29 send "$password\n"
30}
31expect eof