diff --git a/scripts/cert-gating.sh b/scripts/cert-gating.sh index 4067e978d..e6882a8a7 100755 --- a/scripts/cert-gating.sh +++ b/scripts/cert-gating.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash +source $(dirname $0)/utils.sh basepath=$HOME/.storj/capt alpha_config=$basepath/config-alpha.yaml unauthorized_config=$basepath/config-unauthorized.yaml @@ -7,69 +8,75 @@ ca_count=5 ca_basepath=$basepath/ca-alpha- ca_i_basepath() { - echo "$ca_basepath$1" + echo ${ca_basepath}${1} } + rand_ca_basepath() { - let i="($RANDOM % $ca_count) + 1" - echo $(ca_i_basepath $i) + let i="($RANDOM % $ca_count) + 1" + echo $(ca_i_basepath ${i}) } case $1 in - --help) - echo "usage: $(basename $0) [setup|alpha|unauthorized]" - ;; - setup) - echo "setting up captplanet" - captplanet setup --overwrite - echo "clearing whitelist" - echo > $ca_whitelist - echo -n "generating alpha certificate authorities.." - for i in $(seq 1 $ca_count); do - echo -n "$i.." - _basepath=$(ca_i_basepath $i) - identity ca new --ca.overwrite \ - --ca.cert-path $_basepath.cert \ - --ca.key-path $_basepath.key - cat $_basepath.cert >> $ca_whitelist - done - echo "done" - echo -n "generating alpha identities" - for dir in $basepath/{f*,sat*,up*}; do - echo -n "." - _ca_basepath=$(rand_ca_basepath) - _ca_cert=$dir/ca-alpha.cert - _ca_key=$dir/ca-alpha.key - identity ca new --ca.overwrite \ - --ca.cert-path $_ca_cert \ - --ca.key-path $_ca_key \ - --ca.parent-cert-path $_ca_basepath.cert \ - --ca.parent-key-path $_ca_basepath.key - identity id new --identity.overwrite \ - --identity.cert-path $dir/identity-alpha.cert \ - --identity.key-path $dir/identity-alpha.key \ - --ca.cert-path $_ca_cert \ - --ca.key-path $_ca_key - done - echo "done" - echo "writing alpha config" - cat $basepath/config.yaml | \ - sed "s,peer-ca-whitelist-path: \"\",peer-ca-whitelist-path: $ca_whitelist,g" | \ - sed -E 's,cert-path: (.+)\.cert,cert-path: \1-alpha.cert,g' | \ - sed -E 's,key-path: (.+)\.key,key-path: \1-alpha.key,g' \ - > $alpha_config - echo "writing unauthorized config" - cat $basepath/config.yaml | sed -E "s,peer-ca-whitelist-path: \"\",peer-ca-whitelist-path: $ca_whitelist,g" > "$unauthorized_config" - ;; - alpha) - captplanet run --config $alpha_config - ;; - unauthorized) - captplanet run --config $unauthorized_config - ;; - run) - captplanet run - ;; - *) - $0 --help - ;; + --help) + echo "usage: $(basename $0) [setup|alpha|unauthorized]" + ;; + setup) + temp_build captplanet identity + echo "setting up captplanet" + "$captplanet" setup --overwrite + echo "clearing whitelist" + echo > ${ca_whitelist} + echo -n "generating alpha certificate authorities.." + for i in $(seq 1 ${ca_count}); do + echo -n "$i.." + _basepath=$(ca_i_basepath ${i}) + ${identity} ca new --ca.overwrite \ + --ca.cert-path ${_basepath}.cert \ + --ca.key-path ${_basepath}.key + cat ${_basepath}.cert >> ${ca_whitelist} + done + echo "done" + echo -n "generating alpha identities" + for dir in ${basepath}/{f*,sat*,up*}; do + echo -n "." + _ca_basepath=$(rand_ca_basepath) + _ca_cert=${dir}/ca-alpha.cert + _ca_key=${dir}/ca-alpha.key + ${identity} ca new --ca.overwrite \ + --ca.cert-path ${_ca_cert} \ + --ca.key-path ${_ca_key} \ + --ca.parent-cert-path ${_ca_basepath}.cert \ + --ca.parent-key-path ${_ca_basepath}.key + ${identity} id new --identity.overwrite \ + --identity.cert-path ${dir}/identity-alpha.cert \ + --identity.key-path ${dir}/identity-alpha.key \ + --ca.cert-path ${_ca_cert} \ + --ca.key-path ${_ca_key} + done + echo "done" + echo "writing alpha config" + cat ${basepath}/config.yaml | \ + sed "s,peer-ca-whitelist-path: \"\",peer-ca-whitelist-path: $ca_whitelist,g" | \ + sed -E 's,cert-path: (.+)\.cert,cert-path: \1-alpha.cert,g' | \ + sed -E 's,key-path: (.+)\.key,key-path: \1-alpha.key,g' \ + > ${alpha_config} + echo "writing unauthorized config" + cat ${basepath}/config.yaml | sed -E "s,peer-ca-whitelist-path: \"\",peer-ca-whitelist-path: $ca_whitelist,g" >"$unauthorized_config" + ;; + alpha) + build captplanet + ${captplanet} run --config ${alpha_config} + ;; + unauthorized) + build captplanet + ${captplanet} run --config ${unauthorized_config} + ;; + run) + ${captplanet} run + ;; + *) + $@ --help + ;; esac + +rm -rf ${tmp_dir} diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 000000000..1bade2172 --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +dots() { + echo -n "." + sleep 1 + dots +} + +dots_on() { + dots & + dots_pid=$! +} + +dots_off() { + disown $dots_pid + kill "$dots_pid" +} + +build() { + local tmp_dir=$1 + shift + echo "building temp binaries:" + for cmd in $@; do + echo -n " building $cmd..." + dots_on + local path=${tmp_dir}/${cmd} + declare -g ${cmd}=${path} + go build -o ${path} storj.io/storj/cmd/${cmd} + dots_off + echo "done" + done + echo " binaries built in $tmp_dir" +} + +temp_build() { + tmp_dir=$(mktemp -d) + build ${tmp_dir} $@ +} + +check_help() { + if [ $1 == "--help" ] || [ $1 == "-h" ]; then + echo $2 + exit 0 + fi +} + +ensure_dir() { + if [ ! -d $1 ]; then + mkdir $1 + fi +} + +no_overwrite() { + if [ -e $1 ]; then + echo "Error: $1 already exists; refusing to overwrite" + exit 10 + fi +} + +log_list() { + for f in $@; do + echo ${f} + done +} diff --git a/scripts/waitlist/storj.sh b/scripts/waitlist/storj.sh new file mode 100755 index 000000000..0e0c63caa --- /dev/null +++ b/scripts/waitlist/storj.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +source $(dirname $0)/../utils.sh + +comment() { + cat << EOF +-----BEGIN COMMENT----- +Label: $1 +Description: $2 +-----END COMMENT----- +EOF +} + +case $1 in + --help) + echo "usage: $0 new" + ;; + new) + shift + check_help $1 "usage: storj.sh new