]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - bin/install_script.sh
Merge branch 'split_scripts' into dev
[perso/Immae/Projets/Puppet.git] / bin / install_script.sh
CommitLineData
ec1096d8
IB
1#!/bin/bash
2
3babc2c6
IB
3usage() {
4cat <<EOF
69da835d 5$(basename $0) [options]
3babc2c6 6 --help,-h This help
69da835d
IB
7
8 One of the following options is necessary:
9 --instance-id id Id of the cloud instance
10 --vps-id id Id of the vps
11
12 Optional arguments:
13 --password password Password of the host (only useful in case of no reboot and vps)
3babc2c6 14 --reinstall-first Start with reinstalling the vps
69da835d 15 --host-user user Use another user than the default one
3babc2c6
IB
16 --no-reboot Don't reboot
17 --no-reboot-start Don't reboot to rescue at the beginning
18 --no-reboot-end Don't reboot to normal at the end
69da835d
IB
19 --git-branch branch Use another puppet branch (default: master)
20 --environment env Environment to use for the install (default: production)
3babc2c6
IB
21EOF
22}
23
248bd83e
IB
24set -e
25
248bd83e 26git_branch=master
85abd2fd 27environment=production
69da835d
IB
28host_user=""
29password=""
30T=""
248bd83e
IB
31
32while [ -n "$1" ]; do
33 case "$1" in
69da835d
IB
34 --instance-id)
35 host_id="$2"
36 if [ -z "$host_user" ]; then
37 host_user="arch"
38 fi
39 if [ -z "$password" ]; then
40 password="x"
41 fi
42 [ -n "$T" ] && usage && exit 1
43 T="ovh_cloud_instance"
248bd83e
IB
44 shift
45 ;;
69da835d
IB
46 --vps-id)
47 host_id="$2"
48 if [ -z "$host_user" ]; then
49 host_user="root"
50 fi
51 [ -n "$T" ] && usage && exit 1
52 T="ovh_vps_ssd"
53 shift
248bd83e
IB
54 ;;
55 --password)
56 password="$2"
57 shift
58 ;;
69da835d
IB
59 --reinstall-first)
60 reinstall_first=1
61 ;;
248bd83e
IB
62 --host-user)
63 host_user="$2"
64 shift
65 ;;
66 --no-reboot)
67 no_reboot=1
68 ;;
69 --no-reboot-start)
70 no_reboot_start=1
71 ;;
72 --no-reboot-end)
73 no_reboot_end=1
74 ;;
75 --git-branch)
76 git_branch="$2"
77 shift
78 ;;
85abd2fd
IB
79 --environment)
80 environment="$2"
81 shift
82 ;;
3babc2c6
IB
83 --help|-h)
84 usage
85 exit 0
86 ;;
248bd83e
IB
87 esac
88
89 shift
90done
91
69da835d
IB
92if [ -z "$T" -o -z "$host_id" ]; then
93 usage
94 exit 1
95fi
96
ec1096d8
IB
97DIRECTORY=$(cd `dirname $0` && pwd)
98PYTHON_DIRECTORY="$DIRECTORY/../python"
c15f2234 99SCRIPTS="$DIRECTORY/../scripts"
ec1096d8 100
248bd83e
IB
101if [ -n "$reinstall_first" ]; then
102 echo "Réinstallation du système"
69da835d 103 python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id"
248bd83e
IB
104
105 read -p "Appuyer sur une touche quand le serveur est prêt" ready
106fi
107
108if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
109 echo "Patienter le temps du reboot"
69da835d
IB
110 python $PYTHON_DIRECTORY/reboot_$T.py --rescue "$host_id"
111
112 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
248bd83e 113fi
ec1096d8 114
248bd83e
IB
115if [ -z "$password" ]; then
116 stty -echo
117 read -p "Mot de passe reçu par e-mail : " password; echo
118 stty echo
119fi
ec1096d8
IB
120
121ARCH_DIR=`mktemp -d`
69da835d
IB
122ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh"
123if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then
124 ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh"
125else
126 ARCH_CHROOT_SCRIPT=""
127fi
c15f2234 128ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
69da835d 129ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh"
c15f2234 130ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
248bd83e 131ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
ec1096d8
IB
132
133trap "rm -rf $ARCH_DIR" EXIT
134
503e4cf5 135#### Base installation stage
69da835d
IB
136python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
137host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress')
248bd83e 138
69da835d 139dest="$host_user@$host_address"
c15f2234 140files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
ec1096d8 141
c15f2234 142$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
ec1096d8 143
503e4cf5
IB
144### Role specific stage
145read -p "Press key when LDAP is configured" i
146
c15f2234 147files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
503e4cf5 148
c15f2234 149$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
503e4cf5
IB
150
151### Installation finished
248bd83e 152if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
ec1096d8 153 echo "Rebooting"
69da835d 154 python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id"
ec1096d8 155fi