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)
62 DIRECTORY
=$(cd `dirname $0` && pwd)
63 PYTHON_DIRECTORY
="$DIRECTORY/../python"
65 if [ -z "$vps_name" ]; then
66 read -p "Nom du vps : " vps_name
69 if [ -n "$reinstall_first" ]; then
70 echo "Réinstallation du système"
71 python
$PYTHON_DIRECTORY/reinstall_vps_server.py
--use-current "$vps_name"
73 read -p "Appuyer sur une touche quand le serveur est prêt" ready
76 if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
77 echo "Patienter le temps du reboot"
78 python
$PYTHON_DIRECTORY/reboot_vps_server.py
--rescue "$vps_name"
81 if [ -z "$password" ]; then
83 read -p "Mot de passe reçu par e-mail : " password
; echo
88 ARCH_HOST_SCRIPT
="$ARCH_DIR/arch_host_script.sh"
89 ARCH_CHROOT_SCRIPT
="$ARCH_DIR/arch_chroot_script.sh"
90 ARCH_INSTALL_SCRIPT
="$ARCH_DIR/arch_install_script.sh"
91 ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
92 ARCH_PUPPET_CONFIGURATION_SCRIPT
="$ARCH_DIR/arch_puppet_configuration_script.sh"
93 ARCH_PUPPET_INITIAL_CONFIGURATION
="$ARCH_DIR/puppet_variables.json"
95 trap "rm -rf $ARCH_DIR" EXIT
97 #### Base installation stage
98 python
$PYTHON_DIRECTORY/get_initial_configuration.py
$vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
100 cat > $ARCH_HOST_SCRIPT <<EOF
104 apt-get install -y haveged
109 LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
110 SHA1=\$(echo "\$LATEST" | cut -d' ' -f1)
111 NAME=\$(echo "\$LATEST" | cut -d' ' -f3)
113 curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME"
117 echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
119 DEVICE_STR=\$(cat /proc/mounts | grep "/dev/sd.. /mnt/")
120 DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
121 MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
124 UUID=\$(lsblk -rno UUID "\$DEVICE")
126 echo "\$UUID" > /tmp/root.x86_64/device_uuid
128 cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
130 /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
134 cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
135 cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
137 /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
141 cat > $ARCH_CHROOT_SCRIPT <<EOF
145 pacman-key --populate archlinux
147 UUID=\$(cat /device_uuid)
148 PART="/dev/disk/by-uuid/\$UUID"
149 DEVICE=\$(realpath "\$PART")
151 # mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
152 mount "\$DEVICE" /mnt
154 ##### FIXME: mkfs.ext4 would be better ####
156 if [ "\$i" = "/mnt/boot" ]; then
165 pacstrap /mnt base git puppet
167 echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab
172 cat > $ARCH_INSTALL_SCRIPT <<EOF
173 CODE_PATH="/etc/puppetlabs/code"
175 git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
176 puppet apply --test \$CODE_PATH/manifests/site.pp
177 # The password seed requires puppet to be run twice
178 puppet apply --test \$CODE_PATH/manifests/site.pp
181 chmod a
+x
$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT
185 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
189 spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh
195 ### Role specific stage
196 read -p "Press key when LDAP is configured" i
198 cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
199 CODE_PATH="/etc/puppetlabs/code"
200 puppet apply --test \$CODE_PATH/manifests/site.pp
203 cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
204 DEVICE_STR=\$(cat /proc/mounts | grep "/dev/sd.. /mnt/")
205 DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
206 MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
208 cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
210 /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
213 chmod a
+x
$ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
217 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
221 spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh
227 ### Installation finished
228 if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
230 python
$PYTHON_DIRECTORY/reboot_vps_server.py
--local "$vps_name"