]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - bin/install_script_ovh_vps_ssd.sh
Move scripts to separate chunks
[perso/Immae/Projets/Puppet.git] / bin / install_script_ovh_vps_ssd.sh
1 #!/bin/bash
2
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)
15 --environment Environment to use for the installl (default: production)
16 EOF
17 }
18
19 set -e
20
21 host_user=root
22 git_branch=master
23 environment=production
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 ;;
55 --environment)
56 environment="$2"
57 shift
58 ;;
59 --help|-h)
60 usage
61 exit 0
62 ;;
63 esac
64
65 shift
66 done
67
68 DIRECTORY=$(cd `dirname $0` && pwd)
69 PYTHON_DIRECTORY="$DIRECTORY/../python"
70 SCRIPTS="$DIRECTORY/../scripts"
71
72 if [ -z "$vps_name" ]; then
73 read -p "Nom du vps : " vps_name
74 fi
75
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
87
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
93
94 ARCH_DIR=`mktemp -d`
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"
100 ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
101
102 trap "rm -rf $ARCH_DIR" EXIT
103
104 #### Base installation stage
105 python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
106
107 dest="$host_user@$vps_name"
108 files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
109
110 $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
111
112 ### Role specific stage
113 read -p "Press key when LDAP is configured" i
114
115 files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
116
117 $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
118
119 ### Installation finished
120 if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
121 echo "Rebooting"
122 python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name"
123 fi