aboutsummaryrefslogtreecommitdiff
path: root/bin/install_script.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/install_script.sh')
-rwxr-xr-xbin/install_script.sh82
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
3set -e
4
5host_user=root
6git_branch=master
7
8while [ -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
41done
42
3DIRECTORY=$(cd `dirname $0` && pwd) 43DIRECTORY=$(cd `dirname $0` && pwd)
4PYTHON_DIRECTORY="$DIRECTORY/../python" 44PYTHON_DIRECTORY="$DIRECTORY/../python"
5 45
6if [ -n "$1" ]; then 46if [ -z "$vps_name" ]; then
7 vps_name="$1"
8else
9 read -p "Nom du vps : " vps_name 47 read -p "Nom du vps : " vps_name
10fi 48fi
11 49
12echo "Patienter le temps du reboot" 50if [ -n "$reinstall_first" ]; then
13python $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
55fi
56
57if [ -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"
60fi
14 61
15stty -echo 62if [ -z "$password" ]; then
16read -p "Mot de passe reçu par e-mail : " password; echo 63 stty -echo
17stty echo 64 read -p "Mot de passe reçu par e-mail : " password; echo
65 stty echo
66fi
18 67
19ARCH_DIR=`mktemp -d` 68ARCH_DIR=`mktemp -d`
20ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" 69ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
@@ -22,10 +71,13 @@ ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh"
22ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" 71ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
23ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" 72ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
24ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" 73ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
74ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
25 75
26trap "rm -rf $ARCH_DIR" EXIT 76trap "rm -rf $ARCH_DIR" EXIT
27 77
28#### Base installation stage 78#### Base installation stage
79python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
80
29cat > $ARCH_HOST_SCRIPT <<EOF 81cat > $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/
61mount "\$DEVICE" 113mount "\$DEVICE"
62 114
63cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" 115cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
116cp /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
66EOF 119EOF
@@ -100,7 +153,7 @@ EOF
100cat > $ARCH_INSTALL_SCRIPT <<EOF 153cat > $ARCH_INSTALL_SCRIPT <<EOF
101CODE_PATH="/etc/puppetlabs/code" 154CODE_PATH="/etc/puppetlabs/code"
102rm -rf \$CODE_PATH 155rm -rf \$CODE_PATH
103git clone -b master --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH 156git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
104puppet apply --test \$CODE_PATH/manifests/site.pp 157puppet 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
106puppet apply --test \$CODE_PATH/manifests/site.pp 159puppet 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
111expect -f - <<EOF 164expect -f - <<EOF
112set timeout -1 165set timeout -1
113spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT root@$vps_name:/tmp 166spawn 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
114expect "assword:" 167expect "assword:"
115send "$password\n" 168send "$password\n"
116expect eof 169expect eof
117spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no root@$vps_name /tmp/arch_host_script.sh 170spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh
118expect "assword:" 171expect "assword:"
119send "$password\r" 172send "$password\r"
120expect eof 173expect eof
@@ -142,19 +195,18 @@ chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRI
142 195
143expect -f - <<EOF 196expect -f - <<EOF
144set timeout -1 197set timeout -1
145spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT root@$vps_name:/tmp 198spawn 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
146expect "assword:" 199expect "assword:"
147send "$password\n" 200send "$password\n"
148expect eof 201expect eof
149spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no root@$vps_name /tmp/arch_host_puppet_configuration_script.sh 202spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh
150expect "assword:" 203expect "assword:"
151send "$password\r" 204send "$password\r"
152expect eof 205expect eof
153EOF 206EOF
154 207
155### Installation finished 208### Installation finished
156read -p "Reboot to normal? [Y/n]" reboot 209if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
157if [ "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"
160fi 212fi