]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - bin/install_script.sh
Fix ssmtp for mail cofniguration
[perso/Immae/Projets/Puppet.git] / bin / install_script.sh
CommitLineData
ec1096d8
IB
1#!/bin/bash
2
3babc2c6
IB
3usage() {
4cat <<EOF
69da835d 5$(basename $0) [options]
3babc2c6 6 --help,-h This help
69da835d 7
9f430d51
IB
8 Please chose environment:
9 --environment env Environment to use for the install
10
69da835d
IB
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
367c391a 14 --hetzner-id id Id of the Hetzner server
69da835d
IB
15
16 Optional arguments:
17 --password password Password of the host (only useful in case of no reboot and vps)
3babc2c6 18 --reinstall-first Start with reinstalling the vps
69da835d 19 --host-user user Use another user than the default one
3babc2c6
IB
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
69da835d 23 --git-branch branch Use another puppet branch (default: master)
3babc2c6
IB
24EOF
25}
26
248bd83e
IB
27set -e
28
248bd83e 29git_branch=master
69da835d
IB
30host_user=""
31password=""
32T=""
248bd83e
IB
33
34while [ -n "$1" ]; do
35 case "$1" in
69da835d
IB
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"
248bd83e
IB
46 shift
47 ;;
69da835d
IB
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
248bd83e 56 ;;
367c391a
IB
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 ;;
248bd83e
IB
66 --password)
67 password="$2"
68 shift
69 ;;
69da835d
IB
70 --reinstall-first)
71 reinstall_first=1
72 ;;
248bd83e
IB
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 ;;
85abd2fd
IB
90 --environment)
91 environment="$2"
92 shift
93 ;;
3babc2c6
IB
94 --help|-h)
95 usage
96 exit 0
97 ;;
248bd83e
IB
98 esac
99
100 shift
101done
102
9f430d51 103if [ -z "$T" -o -z "$host_id" -o -z "$environment" ]; then
69da835d
IB
104 usage
105 exit 1
106fi
107
ec1096d8
IB
108DIRECTORY=$(cd `dirname $0` && pwd)
109PYTHON_DIRECTORY="$DIRECTORY/../python"
c15f2234 110SCRIPTS="$DIRECTORY/../scripts"
ec1096d8 111
248bd83e
IB
112if [ -n "$reinstall_first" ]; then
113 echo "Réinstallation du système"
69da835d 114 python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id"
248bd83e
IB
115
116 read -p "Appuyer sur une touche quand le serveur est prêt" ready
117fi
118
119if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
120 echo "Patienter le temps du reboot"
69da835d
IB
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
248bd83e 124fi
ec1096d8 125
248bd83e
IB
126if [ -z "$password" ]; then
127 stty -echo
128 read -p "Mot de passe reçu par e-mail : " password; echo
129 stty echo
130fi
ec1096d8
IB
131
132ARCH_DIR=`mktemp -d`
69da835d
IB
133ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh"
134if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then
135 ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh"
136else
137 ARCH_CHROOT_SCRIPT=""
138fi
c15f2234 139ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
69da835d 140ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh"
c15f2234 141ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
248bd83e 142ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
ec1096d8
IB
143
144trap "rm -rf $ARCH_DIR" EXIT
145
503e4cf5 146#### Base installation stage
69da835d
IB
147python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
148host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress')
248bd83e 149
69da835d 150dest="$host_user@$host_address"
c15f2234 151files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
ec1096d8 152
c15f2234 153$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
ec1096d8 154
503e4cf5
IB
155### Role specific stage
156read -p "Press key when LDAP is configured" i
157
c15f2234 158files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
503e4cf5 159
c15f2234 160$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
503e4cf5
IB
161
162### Installation finished
248bd83e 163if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
ec1096d8 164 echo "Rebooting"
69da835d 165 python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id"
ec1096d8 166fi