]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - bin/install_script_ovh_cloud_instance.sh
Move scripts to separate chunks
[perso/Immae/Projets/Puppet.git] / bin / install_script_ovh_cloud_instance.sh
1 #!/bin/bash
2
3 usage() {
4 cat <<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)
15 EOF
16 }
17
18 set -e
19
20 host_user=arch
21 git_branch=master
22 environment=production
23
24 while [ -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
61 done
62
63 DIRECTORY=$(cd `dirname $0` && pwd)
64 PYTHON_DIRECTORY="$DIRECTORY/../python"
65 SCRIPTS="$DIRECTORY/../scripts"
66
67 if [ -z "$instance_id" ]; then
68 read -p "Id de l'instance : " instance_id
69 fi
70
71 if [ -n "$reinstall_first" ]; then
72 echo "Réinstallation du système"
73 python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
74
75 read -p "Appuyer sur une touche quand le serveur est prêt" ready
76 fi
77
78 if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
79 echo "Patienter le temps du reboot"
80 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
81
82 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
83 fi
84
85 ARCH_DIR=`mktemp -d`
86 ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
87 ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
88 ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
89 ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
90 ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
91
92 trap "rm -rf $ARCH_DIR" EXIT
93
94 #### Base installation stage
95 python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
96 host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
97
98 dest="$host_user@$host_address"
99 files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
100
101 $SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
102
103 ### Role specific stage
104 read -p "Press key when LDAP is configured" i
105
106 files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
107
108 $SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
109
110 ### Installation finished
111 if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
112 echo "Rebooting"
113 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id"
114 fi