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