aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-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
8 files changed, 208 insertions, 0 deletions
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