diff options
Diffstat (limited to 'bin/install_script.sh')
-rwxr-xr-x | bin/install_script.sh | 82 |
1 files changed, 67 insertions, 15 deletions
diff --git a/bin/install_script.sh b/bin/install_script.sh index f46ab29..3a59006 100755 --- a/bin/install_script.sh +++ b/bin/install_script.sh | |||
@@ -1,20 +1,69 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | set -e | ||
4 | |||
5 | host_user=root | ||
6 | git_branch=master | ||
7 | |||
8 | while [ -n "$1" ]; do | ||
9 | case "$1" in | ||
10 | --vps) | ||
11 | vps_name="$2" | ||
12 | shift | ||
13 | ;; | ||
14 | --reinstall-first) | ||
15 | reinstall_first=1 | ||
16 | ;; | ||
17 | --password) | ||
18 | password="$2" | ||
19 | shift | ||
20 | ;; | ||
21 | --host-user) | ||
22 | host_user="$2" | ||
23 | shift | ||
24 | ;; | ||
25 | --no-reboot) | ||
26 | no_reboot=1 | ||
27 | ;; | ||
28 | --no-reboot-start) | ||
29 | no_reboot_start=1 | ||
30 | ;; | ||
31 | --no-reboot-end) | ||
32 | no_reboot_end=1 | ||
33 | ;; | ||
34 | --git-branch) | ||
35 | git_branch="$2" | ||
36 | shift | ||
37 | ;; | ||
38 | esac | ||
39 | |||
40 | shift | ||
41 | done | ||
42 | |||
3 | DIRECTORY=$(cd `dirname $0` && pwd) | 43 | DIRECTORY=$(cd `dirname $0` && pwd) |
4 | PYTHON_DIRECTORY="$DIRECTORY/../python" | 44 | PYTHON_DIRECTORY="$DIRECTORY/../python" |
5 | 45 | ||
6 | if [ -n "$1" ]; then | 46 | if [ -z "$vps_name" ]; then |
7 | vps_name="$1" | ||
8 | else | ||
9 | read -p "Nom du vps : " vps_name | 47 | read -p "Nom du vps : " vps_name |
10 | fi | 48 | fi |
11 | 49 | ||
12 | echo "Patienter le temps du reboot" | 50 | if [ -n "$reinstall_first" ]; then |
13 | python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name" | 51 | echo "Réinstallation du système" |
52 | python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name" | ||
53 | |||
54 | read -p "Appuyer sur une touche quand le serveur est prêt" ready | ||
55 | fi | ||
56 | |||
57 | if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then | ||
58 | echo "Patienter le temps du reboot" | ||
59 | python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name" | ||
60 | fi | ||
14 | 61 | ||
15 | stty -echo | 62 | if [ -z "$password" ]; then |
16 | read -p "Mot de passe reçu par e-mail : " password; echo | 63 | stty -echo |
17 | stty echo | 64 | read -p "Mot de passe reçu par e-mail : " password; echo |
65 | stty echo | ||
66 | fi | ||
18 | 67 | ||
19 | ARCH_DIR=`mktemp -d` | 68 | ARCH_DIR=`mktemp -d` |
20 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" | 69 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" |
@@ -22,10 +71,13 @@ ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh" | |||
22 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" | 71 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" |
23 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" | 72 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" |
24 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" | 73 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" |
74 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | ||
25 | 75 | ||
26 | trap "rm -rf $ARCH_DIR" EXIT | 76 | trap "rm -rf $ARCH_DIR" EXIT |
27 | 77 | ||
28 | #### Base installation stage | 78 | #### Base installation stage |
79 | python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION | ||
80 | |||
29 | cat > $ARCH_HOST_SCRIPT <<EOF | 81 | cat > $ARCH_HOST_SCRIPT <<EOF |
30 | #!/bin/bash | 82 | #!/bin/bash |
31 | 83 | ||
@@ -61,6 +113,7 @@ cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/ | |||
61 | mount "\$DEVICE" | 113 | mount "\$DEVICE" |
62 | 114 | ||
63 | cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" | 115 | cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" |
116 | cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/" | ||
64 | 117 | ||
65 | /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh | 118 | /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh |
66 | EOF | 119 | EOF |
@@ -100,7 +153,7 @@ EOF | |||
100 | cat > $ARCH_INSTALL_SCRIPT <<EOF | 153 | cat > $ARCH_INSTALL_SCRIPT <<EOF |
101 | CODE_PATH="/etc/puppetlabs/code" | 154 | CODE_PATH="/etc/puppetlabs/code" |
102 | rm -rf \$CODE_PATH | 155 | rm -rf \$CODE_PATH |
103 | git clone -b master --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH | 156 | git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH |
104 | puppet apply --test \$CODE_PATH/manifests/site.pp | 157 | puppet apply --test \$CODE_PATH/manifests/site.pp |
105 | # The password seed requires puppet to be run twice | 158 | # The password seed requires puppet to be run twice |
106 | puppet apply --test \$CODE_PATH/manifests/site.pp | 159 | puppet apply --test \$CODE_PATH/manifests/site.pp |
@@ -110,11 +163,11 @@ chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT | |||
110 | 163 | ||
111 | expect -f - <<EOF | 164 | expect -f - <<EOF |
112 | set timeout -1 | 165 | set timeout -1 |
113 | spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT root@$vps_name:/tmp | 166 | spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT $host_user@$vps_name:/tmp |
114 | expect "assword:" | 167 | expect "assword:" |
115 | send "$password\n" | 168 | send "$password\n" |
116 | expect eof | 169 | expect eof |
117 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no root@$vps_name /tmp/arch_host_script.sh | 170 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh |
118 | expect "assword:" | 171 | expect "assword:" |
119 | send "$password\r" | 172 | send "$password\r" |
120 | expect eof | 173 | expect eof |
@@ -142,19 +195,18 @@ chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRI | |||
142 | 195 | ||
143 | expect -f - <<EOF | 196 | expect -f - <<EOF |
144 | set timeout -1 | 197 | set timeout -1 |
145 | spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT root@$vps_name:/tmp | 198 | spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $host_user@$vps_name:/tmp |
146 | expect "assword:" | 199 | expect "assword:" |
147 | send "$password\n" | 200 | send "$password\n" |
148 | expect eof | 201 | expect eof |
149 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no root@$vps_name /tmp/arch_host_puppet_configuration_script.sh | 202 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh |
150 | expect "assword:" | 203 | expect "assword:" |
151 | send "$password\r" | 204 | send "$password\r" |
152 | expect eof | 205 | expect eof |
153 | EOF | 206 | EOF |
154 | 207 | ||
155 | ### Installation finished | 208 | ### Installation finished |
156 | read -p "Reboot to normal? [Y/n]" reboot | 209 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then |
157 | if [ "x$reboot" != "xn" ]; then | ||
158 | echo "Rebooting" | 210 | echo "Rebooting" |
159 | python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name" | 211 | python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name" |
160 | fi | 212 | fi |