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