]>
Commit | Line | Data |
---|---|---|
ec1096d8 IB |
1 | #!/bin/bash |
2 | ||
3babc2c6 IB |
3 | usage() { |
4 | cat <<EOF | |
5 | $0 [options] | |
6 | --help,-h This help | |
7 | --vps vps_name Name of the vps | |
8 | --password password Password of the vps (only useful in case of no reboot) | |
9 | --reinstall-first Start with reinstalling the vps | |
10 | --host-user user Use another user (default: root) | |
11 | --no-reboot Don't reboot | |
12 | --no-reboot-start Don't reboot to rescue at the beginning | |
13 | --no-reboot-end Don't reboot to normal at the end | |
14 | --git-branch Use another puppet branch (default: master) | |
85abd2fd | 15 | --environment Environment to use for the installl (default: production) |
3babc2c6 IB |
16 | EOF |
17 | } | |
18 | ||
248bd83e IB |
19 | set -e |
20 | ||
21 | host_user=root | |
22 | git_branch=master | |
85abd2fd | 23 | environment=production |
248bd83e IB |
24 | |
25 | while [ -n "$1" ]; do | |
26 | case "$1" in | |
27 | --vps) | |
28 | vps_name="$2" | |
29 | shift | |
30 | ;; | |
31 | --reinstall-first) | |
32 | reinstall_first=1 | |
33 | ;; | |
34 | --password) | |
35 | password="$2" | |
36 | shift | |
37 | ;; | |
38 | --host-user) | |
39 | host_user="$2" | |
40 | shift | |
41 | ;; | |
42 | --no-reboot) | |
43 | no_reboot=1 | |
44 | ;; | |
45 | --no-reboot-start) | |
46 | no_reboot_start=1 | |
47 | ;; | |
48 | --no-reboot-end) | |
49 | no_reboot_end=1 | |
50 | ;; | |
51 | --git-branch) | |
52 | git_branch="$2" | |
53 | shift | |
54 | ;; | |
85abd2fd IB |
55 | --environment) |
56 | environment="$2" | |
57 | shift | |
58 | ;; | |
3babc2c6 IB |
59 | --help|-h) |
60 | usage | |
61 | exit 0 | |
62 | ;; | |
248bd83e IB |
63 | esac |
64 | ||
65 | shift | |
66 | done | |
67 | ||
ec1096d8 IB |
68 | DIRECTORY=$(cd `dirname $0` && pwd) |
69 | PYTHON_DIRECTORY="$DIRECTORY/../python" | |
c15f2234 | 70 | SCRIPTS="$DIRECTORY/../scripts" |
ec1096d8 | 71 | |
248bd83e | 72 | if [ -z "$vps_name" ]; then |
ec1096d8 IB |
73 | read -p "Nom du vps : " vps_name |
74 | fi | |
75 | ||
248bd83e IB |
76 | if [ -n "$reinstall_first" ]; then |
77 | echo "Réinstallation du système" | |
78 | python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name" | |
79 | ||
80 | read -p "Appuyer sur une touche quand le serveur est prêt" ready | |
81 | fi | |
82 | ||
83 | if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then | |
84 | echo "Patienter le temps du reboot" | |
85 | python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name" | |
86 | fi | |
ec1096d8 | 87 | |
248bd83e IB |
88 | if [ -z "$password" ]; then |
89 | stty -echo | |
90 | read -p "Mot de passe reçu par e-mail : " password; echo | |
91 | stty echo | |
92 | fi | |
ec1096d8 IB |
93 | |
94 | ARCH_DIR=`mktemp -d` | |
c15f2234 IB |
95 | ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh" |
96 | ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh" | |
97 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" | |
98 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh" | |
99 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" | |
248bd83e | 100 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" |
ec1096d8 IB |
101 | |
102 | trap "rm -rf $ARCH_DIR" EXIT | |
103 | ||
503e4cf5 | 104 | #### Base installation stage |
248bd83e IB |
105 | python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION |
106 | ||
c15f2234 IB |
107 | dest="$host_user@$vps_name" |
108 | files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" | |
ec1096d8 | 109 | |
c15f2234 | 110 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files |
ec1096d8 | 111 | |
503e4cf5 IB |
112 | ### Role specific stage |
113 | read -p "Press key when LDAP is configured" i | |
114 | ||
c15f2234 | 115 | files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" |
503e4cf5 | 116 | |
c15f2234 | 117 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files |
503e4cf5 IB |
118 | |
119 | ### Installation finished | |
248bd83e | 120 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then |
ec1096d8 IB |
121 | echo "Rebooting" |
122 | python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name" | |
123 | fi |