aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install_script.sh155
-rwxr-xr-xbin/install_script_ovh_cloud_instance.sh182
-rwxr-xr-xbin/install_script_ovh_vps_ssd.sh237
3 files changed, 155 insertions, 419 deletions
diff --git a/bin/install_script.sh b/bin/install_script.sh
new file mode 100755
index 0000000..bd7f38b
--- /dev/null
+++ b/bin/install_script.sh
@@ -0,0 +1,155 @@
1#!/bin/bash
2
3usage() {
4cat <<EOF
5$(basename $0) [options]
6 --help,-h This help
7
8 One of the following options is necessary:
9 --instance-id id Id of the cloud instance
10 --vps-id id Id of the vps
11
12 Optional arguments:
13 --password password Password of the host (only useful in case of no reboot and vps)
14 --reinstall-first Start with reinstalling the vps
15 --host-user user Use another user than the default one
16 --no-reboot Don't reboot
17 --no-reboot-start Don't reboot to rescue at the beginning
18 --no-reboot-end Don't reboot to normal at the end
19 --git-branch branch Use another puppet branch (default: master)
20 --environment env Environment to use for the install (default: production)
21EOF
22}
23
24set -e
25
26git_branch=master
27environment=production
28host_user=""
29password=""
30T=""
31
32while [ -n "$1" ]; do
33 case "$1" in
34 --instance-id)
35 host_id="$2"
36 if [ -z "$host_user" ]; then
37 host_user="arch"
38 fi
39 if [ -z "$password" ]; then
40 password="x"
41 fi
42 [ -n "$T" ] && usage && exit 1
43 T="ovh_cloud_instance"
44 shift
45 ;;
46 --vps-id)
47 host_id="$2"
48 if [ -z "$host_user" ]; then
49 host_user="root"
50 fi
51 [ -n "$T" ] && usage && exit 1
52 T="ovh_vps_ssd"
53 shift
54 ;;
55 --password)
56 password="$2"
57 shift
58 ;;
59 --reinstall-first)
60 reinstall_first=1
61 ;;
62 --host-user)
63 host_user="$2"
64 shift
65 ;;
66 --no-reboot)
67 no_reboot=1
68 ;;
69 --no-reboot-start)
70 no_reboot_start=1
71 ;;
72 --no-reboot-end)
73 no_reboot_end=1
74 ;;
75 --git-branch)
76 git_branch="$2"
77 shift
78 ;;
79 --environment)
80 environment="$2"
81 shift
82 ;;
83 --help|-h)
84 usage
85 exit 0
86 ;;
87 esac
88
89 shift
90done
91
92if [ -z "$T" -o -z "$host_id" ]; then
93 usage
94 exit 1
95fi
96
97DIRECTORY=$(cd `dirname $0` && pwd)
98PYTHON_DIRECTORY="$DIRECTORY/../python"
99SCRIPTS="$DIRECTORY/../scripts"
100
101if [ -n "$reinstall_first" ]; then
102 echo "Réinstallation du système"
103 python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id"
104
105 read -p "Appuyer sur une touche quand le serveur est prêt" ready
106fi
107
108if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
109 echo "Patienter le temps du reboot"
110 python $PYTHON_DIRECTORY/reboot_$T.py --rescue "$host_id"
111
112 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
113fi
114
115if [ -z "$password" ]; then
116 stty -echo
117 read -p "Mot de passe reçu par e-mail : " password; echo
118 stty echo
119fi
120
121ARCH_DIR=`mktemp -d`
122ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh"
123if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then
124 ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh"
125else
126 ARCH_CHROOT_SCRIPT=""
127fi
128ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
129ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh"
130ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
131ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
132
133trap "rm -rf $ARCH_DIR" EXIT
134
135#### Base installation stage
136python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
137host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress')
138
139dest="$host_user@$host_address"
140files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
141
142$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
143
144### Role specific stage
145read -p "Press key when LDAP is configured" i
146
147files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
148
149$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
150
151### Installation finished
152if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
153 echo "Rebooting"
154 python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id"
155fi
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh
deleted file mode 100755
index 26e410e..0000000
--- a/bin/install_script_ovh_cloud_instance.sh
+++ /dev/null
@@ -1,182 +0,0 @@
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_ovh_vps_ssd.sh b/bin/install_script_ovh_vps_ssd.sh
deleted file mode 100755
index 6b1aa39..0000000
--- a/bin/install_script_ovh_vps_ssd.sh
+++ /dev/null
@@ -1,237 +0,0 @@
1#!/bin/bash
2
3usage() {
4cat <<EOF
5 $0 [options]
6 --help,-h This help
7 --vps vps_name Name of the vps
8 --password password Password of the vps (only useful in case of no reboot)
9 --reinstall-first Start with reinstalling the vps
10 --host-user user Use another user (default: root)
11 --no-reboot Don't reboot
12 --no-reboot-start Don't reboot to rescue at the beginning
13 --no-reboot-end Don't reboot to normal at the end
14 --git-branch Use another puppet branch (default: master)
15 --environment Environment to use for the installl (default: production)
16EOF
17}
18
19set -e
20
21host_user=root
22git_branch=master
23environment=production
24
25while [ -n "$1" ]; do
26 case "$1" in
27 --vps)
28 vps_name="$2"
29 shift
30 ;;
31 --reinstall-first)
32 reinstall_first=1
33 ;;
34 --password)
35 password="$2"
36 shift
37 ;;
38 --host-user)
39 host_user="$2"
40 shift
41 ;;
42 --no-reboot)
43 no_reboot=1
44 ;;
45 --no-reboot-start)
46 no_reboot_start=1
47 ;;
48 --no-reboot-end)
49 no_reboot_end=1
50 ;;
51 --git-branch)
52 git_branch="$2"
53 shift
54 ;;
55 --environment)
56 environment="$2"
57 shift
58 ;;
59 --help|-h)
60 usage
61 exit 0
62 ;;
63 esac
64
65 shift
66done
67
68DIRECTORY=$(cd `dirname $0` && pwd)
69PYTHON_DIRECTORY="$DIRECTORY/../python"
70
71if [ -z "$vps_name" ]; then
72 read -p "Nom du vps : " vps_name
73fi
74
75if [ -n "$reinstall_first" ]; then
76 echo "Réinstallation du système"
77 python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name"
78
79 read -p "Appuyer sur une touche quand le serveur est prêt" ready
80fi
81
82if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
83 echo "Patienter le temps du reboot"
84 python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name"
85fi
86
87if [ -z "$password" ]; then
88 stty -echo
89 read -p "Mot de passe reçu par e-mail : " password; echo
90 stty echo
91fi
92
93ARCH_DIR=`mktemp -d`
94ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
95ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh"
96ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
97ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
98ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
99ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
100
101trap "rm -rf $ARCH_DIR" EXIT
102
103#### Base installation stage
104python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
105
106cat > $ARCH_HOST_SCRIPT <<EOF
107#!/bin/bash
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
150pacman-key --init
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
201### Role specific stage
202read -p "Press key when LDAP is configured" i
203
204cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
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
214cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
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
233### Installation finished
234if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
235 echo "Rebooting"
236 python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name"
237fi