diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/install_script_ovh_cloud_instance.sh | 88 | ||||
-rwxr-xr-x | bin/install_script_ovh_vps_ssd.sh | 136 |
2 files changed, 21 insertions, 203 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 | ||
63 | DIRECTORY=$(cd `dirname $0` && pwd) | 63 | DIRECTORY=$(cd `dirname $0` && pwd) |
64 | PYTHON_DIRECTORY="$DIRECTORY/../python" | 64 | PYTHON_DIRECTORY="$DIRECTORY/../python" |
65 | SCRIPTS="$DIRECTORY/../scripts" | ||
65 | 66 | ||
66 | if [ -z "$instance_id" ]; then | 67 | if [ -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 | |||
82 | fi | 83 | fi |
83 | 84 | ||
84 | ARCH_DIR=`mktemp -d` | 85 | ARCH_DIR=`mktemp -d` |
85 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" | 86 | ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh" |
86 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" | 87 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" |
87 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" | 88 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh" |
88 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" | 89 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" |
89 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | 90 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" |
90 | 91 | ||
91 | trap "rm -rf $ARCH_DIR" EXIT | 92 | trap "rm -rf $ARCH_DIR" EXIT |
@@ -94,86 +95,17 @@ trap "rm -rf $ARCH_DIR" EXIT | |||
94 | python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION | 95 | python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION |
95 | host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress') | 96 | host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress') |
96 | 97 | ||
97 | cat > $ARCH_HOST_SCRIPT <<EOF | 98 | dest="$host_user@$host_address" |
98 | #!/bin/bash | 99 | files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" |
99 | |||
100 | sudo haveged & | ||
101 | sudo pacman -Sy --noconfirm arch-install-scripts | ||
102 | |||
103 | DEVICE=/dev/vdb1 | ||
104 | MOUNTPOINT=/mnt | ||
105 | |||
106 | UUID=\$(lsblk -rno UUID "\$DEVICE") | ||
107 | PART="/dev/disk/by-uuid/\$UUID" | ||
108 | |||
109 | # mkfs.ext4 -F -U "\$UUID" "\$DEVICE" | ||
110 | sudo mount "\$DEVICE" /mnt | ||
111 | |||
112 | ##### FIXME: mkfs.ext4 would be better #### | ||
113 | for 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 | ||
120 | done | ||
121 | ##### /FIXME #### | ||
122 | |||
123 | sudo pacstrap /mnt base git puppet | ||
124 | |||
125 | echo "\$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab | ||
126 | 100 | ||
127 | sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" | 101 | $SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files |
128 | sudo cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/" | ||
129 | |||
130 | sudo arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh | ||
131 | EOF | ||
132 | |||
133 | cat > $ARCH_INSTALL_SCRIPT <<EOF | ||
134 | CODE_PATH="/etc/puppetlabs/code" | ||
135 | rm -rf \$CODE_PATH | ||
136 | git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH | ||
137 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
138 | # The password seed requires puppet to be run twice | ||
139 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
140 | EOF | ||
141 | |||
142 | chmod a+x $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT | ||
143 | |||
144 | expect -f - <<EOF | ||
145 | set timeout -1 | ||
146 | spawn 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 | ||
147 | expect eof | ||
148 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_script.sh | ||
149 | expect eof | ||
150 | EOF | ||
151 | 102 | ||
152 | ### Role specific stage | 103 | ### Role specific stage |
153 | read -p "Press key when LDAP is configured" i | 104 | read -p "Press key when LDAP is configured" i |
154 | 105 | ||
155 | cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF | 106 | files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" |
156 | CODE_PATH="/etc/puppetlabs/code" | ||
157 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
158 | EOF | ||
159 | |||
160 | cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF | ||
161 | MOUNTPOINT=/mnt | ||
162 | 107 | ||
163 | sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/" | 108 | $SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files |
164 | |||
165 | sudo arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh | ||
166 | EOF | ||
167 | |||
168 | chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT | ||
169 | |||
170 | expect -f - <<EOF | ||
171 | set timeout -1 | ||
172 | spawn 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 | ||
173 | expect eof | ||
174 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_puppet_configuration_script.sh | ||
175 | expect eof | ||
176 | EOF | ||
177 | 109 | ||
178 | ### Installation finished | 110 | ### Installation finished |
179 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | 111 | if [ -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 | ||
68 | DIRECTORY=$(cd `dirname $0` && pwd) | 68 | DIRECTORY=$(cd `dirname $0` && pwd) |
69 | PYTHON_DIRECTORY="$DIRECTORY/../python" | 69 | PYTHON_DIRECTORY="$DIRECTORY/../python" |
70 | SCRIPTS="$DIRECTORY/../scripts" | ||
70 | 71 | ||
71 | if [ -z "$vps_name" ]; then | 72 | if [ -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 | |||
91 | fi | 92 | fi |
92 | 93 | ||
93 | ARCH_DIR=`mktemp -d` | 94 | ARCH_DIR=`mktemp -d` |
94 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" | 95 | ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh" |
95 | ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh" | 96 | ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh" |
96 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" | 97 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" |
97 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" | 98 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh" |
98 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" | 99 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" |
99 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | 100 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" |
100 | 101 | ||
101 | trap "rm -rf $ARCH_DIR" EXIT | 102 | trap "rm -rf $ARCH_DIR" EXIT |
@@ -103,132 +104,17 @@ trap "rm -rf $ARCH_DIR" EXIT | |||
103 | #### Base installation stage | 104 | #### Base installation stage |
104 | python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION | 105 | python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION |
105 | 106 | ||
106 | cat > $ARCH_HOST_SCRIPT <<EOF | 107 | dest="$host_user@$vps_name" |
107 | #!/bin/bash | 108 | files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" |
108 | |||
109 | apt-get update | ||
110 | apt-get install -y haveged | ||
111 | haveged & | ||
112 | |||
113 | cd /tmp | ||
114 | |||
115 | LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1) | ||
116 | SHA1=\$(echo "\$LATEST" | cut -d' ' -f1) | ||
117 | NAME=\$(echo "\$LATEST" | cut -d' ' -f3) | ||
118 | |||
119 | curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME" | ||
120 | |||
121 | tar -xzf "\$NAME" | ||
122 | |||
123 | echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist | ||
124 | |||
125 | DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/") | ||
126 | DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1) | ||
127 | MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2) | ||
128 | |||
129 | umount "\$DEVICE" | ||
130 | UUID=\$(lsblk -rno UUID "\$DEVICE") | ||
131 | |||
132 | echo "\$UUID" > /tmp/root.x86_64/device_uuid | ||
133 | |||
134 | cp /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 | |||
138 | mount "\$DEVICE" | ||
139 | |||
140 | cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" | ||
141 | cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/" | ||
142 | |||
143 | /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh | ||
144 | EOF | ||
145 | |||
146 | |||
147 | cat > $ARCH_CHROOT_SCRIPT <<EOF | ||
148 | #!/bin/bash | ||
149 | 109 | ||
150 | pacman-key --init | 110 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files |
151 | pacman-key --populate archlinux | ||
152 | |||
153 | UUID=\$(cat /device_uuid) | ||
154 | PART="/dev/disk/by-uuid/\$UUID" | ||
155 | DEVICE=\$(realpath "\$PART") | ||
156 | |||
157 | # mkfs.ext4 -F -U "\$UUID" "\$DEVICE" | ||
158 | mount "\$DEVICE" /mnt | ||
159 | |||
160 | ##### FIXME: mkfs.ext4 would be better #### | ||
161 | for 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 | ||
168 | done | ||
169 | ##### /FIXME #### | ||
170 | |||
171 | pacstrap /mnt base git puppet | ||
172 | |||
173 | echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab | ||
174 | |||
175 | umount /mnt | ||
176 | EOF | ||
177 | |||
178 | cat > $ARCH_INSTALL_SCRIPT <<EOF | ||
179 | CODE_PATH="/etc/puppetlabs/code" | ||
180 | rm -rf \$CODE_PATH | ||
181 | git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH | ||
182 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
183 | # The password seed requires puppet to be run twice | ||
184 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
185 | EOF | ||
186 | |||
187 | chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT | ||
188 | |||
189 | expect -f - <<EOF | ||
190 | set timeout -1 | ||
191 | spawn 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 | ||
192 | expect "assword:" | ||
193 | send "$password\n" | ||
194 | expect eof | ||
195 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh | ||
196 | expect "assword:" | ||
197 | send "$password\r" | ||
198 | expect eof | ||
199 | EOF | ||
200 | 111 | ||
201 | ### Role specific stage | 112 | ### Role specific stage |
202 | read -p "Press key when LDAP is configured" i | 113 | read -p "Press key when LDAP is configured" i |
203 | 114 | ||
204 | cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF | 115 | files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" |
205 | CODE_PATH="/etc/puppetlabs/code" | ||
206 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
207 | EOF | ||
208 | |||
209 | cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF | ||
210 | DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/") | ||
211 | DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1) | ||
212 | MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2) | ||
213 | 116 | ||
214 | cp /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 | ||
217 | EOF | ||
218 | |||
219 | chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT | ||
220 | |||
221 | expect -f - <<EOF | ||
222 | set timeout -1 | ||
223 | spawn 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 | ||
224 | expect "assword:" | ||
225 | send "$password\n" | ||
226 | expect eof | ||
227 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh | ||
228 | expect "assword:" | ||
229 | send "$password\r" | ||
230 | expect eof | ||
231 | EOF | ||
232 | 118 | ||
233 | ### Installation finished | 119 | ### Installation finished |
234 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | 120 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then |