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