]>
Commit | Line | Data |
---|---|---|
ec1096d8 IB |
1 | #!/bin/bash |
2 | ||
3babc2c6 IB |
3 | usage() { |
4 | cat <<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 |
23 | EOF |
24 | } | |
25 | ||
248bd83e IB |
26 | set -e |
27 | ||
248bd83e | 28 | git_branch=master |
69da835d IB |
29 | host_user="" |
30 | password="" | |
31 | T="" | |
248bd83e IB |
32 | |
33 | while [ -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 | |
91 | done | |
92 | ||
9f430d51 | 93 | if [ -z "$T" -o -z "$host_id" -o -z "$environment" ]; then |
69da835d IB |
94 | usage |
95 | exit 1 | |
96 | fi | |
97 | ||
ec1096d8 IB |
98 | DIRECTORY=$(cd `dirname $0` && pwd) |
99 | PYTHON_DIRECTORY="$DIRECTORY/../python" | |
c15f2234 | 100 | SCRIPTS="$DIRECTORY/../scripts" |
ec1096d8 | 101 | |
248bd83e IB |
102 | if [ -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 | |
107 | fi | |
108 | ||
109 | if [ -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 | 114 | fi |
ec1096d8 | 115 | |
248bd83e IB |
116 | if [ -z "$password" ]; then |
117 | stty -echo | |
118 | read -p "Mot de passe reçu par e-mail : " password; echo | |
119 | stty echo | |
120 | fi | |
ec1096d8 IB |
121 | |
122 | ARCH_DIR=`mktemp -d` | |
69da835d IB |
123 | ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh" |
124 | if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then | |
125 | ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh" | |
126 | else | |
127 | ARCH_CHROOT_SCRIPT="" | |
128 | fi | |
c15f2234 | 129 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" |
69da835d | 130 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh" |
c15f2234 | 131 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" |
248bd83e | 132 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" |
ec1096d8 IB |
133 | |
134 | trap "rm -rf $ARCH_DIR" EXIT | |
135 | ||
503e4cf5 | 136 | #### Base installation stage |
69da835d IB |
137 | python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION |
138 | host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress') | |
248bd83e | 139 | |
69da835d | 140 | dest="$host_user@$host_address" |
c15f2234 | 141 | files="$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 |
146 | read -p "Press key when LDAP is configured" i | |
147 | ||
c15f2234 | 148 | files="$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 | 153 | if [ -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 | 156 | fi |