diff options
21 files changed, 401 insertions, 461 deletions
diff --git a/bin/install_script.sh b/bin/install_script.sh new file mode 100755 index 0000000..bd7f38b --- /dev/null +++ b/bin/install_script.sh | |||
@@ -0,0 +1,155 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | usage() { | ||
4 | cat <<EOF | ||
5 | $(basename $0) [options] | ||
6 | --help,-h This help | ||
7 | |||
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) | ||
14 | --reinstall-first Start with reinstalling the vps | ||
15 | --host-user user Use another user than the default one | ||
16 | --no-reboot Don't reboot | ||
17 | --no-reboot-start Don't reboot to rescue at the beginning | ||
18 | --no-reboot-end Don't reboot to normal at the end | ||
19 | --git-branch branch Use another puppet branch (default: master) | ||
20 | --environment env Environment to use for the install (default: production) | ||
21 | EOF | ||
22 | } | ||
23 | |||
24 | set -e | ||
25 | |||
26 | git_branch=master | ||
27 | environment=production | ||
28 | host_user="" | ||
29 | password="" | ||
30 | T="" | ||
31 | |||
32 | while [ -n "$1" ]; do | ||
33 | case "$1" in | ||
34 | --instance-id) | ||
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" | ||
44 | shift | ||
45 | ;; | ||
46 | --vps-id) | ||
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 | ||
54 | ;; | ||
55 | --password) | ||
56 | password="$2" | ||
57 | shift | ||
58 | ;; | ||
59 | --reinstall-first) | ||
60 | reinstall_first=1 | ||
61 | ;; | ||
62 | --host-user) | ||
63 | host_user="$2" | ||
64 | shift | ||
65 | ;; | ||
66 | --no-reboot) | ||
67 | no_reboot=1 | ||
68 | ;; | ||
69 | --no-reboot-start) | ||
70 | no_reboot_start=1 | ||
71 | ;; | ||
72 | --no-reboot-end) | ||
73 | no_reboot_end=1 | ||
74 | ;; | ||
75 | --git-branch) | ||
76 | git_branch="$2" | ||
77 | shift | ||
78 | ;; | ||
79 | --environment) | ||
80 | environment="$2" | ||
81 | shift | ||
82 | ;; | ||
83 | --help|-h) | ||
84 | usage | ||
85 | exit 0 | ||
86 | ;; | ||
87 | esac | ||
88 | |||
89 | shift | ||
90 | done | ||
91 | |||
92 | if [ -z "$T" -o -z "$host_id" ]; then | ||
93 | usage | ||
94 | exit 1 | ||
95 | fi | ||
96 | |||
97 | DIRECTORY=$(cd `dirname $0` && pwd) | ||
98 | PYTHON_DIRECTORY="$DIRECTORY/../python" | ||
99 | SCRIPTS="$DIRECTORY/../scripts" | ||
100 | |||
101 | if [ -n "$reinstall_first" ]; then | ||
102 | echo "Réinstallation du système" | ||
103 | python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id" | ||
104 | |||
105 | read -p "Appuyer sur une touche quand le serveur est prêt" ready | ||
106 | fi | ||
107 | |||
108 | if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then | ||
109 | echo "Patienter le temps du reboot" | ||
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 | ||
113 | fi | ||
114 | |||
115 | if [ -z "$password" ]; then | ||
116 | stty -echo | ||
117 | read -p "Mot de passe reçu par e-mail : " password; echo | ||
118 | stty echo | ||
119 | fi | ||
120 | |||
121 | ARCH_DIR=`mktemp -d` | ||
122 | ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh" | ||
123 | if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then | ||
124 | ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh" | ||
125 | else | ||
126 | ARCH_CHROOT_SCRIPT="" | ||
127 | fi | ||
128 | ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh" | ||
129 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh" | ||
130 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh" | ||
131 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | ||
132 | |||
133 | trap "rm -rf $ARCH_DIR" EXIT | ||
134 | |||
135 | #### Base installation stage | ||
136 | python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION | ||
137 | host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress') | ||
138 | |||
139 | dest="$host_user@$host_address" | ||
140 | files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" | ||
141 | |||
142 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files | ||
143 | |||
144 | ### Role specific stage | ||
145 | read -p "Press key when LDAP is configured" i | ||
146 | |||
147 | files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" | ||
148 | |||
149 | $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files | ||
150 | |||
151 | ### Installation finished | ||
152 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | ||
153 | echo "Rebooting" | ||
154 | python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id" | ||
155 | fi | ||
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh deleted file mode 100755 index 26e410e..0000000 --- a/bin/install_script_ovh_cloud_instance.sh +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | usage() { | ||
4 | cat <<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) | ||
15 | EOF | ||
16 | } | ||
17 | |||
18 | set -e | ||
19 | |||
20 | host_user=arch | ||
21 | git_branch=master | ||
22 | environment=production | ||
23 | |||
24 | while [ -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 | ||
61 | done | ||
62 | |||
63 | DIRECTORY=$(cd `dirname $0` && pwd) | ||
64 | PYTHON_DIRECTORY="$DIRECTORY/../python" | ||
65 | |||
66 | if [ -z "$instance_id" ]; then | ||
67 | read -p "Id de l'instance : " instance_id | ||
68 | fi | ||
69 | |||
70 | if [ -n "$reinstall_first" ]; then | ||
71 | echo "Réinstallation du système" | ||
72 | python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id" | ||
73 | |||
74 | read -p "Appuyer sur une touche quand le serveur est prêt" ready | ||
75 | fi | ||
76 | |||
77 | if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then | ||
78 | echo "Patienter le temps du reboot" | ||
79 | python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id" | ||
80 | |||
81 | read -p "Appuyer sur une touche quand l'instance a redémarré" ready | ||
82 | fi | ||
83 | |||
84 | ARCH_DIR=`mktemp -d` | ||
85 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" | ||
86 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" | ||
87 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" | ||
88 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" | ||
89 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | ||
90 | |||
91 | trap "rm -rf $ARCH_DIR" EXIT | ||
92 | |||
93 | #### Base installation stage | ||
94 | 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 | |||
97 | cat > $ARCH_HOST_SCRIPT <<EOF | ||
98 | #!/bin/bash | ||
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 | |||
127 | sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" | ||
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 | |||
152 | ### Role specific stage | ||
153 | read -p "Press key when LDAP is configured" i | ||
154 | |||
155 | cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF | ||
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 | |||
163 | sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/" | ||
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 | |||
178 | ### Installation finished | ||
179 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | ||
180 | echo "Rebooting" | ||
181 | python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id" | ||
182 | fi | ||
diff --git a/bin/install_script_ovh_vps_ssd.sh b/bin/install_script_ovh_vps_ssd.sh deleted file mode 100755 index 6b1aa39..0000000 --- a/bin/install_script_ovh_vps_ssd.sh +++ /dev/null | |||
@@ -1,237 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | usage() { | ||
4 | cat <<EOF | ||
5 | $0 [options] | ||
6 | --help,-h This help | ||
7 | --vps vps_name Name of the vps | ||
8 | --password password Password of the vps (only useful in case of no reboot) | ||
9 | --reinstall-first Start with reinstalling the vps | ||
10 | --host-user user Use another user (default: root) | ||
11 | --no-reboot Don't reboot | ||
12 | --no-reboot-start Don't reboot to rescue at the beginning | ||
13 | --no-reboot-end Don't reboot to normal at the end | ||
14 | --git-branch Use another puppet branch (default: master) | ||
15 | --environment Environment to use for the installl (default: production) | ||
16 | EOF | ||
17 | } | ||
18 | |||
19 | set -e | ||
20 | |||
21 | host_user=root | ||
22 | git_branch=master | ||
23 | environment=production | ||
24 | |||
25 | while [ -n "$1" ]; do | ||
26 | case "$1" in | ||
27 | --vps) | ||
28 | vps_name="$2" | ||
29 | shift | ||
30 | ;; | ||
31 | --reinstall-first) | ||
32 | reinstall_first=1 | ||
33 | ;; | ||
34 | --password) | ||
35 | password="$2" | ||
36 | shift | ||
37 | ;; | ||
38 | --host-user) | ||
39 | host_user="$2" | ||
40 | shift | ||
41 | ;; | ||
42 | --no-reboot) | ||
43 | no_reboot=1 | ||
44 | ;; | ||
45 | --no-reboot-start) | ||
46 | no_reboot_start=1 | ||
47 | ;; | ||
48 | --no-reboot-end) | ||
49 | no_reboot_end=1 | ||
50 | ;; | ||
51 | --git-branch) | ||
52 | git_branch="$2" | ||
53 | shift | ||
54 | ;; | ||
55 | --environment) | ||
56 | environment="$2" | ||
57 | shift | ||
58 | ;; | ||
59 | --help|-h) | ||
60 | usage | ||
61 | exit 0 | ||
62 | ;; | ||
63 | esac | ||
64 | |||
65 | shift | ||
66 | done | ||
67 | |||
68 | DIRECTORY=$(cd `dirname $0` && pwd) | ||
69 | PYTHON_DIRECTORY="$DIRECTORY/../python" | ||
70 | |||
71 | if [ -z "$vps_name" ]; then | ||
72 | read -p "Nom du vps : " vps_name | ||
73 | fi | ||
74 | |||
75 | if [ -n "$reinstall_first" ]; then | ||
76 | echo "Réinstallation du système" | ||
77 | python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name" | ||
78 | |||
79 | read -p "Appuyer sur une touche quand le serveur est prêt" ready | ||
80 | fi | ||
81 | |||
82 | if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then | ||
83 | echo "Patienter le temps du reboot" | ||
84 | python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name" | ||
85 | fi | ||
86 | |||
87 | if [ -z "$password" ]; then | ||
88 | stty -echo | ||
89 | read -p "Mot de passe reçu par e-mail : " password; echo | ||
90 | stty echo | ||
91 | fi | ||
92 | |||
93 | ARCH_DIR=`mktemp -d` | ||
94 | ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh" | ||
95 | ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh" | ||
96 | ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh" | ||
97 | ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh" | ||
98 | ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh" | ||
99 | ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json" | ||
100 | |||
101 | trap "rm -rf $ARCH_DIR" EXIT | ||
102 | |||
103 | #### Base installation stage | ||
104 | python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION | ||
105 | |||
106 | cat > $ARCH_HOST_SCRIPT <<EOF | ||
107 | #!/bin/bash | ||
108 | |||
109 | apt-get update | ||
110 | apt-get install -y haveged | ||
111 | haveged & | ||
112 | |||
113 | cd /tmp | ||
114 | |||
115 | LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1) | ||
116 | SHA1=\$(echo "\$LATEST" | cut -d' ' -f1) | ||
117 | NAME=\$(echo "\$LATEST" | cut -d' ' -f3) | ||
118 | |||
119 | curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME" | ||
120 | |||
121 | tar -xzf "\$NAME" | ||
122 | |||
123 | echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist | ||
124 | |||
125 | DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/") | ||
126 | DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1) | ||
127 | MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2) | ||
128 | |||
129 | umount "\$DEVICE" | ||
130 | UUID=\$(lsblk -rno UUID "\$DEVICE") | ||
131 | |||
132 | echo "\$UUID" > /tmp/root.x86_64/device_uuid | ||
133 | |||
134 | cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/ | ||
135 | |||
136 | /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh | ||
137 | |||
138 | mount "\$DEVICE" | ||
139 | |||
140 | cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/" | ||
141 | cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/" | ||
142 | |||
143 | /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh | ||
144 | EOF | ||
145 | |||
146 | |||
147 | cat > $ARCH_CHROOT_SCRIPT <<EOF | ||
148 | #!/bin/bash | ||
149 | |||
150 | pacman-key --init | ||
151 | pacman-key --populate archlinux | ||
152 | |||
153 | UUID=\$(cat /device_uuid) | ||
154 | PART="/dev/disk/by-uuid/\$UUID" | ||
155 | DEVICE=\$(realpath "\$PART") | ||
156 | |||
157 | # mkfs.ext4 -F -U "\$UUID" "\$DEVICE" | ||
158 | mount "\$DEVICE" /mnt | ||
159 | |||
160 | ##### FIXME: mkfs.ext4 would be better #### | ||
161 | for i in /mnt/*; do | ||
162 | if [ "\$i" = "/mnt/boot" ]; then | ||
163 | # keep /boot/grub | ||
164 | rm -f \$i/* | ||
165 | else | ||
166 | rm -rf \$i | ||
167 | fi | ||
168 | done | ||
169 | ##### /FIXME #### | ||
170 | |||
171 | pacstrap /mnt base git puppet | ||
172 | |||
173 | echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab | ||
174 | |||
175 | umount /mnt | ||
176 | EOF | ||
177 | |||
178 | cat > $ARCH_INSTALL_SCRIPT <<EOF | ||
179 | CODE_PATH="/etc/puppetlabs/code" | ||
180 | rm -rf \$CODE_PATH | ||
181 | git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH | ||
182 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
183 | # The password seed requires puppet to be run twice | ||
184 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
185 | EOF | ||
186 | |||
187 | chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT | ||
188 | |||
189 | expect -f - <<EOF | ||
190 | set timeout -1 | ||
191 | 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 | ||
192 | expect "assword:" | ||
193 | send "$password\n" | ||
194 | expect eof | ||
195 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh | ||
196 | expect "assword:" | ||
197 | send "$password\r" | ||
198 | expect eof | ||
199 | EOF | ||
200 | |||
201 | ### Role specific stage | ||
202 | read -p "Press key when LDAP is configured" i | ||
203 | |||
204 | cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF | ||
205 | CODE_PATH="/etc/puppetlabs/code" | ||
206 | puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp | ||
207 | EOF | ||
208 | |||
209 | cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF | ||
210 | DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/") | ||
211 | DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1) | ||
212 | MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2) | ||
213 | |||
214 | cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/" | ||
215 | |||
216 | /tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh | ||
217 | EOF | ||
218 | |||
219 | chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT | ||
220 | |||
221 | expect -f - <<EOF | ||
222 | set timeout -1 | ||
223 | 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 | ||
224 | expect "assword:" | ||
225 | send "$password\n" | ||
226 | expect eof | ||
227 | spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh | ||
228 | expect "assword:" | ||
229 | send "$password\r" | ||
230 | expect eof | ||
231 | EOF | ||
232 | |||
233 | ### Installation finished | ||
234 | if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then | ||
235 | echo "Rebooting" | ||
236 | python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name" | ||
237 | fi | ||
diff --git a/modules/base_installation/templates/puppet/host_ldap.info.erb b/modules/base_installation/templates/puppet/host_ldap.info.erb index a71c6f3..9c79d3c 100644 --- a/modules/base_installation/templates/puppet/host_ldap.info.erb +++ b/modules/base_installation/templates/puppet/host_ldap.info.erb | |||
@@ -1,4 +1,4 @@ | |||
1 | #### Please add this node to LDAP: | 1 | [0;35m#### Please add this node to LDAP:[0m |
2 | ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF' | 2 | ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF' |
3 | dn: <%= @ldap_dn %> | 3 | dn: <%= @ldap_dn %> |
4 | cn: <%= @ldap_cn %> | 4 | cn: <%= @ldap_cn %> |
@@ -14,12 +14,13 @@ objectclass: ipHost | |||
14 | environment: <%= @environment %> | 14 | environment: <%= @environment %> |
15 | userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> | 15 | userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> |
16 | EOF | 16 | EOF |
17 | #### Or modify an existing entry: | 17 | [0;35m#### Or modify an existing entry:[0m |
18 | ldapmodify -D "cn=root,<%= @ldap_base %>" -W << 'EOF' | 18 | ldapmodify -D "cn=root,<%= @ldap_base %>" -W << 'EOF' |
19 | dn: <%= @ldap_dn %> | 19 | dn: <%= @ldap_dn %> |
20 | changetype: modify | 20 | changetype: modify |
21 | replace: userPassword | 21 | replace: userPassword |
22 | userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> | 22 | userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> |
23 | - | ||
23 | replace: environment | 24 | replace: environment |
24 | environment: <%= @environment %> | 25 | environment: <%= @environment %> |
25 | <%- unless @ips.empty? -%> | 26 | <%- unless @ips.empty? -%> |
diff --git a/python/buy_vps_server.py b/python/buy_ovh_vps_ssd.py index 44ae786..44ae786 100644 --- a/python/buy_vps_server.py +++ b/python/buy_ovh_vps_ssd.py | |||
diff --git a/python/get_initial_configuration_cloud_instance.py b/python/get_initial_configuration_ovh_cloud_instance.py index 4157716..844373c 100644 --- a/python/get_initial_configuration_cloud_instance.py +++ b/python/get_initial_configuration_ovh_cloud_instance.py | |||
@@ -6,6 +6,7 @@ except ImportError: | |||
6 | # In case it's installed globally | 6 | # In case it's installed globally |
7 | import ovh | 7 | import ovh |
8 | import sys | 8 | import sys |
9 | from ovh_helper import find_cloud_instance | ||
9 | 10 | ||
10 | infos = {} | 11 | infos = {} |
11 | 12 | ||
@@ -13,19 +14,7 @@ infos = {} | |||
13 | # See ovh/README.rst | 14 | # See ovh/README.rst |
14 | client = ovh.Client() | 15 | client = ovh.Client() |
15 | 16 | ||
16 | projects_list = client.get('/cloud/project/') | 17 | _, instance = find_cloud_instance(client, sys.argv[-1]) |
17 | if len(projects_list) > 1: | ||
18 | print("More than one project is not supported, taking the first one") | ||
19 | project = projects_list[0] | ||
20 | instances_list = client.get('/cloud/project/{}/instance'.format(project)) | ||
21 | instances = dict(map(lambda x: (x["id"], x), instances_list)) | ||
22 | if sys.argv[-1] in instances: | ||
23 | instance = instances[sys.argv[-1]] | ||
24 | else: | ||
25 | print("Instance not in list:") | ||
26 | for instance in instances_list: | ||
27 | print("{}: {}".format(instance["name"], instance["id"])) | ||
28 | sys.exit(1) | ||
29 | 18 | ||
30 | infos["ips"] = {} | 19 | infos["ips"] = {} |
31 | for ip_infos in instance["ipAddresses"]: | 20 | for ip_infos in instance["ipAddresses"]: |
diff --git a/python/get_initial_configuration.py b/python/get_initial_configuration_ovh_vps_ssd.py index 0c6f698..0c6f698 100644 --- a/python/get_initial_configuration.py +++ b/python/get_initial_configuration_ovh_vps_ssd.py | |||
diff --git a/python/list_servers.py b/python/list_servers.py index 9b8bc64..e7bd2af 100644 --- a/python/list_servers.py +++ b/python/list_servers.py | |||
@@ -6,7 +6,18 @@ except ImportError: | |||
6 | 6 | ||
7 | client = ovh.Client() | 7 | client = ovh.Client() |
8 | 8 | ||
9 | print("OVH cloud instances:") | ||
10 | projects_list = client.get('/cloud/project/') | ||
11 | for project_id in projects_list: | ||
12 | project = client.get('/cloud/project/{}'.format(project_id)) | ||
13 | print("\t{}:".format(project["description"])) | ||
14 | instances_list = client.get('/cloud/project/{}/instance'.format(project_id)) | ||
15 | for instance in instances_list: | ||
16 | print("\t\t{}: {}".format(instance["name"], instance["id"])) | ||
17 | |||
9 | vps_list = client.get('/vps/') | 18 | vps_list = client.get('/vps/') |
10 | 19 | ||
20 | print("OVH VPS SSD servers:") | ||
11 | for vps in vps_list: | 21 | for vps in vps_list: |
12 | print(vps) | 22 | print("\t{}".format(vps)) |
23 | |||
diff --git a/python/ovh_helper.py b/python/ovh_helper.py index a49a245..19834ae 100644 --- a/python/ovh_helper.py +++ b/python/ovh_helper.py | |||
@@ -1,4 +1,5 @@ | |||
1 | import time | 1 | import time |
2 | import sys | ||
2 | 3 | ||
3 | def show_progress(client, vps, task_type): | 4 | def show_progress(client, vps, task_type): |
4 | running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0] | 5 | running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0] |
@@ -17,3 +18,19 @@ def show_progress(client, vps, task_type): | |||
17 | time.sleep(3) | 18 | time.sleep(3) |
18 | 19 | ||
19 | print("\rFinished") | 20 | print("\rFinished") |
21 | |||
22 | def find_cloud_instance(client, instance_id): | ||
23 | projects_list = client.get('/cloud/project/') | ||
24 | instances_list = [] | ||
25 | for project in projects_list: | ||
26 | instances_list += list(map(lambda x: [project, x], | ||
27 | client.get('/cloud/project/{}/instance'.format(project)))) | ||
28 | instances = dict(map(lambda x: (x[1]["id"], x), instances_list)) | ||
29 | if instance_id in instances: | ||
30 | project_instance = instances[instance_id] | ||
31 | else: | ||
32 | print("Instance not in list:") | ||
33 | for instance in instances_list: | ||
34 | print("{}: {}".format(instance[1]["name"], instance[1]["id"])) | ||
35 | sys.exit(1) | ||
36 | return project_instance | ||
diff --git a/python/reboot_cloud_instance.py b/python/reboot_ovh_cloud_instance.py index b90f488..de20c07 100644 --- a/python/reboot_cloud_instance.py +++ b/python/reboot_ovh_cloud_instance.py | |||
@@ -6,24 +6,13 @@ except ImportError: | |||
6 | # In case it's installed globally | 6 | # In case it's installed globally |
7 | import ovh | 7 | import ovh |
8 | import sys | 8 | import sys |
9 | from ovh_helper import find_cloud_instance | ||
9 | 10 | ||
10 | # Credentials are stored in ~/.ovh.conf | 11 | # Credentials are stored in ~/.ovh.conf |
11 | # See ovh/README.rst | 12 | # See ovh/README.rst |
12 | client = ovh.Client() | 13 | client = ovh.Client() |
13 | 14 | ||
14 | projects_list = client.get('/cloud/project/') | 15 | project, instance = find_cloud_instance(client, sys.argv[-1]) |
15 | if len(projects_list) > 1: | ||
16 | print("More than one project is not supported, taking the first one") | ||
17 | project = projects_list[0] | ||
18 | instances_list = client.get('/cloud/project/{}/instance'.format(project)) | ||
19 | instances = dict(map(lambda x: (x["id"], x), instances_list)) | ||
20 | if sys.argv[-1] in instances: | ||
21 | instance = instances[sys.argv[-1]] | ||
22 | else: | ||
23 | print("Instance not in list:") | ||
24 | for instance in instances_list: | ||
25 | print("{}: {}".format(instance["name"], instance["id"])) | ||
26 | sys.exit(1) | ||
27 | 16 | ||
28 | if "--rescue" in sys.argv: | 17 | if "--rescue" in sys.argv: |
29 | netboot_mode="rescue" | 18 | netboot_mode="rescue" |
diff --git a/python/reboot_vps_server.py b/python/reboot_ovh_vps_ssd.py index 71c5227..71c5227 100644 --- a/python/reboot_vps_server.py +++ b/python/reboot_ovh_vps_ssd.py | |||
diff --git a/python/reinstall_cloud_instance.py b/python/reinstall_ovh_cloud_instance.py index c488fda..c0d2617 100644 --- a/python/reinstall_cloud_instance.py +++ b/python/reinstall_ovh_cloud_instance.py | |||
@@ -6,24 +6,13 @@ except ImportError: | |||
6 | # In case it's installed globally | 6 | # In case it's installed globally |
7 | import ovh | 7 | import ovh |
8 | import sys | 8 | import sys |
9 | from ovh_helper import find_cloud_instance | ||
9 | 10 | ||
10 | # Credentials are stored in ~/.ovh.conf | 11 | # Credentials are stored in ~/.ovh.conf |
11 | # See ovh/README.rst | 12 | # See ovh/README.rst |
12 | client = ovh.Client() | 13 | client = ovh.Client() |
13 | 14 | ||
14 | projects_list = client.get('/cloud/project/') | 15 | project, instance = find_cloud_instance(client, sys.argv[-1]) |
15 | if len(projects_list) > 1: | ||
16 | print("More than one project is not supported, taking the first one") | ||
17 | project = projects_list[0] | ||
18 | instances_list = client.get('/cloud/project/{}/instance'.format(project)) | ||
19 | instances = dict(map(lambda x: (x["id"], x), instances_list)) | ||
20 | if sys.argv[-1] in instances: | ||
21 | instance = instances[sys.argv[-1]] | ||
22 | else: | ||
23 | print("Instance not in list:") | ||
24 | for instance in instances_list: | ||
25 | print("{}: {}".format(instance["name"], instance["id"])) | ||
26 | sys.exit(1) | ||
27 | 16 | ||
28 | current_image = instance["imageId"] | 17 | current_image = instance["imageId"] |
29 | available_images = client.get('/cloud/project/{}/image'.format(project), | 18 | available_images = client.get('/cloud/project/{}/image'.format(project), |
diff --git a/python/reinstall_vps_server.py b/python/reinstall_ovh_vps_ssd.py index 9f535cc..9f535cc 100644 --- a/python/reinstall_vps_server.py +++ b/python/reinstall_ovh_vps_ssd.py | |||
diff --git a/scripts/arch_install_script.sh b/scripts/arch_install_script.sh new file mode 100755 index 0000000..21e202f --- /dev/null +++ b/scripts/arch_install_script.sh | |||
@@ -0,0 +1,13 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | git_branch="$1" | ||
4 | environment="$2" | ||
5 | CODE_PATH="/etc/puppetlabs/code" | ||
6 | |||
7 | rm -rf $CODE_PATH | ||
8 | |||
9 | git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git $CODE_PATH | ||
10 | puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp | ||
11 | # The password seed requires puppet to be run twice | ||
12 | puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp | ||
13 | |||
diff --git a/scripts/arch_puppet_configuration_script.sh b/scripts/arch_puppet_configuration_script.sh new file mode 100755 index 0000000..caf8987 --- /dev/null +++ b/scripts/arch_puppet_configuration_script.sh | |||
@@ -0,0 +1,8 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | git_branch="$1" | ||
4 | environment="$2" | ||
5 | CODE_PATH="/etc/puppetlabs/code" | ||
6 | |||
7 | puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp | ||
8 | |||
diff --git a/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh b/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh new file mode 100755 index 0000000..b58e255 --- /dev/null +++ b/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | git_branch="$1" | ||
4 | environment="$2" | ||
5 | |||
6 | MOUNTPOINT=/mnt | ||
7 | |||
8 | sudo cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/" | ||
9 | |||
10 | sudo arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment" | ||
11 | |||
diff --git a/scripts/ovh_cloud_instance/arch_host_script.sh b/scripts/ovh_cloud_instance/arch_host_script.sh new file mode 100755 index 0000000..3408563 --- /dev/null +++ b/scripts/ovh_cloud_instance/arch_host_script.sh | |||
@@ -0,0 +1,50 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | git_branch="$1" | ||
6 | environment="$2" | ||
7 | |||
8 | # Randomizer | ||
9 | sudo haveged & | ||
10 | # /Randomizer | ||
11 | |||
12 | # Prepare an arch chroot | ||
13 | sudo pacman -Sy --noconfirm arch-install-scripts | ||
14 | # /Prepare an arch chroot | ||
15 | |||
16 | # Prepare device information | ||
17 | DEVICE=/dev/vdb1 | ||
18 | MOUNTPOINT=/mnt | ||
19 | |||
20 | UUID=$(lsblk -rno UUID "$DEVICE") | ||
21 | PART="/dev/disk/by-uuid/$UUID" | ||
22 | # /Prepare device information | ||
23 | |||
24 | # Install very basic system (base git puppet) | ||
25 | # mkfs.ext4 -F -U "$UUID" "$DEVICE" | ||
26 | sudo mount "$DEVICE" /mnt | ||
27 | |||
28 | ##### FIXME: mkfs.ext4 would be better #### | ||
29 | for i in /mnt/*; do | ||
30 | if [ "$i" = "/mnt/boot" ]; then | ||
31 | # keep /boot/grub | ||
32 | sudo rm -f $i/* || true | ||
33 | else | ||
34 | sudo rm -rf $i | ||
35 | fi | ||
36 | done | ||
37 | ##### /FIXME #### | ||
38 | |||
39 | sudo pacstrap /mnt base git puppet | ||
40 | |||
41 | echo "$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab | ||
42 | # /Install very basic system | ||
43 | |||
44 | # Install rest of system (via puppet) | ||
45 | sudo cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/" | ||
46 | sudo cp /tmp/puppet_variables.json "$MOUNTPOINT/root/" | ||
47 | |||
48 | sudo arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment" | ||
49 | # /Install rest of system | ||
50 | |||
diff --git a/scripts/ovh_vps_ssd/arch_chroot_script.sh b/scripts/ovh_vps_ssd/arch_chroot_script.sh new file mode 100755 index 0000000..9dc5c46 --- /dev/null +++ b/scripts/ovh_vps_ssd/arch_chroot_script.sh | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | pacman-key --init | ||
4 | pacman-key --populate archlinux | ||
5 | |||
6 | UUID=$(cat /device_uuid) | ||
7 | PART="/dev/disk/by-uuid/$UUID" | ||
8 | DEVICE=$(realpath "$PART") | ||
9 | |||
10 | # mkfs.ext4 -F -U "$UUID" "$DEVICE" | ||
11 | mount "$DEVICE" /mnt | ||
12 | |||
13 | ##### FIXME: mkfs.ext4 would be better #### | ||
14 | for i in /mnt/*; do | ||
15 | if [ "$i" = "/mnt/boot" ]; then | ||
16 | # keep /boot/grub | ||
17 | rm -f $i/* | ||
18 | else | ||
19 | rm -rf $i | ||
20 | fi | ||
21 | done | ||
22 | ##### /FIXME #### | ||
23 | |||
24 | pacstrap /mnt base git puppet | ||
25 | |||
26 | echo "$PART / auto defaults 0 1" > /mnt/etc/fstab | ||
27 | |||
28 | umount /mnt | ||
29 | |||
diff --git a/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh b/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh new file mode 100755 index 0000000..dab8fac --- /dev/null +++ b/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh | |||
@@ -0,0 +1,13 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | git_branch="$1" | ||
4 | environment="$2" | ||
5 | |||
6 | DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/") | ||
7 | DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1) | ||
8 | MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2) | ||
9 | |||
10 | cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/" | ||
11 | |||
12 | /tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment" | ||
13 | |||
diff --git a/scripts/ovh_vps_ssd/arch_host_script.sh b/scripts/ovh_vps_ssd/arch_host_script.sh new file mode 100755 index 0000000..8eecae4 --- /dev/null +++ b/scripts/ovh_vps_ssd/arch_host_script.sh | |||
@@ -0,0 +1,53 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | git_branch="$1" | ||
6 | environment="$2" | ||
7 | |||
8 | # Randomizer | ||
9 | apt-get update | ||
10 | apt-get install -y haveged | ||
11 | haveged & | ||
12 | # /Randomizer | ||
13 | |||
14 | # Prepare an arch chroot | ||
15 | cd /tmp | ||
16 | |||
17 | LATEST=$(curl -L https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1) | ||
18 | SHA1=$(echo "$LATEST" | cut -d' ' -f1) | ||
19 | NAME=$(echo "$LATEST" | cut -d' ' -f3) | ||
20 | |||
21 | curl -L -O "https://mirrors.kernel.org/archlinux/iso/latest/$NAME" | ||
22 | |||
23 | tar -xzf "$NAME" | ||
24 | |||
25 | echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/$repo/os/$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist | ||
26 | # /Prepare an arch chroot | ||
27 | |||
28 | # Prepare device information (not available in chroot) | ||
29 | DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/") | ||
30 | DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1) | ||
31 | MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2) | ||
32 | |||
33 | umount "$DEVICE" | ||
34 | UUID=$(lsblk -rno UUID "$DEVICE") | ||
35 | |||
36 | echo "$UUID" > /tmp/root.x86_64/device_uuid | ||
37 | # /Prepare device information | ||
38 | |||
39 | # Install very basic system via chroot (base git puppet) | ||
40 | cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/ | ||
41 | |||
42 | /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh | ||
43 | # /Install very basic system via chroot | ||
44 | |||
45 | # Mount and install rest of system (via puppet) | ||
46 | mount "$DEVICE" | ||
47 | |||
48 | cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/" | ||
49 | cp /tmp/puppet_variables.json "$MOUNTPOINT/root/" | ||
50 | |||
51 | /tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment" | ||
52 | # /Mount and install rest of system | ||
53 | |||
diff --git a/scripts/send_and_run.tcl b/scripts/send_and_run.tcl new file mode 100755 index 0000000..42fae62 --- /dev/null +++ b/scripts/send_and_run.tcl | |||
@@ -0,0 +1,31 @@ | |||
1 | #!/usr/bin/expect -f | ||
2 | set dest [lindex $argv 0] | ||
3 | set password [lindex $argv 1] | ||
4 | set git_branch [lindex $argv 2] | ||
5 | set environment [lindex $argv 3] | ||
6 | set script [lindex $argv 4] | ||
7 | set files [lrange $argv 4 end] | ||
8 | |||
9 | if {$password == "x"} { | ||
10 | set ask_password 0 | ||
11 | } else { | ||
12 | set ask_password 1 | ||
13 | } | ||
14 | |||
15 | set scriptname [file tail $script] | ||
16 | |||
17 | set sshopts [split "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no"] | ||
18 | |||
19 | set timeout -1 | ||
20 | spawn scp {*}$sshopts {*}$files $dest:/tmp | ||
21 | if {$ask_password} { | ||
22 | expect "assword:" | ||
23 | send "$password\n" | ||
24 | } | ||
25 | expect eof | ||
26 | spawn ssh {*}$sshopts $dest /tmp/$scriptname $git_branch $environment | ||
27 | if {$ask_password} { | ||
28 | expect "assword:" | ||
29 | send "$password\n" | ||
30 | } | ||
31 | expect eof | ||