]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - bin/install_script_ovh_vps_ssd.sh
Move scripts to separate chunks
[perso/Immae/Projets/Puppet.git] / bin / install_script_ovh_vps_ssd.sh
CommitLineData
ec1096d8
IB
1#!/bin/bash
2
3babc2c6
IB
3usage() {
4cat <<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
16EOF
17}
18
248bd83e
IB
19set -e
20
21host_user=root
22git_branch=master
85abd2fd 23environment=production
248bd83e
IB
24
25while [ -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
66done
67
ec1096d8
IB
68DIRECTORY=$(cd `dirname $0` && pwd)
69PYTHON_DIRECTORY="$DIRECTORY/../python"
c15f2234 70SCRIPTS="$DIRECTORY/../scripts"
ec1096d8 71
248bd83e 72if [ -z "$vps_name" ]; then
ec1096d8
IB
73 read -p "Nom du vps : " vps_name
74fi
75
248bd83e
IB
76if [ -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
81fi
82
83if [ -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"
86fi
ec1096d8 87
248bd83e
IB
88if [ -z "$password" ]; then
89 stty -echo
90 read -p "Mot de passe reçu par e-mail : " password; echo
91 stty echo
92fi
ec1096d8
IB
93
94ARCH_DIR=`mktemp -d`
c15f2234
IB
95ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh"
96ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh"
97ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
98ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh"
99ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
248bd83e 100ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
ec1096d8
IB
101
102trap "rm -rf $ARCH_DIR" EXIT
103
503e4cf5 104#### Base installation stage
248bd83e
IB
105python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
106
c15f2234
IB
107dest="$host_user@$vps_name"
108files="$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
113read -p "Press key when LDAP is configured" i
114
c15f2234 115files="$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 120if [ -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"
123fi