From 6c58c57881299a2932360a7726aa6f8997476773 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 16 Oct 2018 23:15:09 -0400 Subject: more script fixes --- bin/helpers/bootstrap-tozt | 41 -------------------------------------- bin/helpers/launch-algo | 8 +------- bin/helpers/launch-tozt | 49 +++++++++++++++++++++++++++++++++++++++++++--- bin/launch | 5 +++++ bin/terminate | 7 ++++++- 5 files changed, 58 insertions(+), 52 deletions(-) delete mode 100755 bin/helpers/bootstrap-tozt (limited to 'bin') diff --git a/bin/helpers/bootstrap-tozt b/bin/helpers/bootstrap-tozt deleted file mode 100755 index 7d8ab75..0000000 --- a/bin/helpers/bootstrap-tozt +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -eux -set -o pipefail - -host="${1:-tozt.net}" -conf_location="/usr/local/share/puppet-tozt" -conf_repo="git://github.com/doy/puppet-tozt" - -remote() { - # shellcheck disable=SC2029 - ssh root@"$host" "$@" -} - -ensure_conf_exists() { - if remote test -d "$conf_location"; then - remote "cd '$conf_location' && git pull" - else - remote "mkdir -p '$conf_location'" - remote "cd '$conf_location' && git clone '$conf_repo' ." - fi - remote "cd '$conf_location' && git submodule update --init --recursive" -} - -while ! remote true; do - sleep 5 -done - -if remote test ! -e /usr/bin/pacman; then - remote apt-get -y update - remote apt-get -y install git - ensure_conf_exists - remote "cd '$conf_location/digitalocean-debian-to-arch' && bash install.sh --i_understand_that_this_droplet_will_be_completely_wiped --extra_packages 'puppet git ruby-shadow'" - sleep 30 - while ! remote true; do - sleep 30 - done -fi - -ensure_conf_exists -scp -r /mnt/puppet/ root@"$host":/usr/local/share/puppet-tozt/modules/secret/files -remote "cd '$conf_location' && puppet apply --modulepath=./modules -e 'include tozt'" diff --git a/bin/helpers/launch-algo b/bin/helpers/launch-algo index 06260b7..bf8937b 100755 --- a/bin/helpers/launch-algo +++ b/bin/helpers/launch-algo @@ -3,9 +3,6 @@ set -eu set -o pipefail script_path="$(realpath "$(dirname "$0")")" -secrets_bin="${script_path}/../secrets" - -"$secrets_bin" open cd /mnt/algo/algo git reset --hard @@ -20,9 +17,6 @@ cleanup() { if perl -e'exit 1 unless $ARGV[0] =~ m{^/tmp/launch-algo.*$}' "$envdir"; then rm -rf "$envdir" fi - - cd - "$secrets_bin" close } trap cleanup EXIT @@ -44,7 +38,7 @@ python -m pip install -r requirements.txt >> "$logfile" echo "done." echo "Running Ansible..." -do_token=$(cat /mnt/algo/algo-digitalocean) +do_token=$(cat /mnt/digitalocean) ansible-playbook main.yml -e " provider=digitalocean server_name=algo diff --git a/bin/helpers/launch-tozt b/bin/helpers/launch-tozt index 5ff8d23..acd7ed9 100755 --- a/bin/helpers/launch-tozt +++ b/bin/helpers/launch-tozt @@ -3,7 +3,9 @@ set -eu set -o pipefail echo "Creating droplet for tozt..." -id=$(doctl compute droplet create \ +id=$(doctl \ + -t "$(cat /mnt/digitalocean)" \ + compute droplet create \ tozt \ --image debian-9-x64 \ --region nyc3 \ @@ -19,10 +21,51 @@ echo "Assigning floating ip to tozt..." # XXX this returns an error for some reason, but actually succeeds: # Error: could not assign IP to droplet: json: cannot unmarshal number # 2328181259 into Go struct field Action.resource_id of type int -doctl compute floating-ip-action assign 138.197.58.11 "$id" || true +doctl \ + -t "$(cat /mnt/digitalocean)" \ + compute floating-ip-action assign + 138.197.58.11 + "$id" || true echo "Done assigning floating ip" echo "Provisioning droplet..." -"$(dirname "$0")/bootstrap-tozt" + +host="${1:-tozt.net}" +conf_location="/usr/local/share/puppet-tozt" +conf_repo="git://github.com/doy/puppet-tozt" + +remote() { + # shellcheck disable=SC2029 + ssh root@"$host" "$@" +} + +ensure_conf_exists() { + if remote test -d "$conf_location"; then + remote "cd '$conf_location' && git pull" + else + remote "mkdir -p '$conf_location'" + remote "cd '$conf_location' && git clone '$conf_repo' ." + fi + remote "cd '$conf_location' && git submodule update --init --recursive" +} + +while ! remote true; do + sleep 5 +done + +if remote test ! -e /usr/bin/pacman; then + remote apt-get -y update + remote apt-get -y install git + ensure_conf_exists + remote "cd '$conf_location/digitalocean-debian-to-arch' && bash install.sh --i_understand_that_this_droplet_will_be_completely_wiped --extra_packages 'puppet git ruby-shadow'" + sleep 30 + while ! remote true; do + sleep 30 + done +fi + +ensure_conf_exists +scp -r /mnt/puppet/ root@"$host":/usr/local/share/puppet-tozt/modules/secret/files +remote "cd '$conf_location' && puppet apply --modulepath=./modules -e 'include tozt'" echo "Done" diff --git a/bin/launch b/bin/launch index 50c2b72..ee30dba 100755 --- a/bin/launch +++ b/bin/launch @@ -2,8 +2,13 @@ set -eu set -o pipefail +script_path="$(realpath "$(dirname "$0")")" +secrets_bin="${script_path}/secrets" + case "$1" in tozt|algo) + "$secrets_bin" open + trap '"$secrets_bin" close' EXIT "$(dirname "$0")/helpers/launch-$1" ;; *) diff --git a/bin/terminate b/bin/terminate index 7631206..23aab67 100755 --- a/bin/terminate +++ b/bin/terminate @@ -2,9 +2,14 @@ set -eu set -o pipefail +script_path="$(realpath "$(dirname "$0")")" +secrets_bin="${script_path}/secrets" + case "$1" in tozt|algo) - doctl compute droplet delete "$1" + "$secrets_bin" open + trap '"$secrets_bin" close' EXIT + doctl -t "$(cat /mnt/digitalocean)" compute droplet delete "$1" ;; *) echo "unknown host $1" >&2 -- cgit v1.2.3-54-g00ecf