]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - bin/install_script_ovh_cloud_instance.sh
Move scripts to separate chunks
[perso/Immae/Projets/Puppet.git] / bin / install_script_ovh_cloud_instance.sh
CommitLineData
ec1096d8
IB
1#!/bin/bash
2
3babc2c6
IB
3usage() {
4cat <<EOF
5 $0 [options]
6 --help,-h This help
df0c42af 7 --instance-id id Id of the instance
3babc2c6 8 --reinstall-first Start with reinstalling the vps
df0c42af 9 --host-user user Use another user (default: arch)
3babc2c6
IB
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)
85abd2fd 14 --environment Environment to use for the installl (default: production)
3babc2c6
IB
15EOF
16}
17
248bd83e
IB
18set -e
19
df0c42af 20host_user=arch
248bd83e 21git_branch=master
85abd2fd 22environment=production
248bd83e
IB
23
24while [ -n "$1" ]; do
25 case "$1" in
df0c42af
IB
26 --instance-id)
27 instance_id="$2"
248bd83e
IB
28 shift
29 ;;
30 --reinstall-first)
31 reinstall_first=1
32 ;;
248bd83e
IB
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 ;;
85abd2fd
IB
50 --environment)
51 environment="$2"
52 shift
53 ;;
3babc2c6
IB
54 --help|-h)
55 usage
56 exit 0
57 ;;
248bd83e
IB
58 esac
59
60 shift
61done
62
ec1096d8
IB
63DIRECTORY=$(cd `dirname $0` && pwd)
64PYTHON_DIRECTORY="$DIRECTORY/../python"
c15f2234 65SCRIPTS="$DIRECTORY/../scripts"
ec1096d8 66
df0c42af
IB
67if [ -z "$instance_id" ]; then
68 read -p "Id de l'instance : " instance_id
ec1096d8
IB
69fi
70
248bd83e
IB
71if [ -n "$reinstall_first" ]; then
72 echo "Réinstallation du système"
df0c42af 73 python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
248bd83e
IB
74
75 read -p "Appuyer sur une touche quand le serveur est prêt" ready
76fi
77
78if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
79 echo "Patienter le temps du reboot"
df0c42af 80 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
ec1096d8 81
df0c42af 82 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
248bd83e 83fi
ec1096d8
IB
84
85ARCH_DIR=`mktemp -d`
c15f2234
IB
86ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
87ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
88ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
89ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
248bd83e 90ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
ec1096d8
IB
91
92trap "rm -rf $ARCH_DIR" EXIT
93
503e4cf5 94#### Base installation stage
df0c42af
IB
95python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
96host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
248bd83e 97
c15f2234
IB
98dest="$host_user@$host_address"
99files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
ec1096d8 100
c15f2234 101$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
ec1096d8 102
503e4cf5
IB
103### Role specific stage
104read -p "Press key when LDAP is configured" i
105
c15f2234 106files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
503e4cf5 107
c15f2234 108$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
503e4cf5
IB
109
110### Installation finished
248bd83e 111if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
ec1096d8 112 echo "Rebooting"
df0c42af 113 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id"
ec1096d8 114fi