aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-16 19:14:29 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-16 20:13:46 +0100
commit69da835d04e741f4e85da3c473ba86c8801931fd (patch)
tree0cfb28cfd468a5b681f2b5af2b935c81d2221950 /bin
parentc15f2234474ff8a8266e26856702b3c561050667 (diff)
downloadPuppet-69da835d04e741f4e85da3c473ba86c8801931fd.tar.gz
Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.tar.zst
Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.zip
Merge install scripts
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install_script.sh (renamed from bin/install_script_ovh_vps_ssd.sh)78
-rwxr-xr-xbin/install_script_ovh_cloud_instance.sh114
2 files changed, 55 insertions, 137 deletions
diff --git a/bin/install_script_ovh_vps_ssd.sh b/bin/install_script.sh
index b5b0efb..bd7f38b 100755
--- a/bin/install_script_ovh_vps_ssd.sh
+++ b/bin/install_script.sh
@@ -2,39 +2,63 @@
2 2
3usage() { 3usage() {
4cat <<EOF 4cat <<EOF
5 $0 [options] 5$(basename $0) [options]
6 --help,-h This help 6 --help,-h This help
7 --vps vps_name Name of the vps 7
8 --password password Password of the vps (only useful in case of no reboot) 8 One of the following options is necessary:
9 --instance-id id Id of the cloud instance
10 --vps-id id Id of the vps
11
12 Optional arguments:
13 --password password Password of the host (only useful in case of no reboot and vps)
9 --reinstall-first Start with reinstalling the vps 14 --reinstall-first Start with reinstalling the vps
10 --host-user user Use another user (default: root) 15 --host-user user Use another user than the default one
11 --no-reboot Don't reboot 16 --no-reboot Don't reboot
12 --no-reboot-start Don't reboot to rescue at the beginning 17 --no-reboot-start Don't reboot to rescue at the beginning
13 --no-reboot-end Don't reboot to normal at the end 18 --no-reboot-end Don't reboot to normal at the end
14 --git-branch Use another puppet branch (default: master) 19 --git-branch branch Use another puppet branch (default: master)
15 --environment Environment to use for the installl (default: production) 20 --environment env Environment to use for the install (default: production)
16EOF 21EOF
17} 22}
18 23
19set -e 24set -e
20 25
21host_user=root
22git_branch=master 26git_branch=master
23environment=production 27environment=production
28host_user=""
29password=""
30T=""
24 31
25while [ -n "$1" ]; do 32while [ -n "$1" ]; do
26 case "$1" in 33 case "$1" in
27 --vps) 34 --instance-id)
28 vps_name="$2" 35 host_id="$2"
36 if [ -z "$host_user" ]; then
37 host_user="arch"
38 fi
39 if [ -z "$password" ]; then
40 password="x"
41 fi
42 [ -n "$T" ] && usage && exit 1
43 T="ovh_cloud_instance"
29 shift 44 shift
30 ;; 45 ;;
31 --reinstall-first) 46 --vps-id)
32 reinstall_first=1 47 host_id="$2"
48 if [ -z "$host_user" ]; then
49 host_user="root"
50 fi
51 [ -n "$T" ] && usage && exit 1
52 T="ovh_vps_ssd"
53 shift
33 ;; 54 ;;
34 --password) 55 --password)
35 password="$2" 56 password="$2"
36 shift 57 shift
37 ;; 58 ;;
59 --reinstall-first)
60 reinstall_first=1
61 ;;
38 --host-user) 62 --host-user)
39 host_user="$2" 63 host_user="$2"
40 shift 64 shift
@@ -65,24 +89,27 @@ while [ -n "$1" ]; do
65 shift 89 shift
66done 90done
67 91
92if [ -z "$T" -o -z "$host_id" ]; then
93 usage
94 exit 1
95fi
96
68DIRECTORY=$(cd `dirname $0` && pwd) 97DIRECTORY=$(cd `dirname $0` && pwd)
69PYTHON_DIRECTORY="$DIRECTORY/../python" 98PYTHON_DIRECTORY="$DIRECTORY/../python"
70SCRIPTS="$DIRECTORY/../scripts" 99SCRIPTS="$DIRECTORY/../scripts"
71 100
72if [ -z "$vps_name" ]; then
73 read -p "Nom du vps : " vps_name
74fi
75
76if [ -n "$reinstall_first" ]; then 101if [ -n "$reinstall_first" ]; then
77 echo "Réinstallation du système" 102 echo "Réinstallation du système"
78 python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name" 103 python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id"
79 104
80 read -p "Appuyer sur une touche quand le serveur est prêt" ready 105 read -p "Appuyer sur une touche quand le serveur est prêt" ready
81fi 106fi
82 107
83if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then 108if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
84 echo "Patienter le temps du reboot" 109 echo "Patienter le temps du reboot"
85 python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name" 110 python $PYTHON_DIRECTORY/reboot_$T.py --rescue "$host_id"
111
112 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
86fi 113fi
87 114
88if [ -z "$password" ]; then 115if [ -z "$password" ]; then
@@ -92,19 +119,24 @@ if [ -z "$password" ]; then
92fi 119fi
93 120
94ARCH_DIR=`mktemp -d` 121ARCH_DIR=`mktemp -d`
95ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh" 122ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh"
96ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh" 123if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then
124 ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh"
125else
126 ARCH_CHROOT_SCRIPT=""
127fi
97ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" 128ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
98ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh" 129ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh"
99ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" 130ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
100ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" 131ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
101 132
102trap "rm -rf $ARCH_DIR" EXIT 133trap "rm -rf $ARCH_DIR" EXIT
103 134
104#### Base installation stage 135#### Base installation stage
105python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION 136python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
137host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress')
106 138
107dest="$host_user@$vps_name" 139dest="$host_user@$host_address"
108files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" 140files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
109 141
110$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files 142$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
@@ -119,5 +151,5 @@ $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $file
119### Installation finished 151### Installation finished
120if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then 152if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
121 echo "Rebooting" 153 echo "Rebooting"
122 python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name" 154 python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id"
123fi 155fi
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh
deleted file mode 100755
index e1c8a54..0000000
--- a/bin/install_script_ovh_cloud_instance.sh
+++ /dev/null
@@ -1,114 +0,0 @@
1#!/bin/bash
2
3usage() {
4cat <<EOF
5 $0 [options]
6 --help,-h This help
7 --instance-id id Id of the instance
8 --reinstall-first Start with reinstalling the vps
9 --host-user user Use another user (default: arch)
10 --no-reboot Don't reboot
11 --no-reboot-start Don't reboot to rescue at the beginning
12 --no-reboot-end Don't reboot to normal at the end
13 --git-branch Use another puppet branch (default: master)
14 --environment Environment to use for the installl (default: production)
15EOF
16}
17
18set -e
19
20host_user=arch
21git_branch=master
22environment=production
23
24while [ -n "$1" ]; do
25 case "$1" in
26 --instance-id)
27 instance_id="$2"
28 shift
29 ;;
30 --reinstall-first)
31 reinstall_first=1
32 ;;
33 --host-user)
34 host_user="$2"
35 shift
36 ;;
37 --no-reboot)
38 no_reboot=1
39 ;;
40 --no-reboot-start)
41 no_reboot_start=1
42 ;;
43 --no-reboot-end)
44 no_reboot_end=1
45 ;;
46 --git-branch)
47 git_branch="$2"
48 shift
49 ;;
50 --environment)
51 environment="$2"
52 shift
53 ;;
54 --help|-h)
55 usage
56 exit 0
57 ;;
58 esac
59
60 shift
61done
62
63DIRECTORY=$(cd `dirname $0` && pwd)
64PYTHON_DIRECTORY="$DIRECTORY/../python"
65SCRIPTS="$DIRECTORY/../scripts"
66
67if [ -z "$instance_id" ]; then
68 read -p "Id de l'instance : " instance_id
69fi
70
71if [ -n "$reinstall_first" ]; then
72 echo "Réinstallation du système"
73 python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
74
75 read -p "Appuyer sur une touche quand le serveur est prêt" ready
76fi
77
78if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
79 echo "Patienter le temps du reboot"
80 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
81
82 read -p "Appuyer sur une touche quand l'instance a redémarré" ready
83fi
84
85ARCH_DIR=`mktemp -d`
86ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
87ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
88ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
89ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
90ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
91
92trap "rm -rf $ARCH_DIR" EXIT
93
94#### Base installation stage
95python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
96host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
97
98dest="$host_user@$host_address"
99files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
100
101$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
102
103### Role specific stage
104read -p "Press key when LDAP is configured" i
105
106files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
107
108$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
109
110### Installation finished
111if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
112 echo "Rebooting"
113 python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id"
114fi