aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install_script_ovh_cloud_instance.sh182
-rwxr-xr-xbin/install_script_ovh_vps_ssd.sh (renamed from bin/install_script.sh)0
2 files changed, 182 insertions, 0 deletions
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh
new file mode 100755
index 0000000..26e410e
--- /dev/null
+++ b/bin/install_script_ovh_cloud_instance.sh
@@ -0,0 +1,182 @@
1#!/bin/bash
2
3usage() {
4cat <<EOF
5 $0 [options]
6 --help,-h This help
7 --instance-id id Id of the instance
8 --reinstall-first Start with reinstalling the vps
9 --host-user user Use another user (default: arch)
10 --no-reboot Don't reboot
11 --no-reboot-start Don't reboot to rescue at the beginning
12 --no-reboot-end Don't reboot to normal at the end
13 --git-branch Use another puppet branch (default: master)
14 --environment Environment to use for the installl (default: production)
15EOF
16}
17
18set -e
19
20host_user=arch
21git_branch=master
22environment=production
23
24while [ -n "$1" ]; do
25 case "$1" in
26 --instance-id)
27 instance_id="$2"
28 shift
29 ;;
30 --reinstall-first)
31 reinstall_first=1
32 ;;
33 --host-user)
34 host_user="$2"
35 shift
36 ;;
37 --no-reboot)
38 no_reboot=1
39 ;;
40 --no-reboot-start)
41 no_reboot_start=1
42 ;;
43 --no-reboot-end)
44 no_reboot_end=1
45 ;;
46 --git-branch)
47 git_branch="$2"
48 shift
49 ;;
50 --environment)
51 environment="$2"
52 shift
53 ;;
54 --help|-h)
55 usage
56 exit 0
57 ;;
58 esac
59
60 shift
61done
62
63DIRECTORY=$(cd `dirname $0` && pwd)
64PYTHON_DIRECTORY="$DIRECTORY/../python"
65
66if [ -z "$instance_id" ]; then
67 read -p "Id de l'instance : " instance_id
68fi
69
70if [ -n "$reinstall_first" ]; then
71 echo "Réinstallation du système"
72 python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
73
74 read -p "Appuyer sur une touche quand le serveur est prêt" ready
75fi
76
77if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
78 echo "Patienter le temps du reboot"
79 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
80
81 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
82fi
83
84ARCH_DIR=`mktemp -d`
85ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
86ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
87ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
88ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
89ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
90
91trap "rm -rf $ARCH_DIR" EXIT
92
93#### Base installation stage
94python $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')
96
97cat > $ARCH_HOST_SCRIPT <<EOF
98#!/bin/bash
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
127sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
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
152### Role specific stage
153read -p "Press key when LDAP is configured" i
154
155cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
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
163sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
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
178### Installation finished
179if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
180 echo "Rebooting"
181 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id"
182fi
diff --git a/bin/install_script.sh b/bin/install_script_ovh_vps_ssd.sh
index 6b1aa39..6b1aa39 100755
--- a/bin/install_script.sh
+++ b/bin/install_script_ovh_vps_ssd.sh