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)
23 environment
=production
68 DIRECTORY
=$(cd `dirname $0` && pwd)
69 PYTHON_DIRECTORY
="$DIRECTORY/../python"
71 if [ -z "$vps_name" ]; then
72 read -p "Nom du vps : " vps_name
75 if [ -n "$reinstall_first" ]; then
76 echo "Réinstallation du système"
77 python
$PYTHON_DIRECTORY/reinstall_vps_server.py
--use-current "$vps_name"
79 read -p "Appuyer sur une touche quand le serveur est prêt" ready
82 if [ -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"
87 if [ -z "$password" ]; then
89 read -p "Mot de passe reçu par e-mail : " password
; echo
94 ARCH_HOST_SCRIPT
="$ARCH_DIR/arch_host_script.sh"
95 ARCH_CHROOT_SCRIPT
="$ARCH_DIR/arch_chroot_script.sh"
96 ARCH_INSTALL_SCRIPT
="$ARCH_DIR/arch_install_script.sh"
97 ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
98 ARCH_PUPPET_CONFIGURATION_SCRIPT
="$ARCH_DIR/arch_puppet_configuration_script.sh"
99 ARCH_PUPPET_INITIAL_CONFIGURATION
="$ARCH_DIR/puppet_variables.json"
101 trap "rm -rf $ARCH_DIR" EXIT
103 #### Base installation stage
104 python
$PYTHON_DIRECTORY/get_initial_configuration.py
$vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
106 cat > $ARCH_HOST_SCRIPT <<EOF
110 apt-get install -y haveged
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)
119 curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME"
123 echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
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)
130 UUID=\$(lsblk -rno UUID "\$DEVICE")
132 echo "\$UUID" > /tmp/root.x86_64/device_uuid
134 cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
136 /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
140 cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
141 cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
143 /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
147 cat > $ARCH_CHROOT_SCRIPT <<EOF
151 pacman-key --populate archlinux
153 UUID=\$(cat /device_uuid)
154 PART="/dev/disk/by-uuid/\$UUID"
155 DEVICE=\$(realpath "\$PART")
157 # mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
158 mount "\$DEVICE" /mnt
160 ##### FIXME: mkfs.ext4 would be better ####
162 if [ "\$i" = "/mnt/boot" ]; then
171 pacstrap /mnt base git puppet
173 echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab
178 cat > $ARCH_INSTALL_SCRIPT <<EOF
179 CODE_PATH="/etc/puppetlabs/code"
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
187 chmod a
+x
$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT
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
195 spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh
201 ### Role specific stage
202 read -p "Press key when LDAP is configured" i
204 cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
205 CODE_PATH="/etc/puppetlabs/code"
206 puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
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)
214 cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
216 /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
219 chmod a
+x
$ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
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
227 spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh
233 ### Installation finished
234 if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
236 python
$PYTHON_DIRECTORY/reboot_vps_server.py
--local "$vps_name"