diff options
Diffstat (limited to 'bin/install_script_ovh_cloud_instance.sh')
-rwxr-xr-x | bin/install_script_ovh_cloud_instance.sh | 88 |
1 files changed, 10 insertions, 78 deletions
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh index 26e410e..e1c8a54 100755 --- a/bin/install_script_ovh_cloud_instance.sh +++ b/bin/install_script_ovh_cloud_instance.sh | |||
@@ -62,6 +62,7 @@ done | |||
62 | 62 | ||
63 | DIRECTORY=$(cd `dirname $0` && pwd) | 63 | DIRECTORY=$(cd `dirname $0` && pwd) |
64 | PYTHON_DIRECTORY="$DIRECTORY/../python" | 64 | PYTHON_DIRECTORY="$DIRECTORY/../python" |
65 | SCRIPTS="$DIRECTORY/../scripts" | ||
65 | 66 | ||
66 | if [ -z "$instance_id" ]; then | 67 | if [ -z "$instance_id" ]; then |
67 | read -p "Id de l'instance : " instance_id | 68 | read -p "Id de l'instance : " instance_id |
@@ -82,10 +83,10 @@ if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then | |||
82 | fi | 83 | fi |
83 | 84 | ||
84 | ARCH_DIR=`mktemp -d` | 85 | ARCH_DIR=`mktemp -d` |
85 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" | 86 | ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh" |
86 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" | 87 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" |
87 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" | 88 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh" |
88 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" | 89 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" |
89 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | 90 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" |
90 | 91 | ||
91 | trap "rm -rf $ARCH_DIR" EXIT | 92 | trap "rm -rf $ARCH_DIR" EXIT |
@@ -94,86 +95,17 @@ trap "rm -rf $ARCH_DIR" EXIT | |||
94 | python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION | 95 | python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION |
95 | host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress') | 96 | host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress') |
96 | 97 | ||
97 | cat > $ARCH_HOST_SCRIPT <<EOF | 98 | dest="$host_user@$host_address" |
98 | #!/bin/bash | 99 | files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" |
99 | |||
100 | sudo haveged & | ||
101 | sudo pacman -Sy --noconfirm arch-install-scripts | ||
102 | |||
103 | DEVICE=/dev/vdb1 | ||
104 | MOUNTPOINT=/mnt | ||
105 | |||
106 | UUID=\$(lsblk -rno UUID "\$DEVICE") | ||
107 | PART="/dev/disk/by-uuid/\$UUID" | ||
108 | |||
109 | # mkfs.ext4 -F -U "\$UUID" "\$DEVICE" | ||
110 | sudo mount "\$DEVICE" /mnt | ||
111 | |||
112 | ##### FIXME: mkfs.ext4 would be better #### | ||
113 | for i in /mnt/*; do | ||
114 | if [ "\$i" = "/mnt/boot" ]; then | ||
115 | # keep /boot/grub | ||
116 | sudo rm -f \$i/* | ||
117 | else | ||
118 | sudo rm -rf \$i | ||
119 | fi | ||
120 | done | ||
121 | ##### /FIXME #### | ||
122 | |||
123 | sudo pacstrap /mnt base git puppet | ||
124 | |||
125 | echo "\$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab | ||
126 | 100 | ||
127 | sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" | 101 | $SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files |
128 | sudo cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/" | ||
129 | |||
130 | sudo arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh | ||
131 | EOF | ||
132 | |||
133 | cat > $ARCH_INSTALL_SCRIPT <<EOF | ||
134 | CODE_PATH="/etc/puppetlabs/code" | ||
135 | rm -rf \$CODE_PATH | ||
136 | git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH | ||
137 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
138 | # The password seed requires puppet to be run twice | ||
139 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
140 | EOF | ||
141 | |||
142 | chmod a+x $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT | ||
143 | |||
144 | expect -f - <<EOF | ||
145 | set timeout -1 | ||
146 | spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT $host_user@$host_address:/tmp | ||
147 | expect eof | ||
148 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_script.sh | ||
149 | expect eof | ||
150 | EOF | ||
151 | 102 | ||
152 | ### Role specific stage | 103 | ### Role specific stage |
153 | read -p "Press key when LDAP is configured" i | 104 | read -p "Press key when LDAP is configured" i |
154 | 105 | ||
155 | cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF | 106 | files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" |
156 | CODE_PATH="/etc/puppetlabs/code" | ||
157 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
158 | EOF | ||
159 | |||
160 | cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF | ||
161 | MOUNTPOINT=/mnt | ||
162 | 107 | ||
163 | sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/" | 108 | $SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files |
164 | |||
165 | sudo arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh | ||
166 | EOF | ||
167 | |||
168 | chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT | ||
169 | |||
170 | expect -f - <<EOF | ||
171 | set timeout -1 | ||
172 | spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $host_user@$host_address:/tmp | ||
173 | expect eof | ||
174 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_puppet_configuration_script.sh | ||
175 | expect eof | ||
176 | EOF | ||
177 | 109 | ||
178 | ### Installation finished | 110 | ### Installation finished |
179 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | 111 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then |