aboutsummaryrefslogtreecommitdiff
path: root/bin/install_script_ovh_vps_ssd.sh
blob: b5b0efbbc9978b34dca092155e10a55e5ed0b1b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash

usage() {
cat <<EOF
  $0 [options]
  --help,-h               This help
  --vps vps_name          Name of the vps
  --password password     Password of the vps (only useful in case of no reboot)
  --reinstall-first       Start with reinstalling the vps
  --host-user user        Use another user (default: root)
  --no-reboot             Don't reboot
  --no-reboot-start       Don't reboot to rescue at the beginning
  --no-reboot-end         Don't reboot to normal at the end
  --git-branch            Use another puppet branch (default: master)
  --environment           Environment to use for the installl (default: production)
EOF
}

set -e

host_user=root
git_branch=master
environment=production

while [ -n "$1" ]; do
  case "$1" in
    --vps)
      vps_name="$2"
      shift
      ;;
    --reinstall-first)
      reinstall_first=1
      ;;
    --password)
      password="$2"
      shift
      ;;
    --host-user)
      host_user="$2"
      shift
      ;;
    --no-reboot)
      no_reboot=1
      ;;
    --no-reboot-start)
      no_reboot_start=1
      ;;
    --no-reboot-end)
      no_reboot_end=1
      ;;
    --git-branch)
      git_branch="$2"
      shift
      ;;
    --environment)
      environment="$2"
      shift
      ;;
    --help|-h)
      usage
      exit 0
      ;;
  esac

  shift
done

DIRECTORY=$(cd `dirname $0` && pwd)
PYTHON_DIRECTORY="$DIRECTORY/../python"
SCRIPTS="$DIRECTORY/../scripts"

if [ -z "$vps_name" ]; then
  read -p "Nom du vps : " vps_name
fi

if [ -n "$reinstall_first" ]; then
  echo "Réinstallation du système"
  python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name"

  read -p "Appuyer sur une touche quand le serveur est prêt" ready
fi

if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
  echo "Patienter le temps du reboot"
  python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name"
fi

if [ -z "$password" ]; then
  stty -echo
  read -p "Mot de passe reçu par e-mail : " password; echo
  stty echo
fi

ARCH_DIR=`mktemp -d`
ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh"
ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh"
ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh"
ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"

trap "rm -rf $ARCH_DIR" EXIT

#### Base installation stage
python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION

dest="$host_user@$vps_name"
files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"

$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files

### Role specific stage
read -p "Press key when LDAP is configured" i

files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"

$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files

### Installation finished
if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
  echo "Rebooting"
  python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name"
fi