aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-01 00:22:47 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-01 00:42:25 +0200
commitec1096d8c0d897ebd1ea445d9c5404a13c33ce2e (patch)
tree2f81f476207059287c991e19d390f89e4bb5c5ab /bin
parent548061112d2e2627317f9379d2f501fcf3f6ea54 (diff)
downloadPuppet-ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e.tar.gz
Puppet-ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e.tar.zst
Puppet-ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e.zip
Add install scripts
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install_script.sh124
1 files changed, 124 insertions, 0 deletions
diff --git a/bin/install_script.sh b/bin/install_script.sh
new file mode 100755
index 0000000..f250285
--- /dev/null
+++ b/bin/install_script.sh
@@ -0,0 +1,124 @@
1#!/bin/bash
2
3DIRECTORY=$(cd `dirname $0` && pwd)
4PYTHON_DIRECTORY="$DIRECTORY/../python"
5
6if [ -n "$1" ]; then
7 vps_name="$1"
8else
9 read -p "Nom du vps : " vps_name
10fi
11
12echo "Patienter le temps du reboot"
13python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name"
14
15stty -echo
16read -p "Mot de passe reçu par e-mail : " password; echo
17stty echo
18
19ARCH_DIR=`mktemp -d`
20ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
21ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh"
22ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
23
24trap "rm -rf $ARCH_DIR" EXIT
25
26cat > $ARCH_HOST_SCRIPT <<EOF
27#!/bin/bash
28
29apt-get update
30apt-get install -y haveged
31haveged &
32
33cd /tmp
34
35LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
36SHA1=\$(echo "\$LATEST" | cut -d' ' -f1)
37NAME=\$(echo "\$LATEST" | cut -d' ' -f3)
38
39curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME"
40
41tar -xzf "\$NAME"
42
43echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
44
45DEVICE_STR=\$(cat /proc/mounts | grep "/dev/sd.. /mnt/")
46DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
47MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
48
49umount "\$DEVICE"
50UUID=\$(lsblk -rno UUID "\$DEVICE")
51
52echo "\$UUID" > /tmp/root.x86_64/device_uuid
53
54cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
55
56/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
57
58mount "\$DEVICE"
59
60cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
61
62/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
63EOF
64
65
66cat > $ARCH_CHROOT_SCRIPT <<EOF
67#!/bin/bash
68
69pacman-key --init
70pacman-key --populate archlinux
71
72UUID=\$(cat /device_uuid)
73PART="/dev/disk/by-uuid/\$UUID"
74DEVICE=\$(realpath "\$PART")
75
76# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
77mount "\$DEVICE" /mnt
78
79##### FIXME: mkfs.ext4 would be better ####
80for i in /mnt/*; do
81 if [ "\$i" = "/mnt/boot" ]; then
82 # keep /boot/grub
83 rm -f \$i/*
84 else
85 rm -rf \$i
86 fi
87done
88##### /FIXME ####
89
90pacstrap /mnt base git puppet
91
92echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab
93
94umount /mnt
95EOF
96
97cat > $ARCH_INSTALL_SCRIPT <<EOF
98CODE_PATH="/etc/puppetlabs/code"
99rm -rf \$CODE_PATH
100git clone -b master --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
101puppet apply --test \$CODE_PATH/manifests/site.pp
102# The password seed requires puppet to be run twice
103puppet apply --test \$CODE_PATH/manifests/site.pp
104EOF
105
106chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT
107
108expect -f - <<EOF
109set timeout -1
110spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT root@$vps_name:/tmp
111expect "assword:"
112send "$password\n"
113expect eof
114spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no root@$vps_name /tmp/arch_host_script.sh
115expect "assword:"
116send "$password\r"
117expect eof
118EOF
119
120read -p "Reboot to normal? [Y/n]" reboot
121if [ "x$reboot" != "xn" ]; then
122 echo "Rebooting"
123 python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name"
124fi