]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | ||
3 | usage() { | |
4 | cat <<EOF | |
5 | $(basename $0) [options] | |
6 | --help,-h This help | |
7 | ||
8 | Please chose environment: | |
9 | --environment env Environment to use for the install | |
10 | ||
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) | |
17 | --reinstall-first Start with reinstalling the vps | |
18 | --host-user user Use another user than the default one | |
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 | |
22 | --git-branch branch Use another puppet branch (default: master) | |
23 | EOF | |
24 | } | |
25 | ||
26 | set -e | |
27 | ||
28 | git_branch=master | |
29 | host_user="" | |
30 | password="" | |
31 | T="" | |
32 | ||
33 | while [ -n "$1" ]; do | |
34 | case "$1" in | |
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" | |
45 | shift | |
46 | ;; | |
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 | |
55 | ;; | |
56 | --password) | |
57 | password="$2" | |
58 | shift | |
59 | ;; | |
60 | --reinstall-first) | |
61 | reinstall_first=1 | |
62 | ;; | |
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 | ;; | |
80 | --environment) | |
81 | environment="$2" | |
82 | shift | |
83 | ;; | |
84 | --help|-h) | |
85 | usage | |
86 | exit 0 | |
87 | ;; | |
88 | esac | |
89 | ||
90 | shift | |
91 | done | |
92 | ||
93 | if [ -z "$T" -o -z "$host_id" -o -z "$environment" ]; then | |
94 | usage | |
95 | exit 1 | |
96 | fi | |
97 | ||
98 | DIRECTORY=$(cd `dirname $0` && pwd) | |
99 | PYTHON_DIRECTORY="$DIRECTORY/../python" | |
100 | SCRIPTS="$DIRECTORY/../scripts" | |
101 | ||
102 | if [ -n "$reinstall_first" ]; then | |
103 | echo "Réinstallation du système" | |
104 | python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id" | |
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" | |
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 | |
114 | fi | |
115 | ||
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 | |
121 | ||
122 | ARCH_DIR=`mktemp -d` | |
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 | |
129 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" | |
130 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh" | |
131 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" | |
132 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | |
133 | ||
134 | trap "rm -rf $ARCH_DIR" EXIT | |
135 | ||
136 | #### Base installation stage | |
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') | |
139 | ||
140 | dest="$host_user@$host_address" | |
141 | files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" | |
142 | ||
143 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files | |
144 | ||
145 | ### Role specific stage | |
146 | read -p "Press key when LDAP is configured" i | |
147 | ||
148 | files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" | |
149 | ||
150 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files | |
151 | ||
152 | ### Installation finished | |
153 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | |
154 | echo "Rebooting" | |
155 | python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id" | |
156 | fi |