server.garden privileged automation agent (mirror of https://git.sequentialread.com/forest/rootsystem)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
3.0 KiB

#!/bin/bash -e
rm -rf build
mkdir -p build/servergarden-rootsystem
mkdir -p build/servergarden-rootsystem/host-key-poller
mkdir -p build/servergarden-rootsystem/ansible-wrapper
GOOS=linux GOARCH=arm go build -o build/servergarden-rootsystem/rootsystem *.go
GOOS=linux GOARCH=arm go build -o build/servergarden-rootsystem/host-key-poller/host-key-poller host-key-poller/*.go
GOOS=linux GOARCH=arm go build -o build/servergarden-rootsystem/ansible-wrapper/ansible-playbook-wrapper ansible-wrapper/*.go
cp -r ansible-wrapper/callback_plugins build/servergarden-rootsystem/ansible-wrapper/callback_plugins
cp ansible-wrapper/ansible.cfg build/servergarden-rootsystem/ansible-wrapper/ansible.cfg
cp -r terraform-modules build/servergarden-rootsystem/terraform-modules
cp -r ansible-roles build/servergarden-rootsystem/ansible-roles
cp -r application-modules build/servergarden-rootsystem/application-modules
#remove symlinks/log files that rootsystem adds at runtime.
rm -f build/servergarden-rootsystem/terraform-modules/*/roles
rm -f build/servergarden-rootsystem/terraform-modules/*/ansible.cfg
rm -f build/servergarden-rootsystem/terraform-modules/*/ansible-playbook-wrapper
rm -f build/servergarden-rootsystem/terraform-modules/*/callback_plugins
rm -f build/servergarden-rootsystem/terraform-modules/*/ansible-log.json
rm -f build/servergarden-rootsystem/terraform-modules/*/ansible.log
cp ReadMe.md build/servergarden-rootsystem/ReadMe.md
cd build
tar "--exclude=.git" "--exclude=__pycache__" "--exclude=*.crt" "--exclude=*.key" -czvf servergarden-rootsystem-arm.tar.gz servergarden-rootsystem
cd ../
FILE_PATH="servergarden-rootsystem-arm.tar.gz"
FILE_NAME="build/servergarden-rootsystem-arm.tar.gz"
BUCKET_NAME="server-garden-artifacts"
AUTH_JSON="$(curl -sS -u "$BACKBLAZE_CRED" https://api.backblazeb2.com/b2api/v2/b2_authorize_account)"
API_URL="$(echo "$AUTH_JSON" | grep -E -o '"apiUrl": "([^"]+)"' | sed -E 's|"apiUrl": "([^"]+)"|\1|')"
ACCOUNT_ID="$(echo "$AUTH_JSON" | grep -E -o '"accountId": "([^"]+)"' | sed -E 's|"accountId": "([^"]+)"|\1|')"
AUTH_TOKEN="$(echo "$AUTH_JSON" | grep -E -o '"authorizationToken": "([^"]+)"' | sed -E 's|"authorizationToken": "([^"]+)"|\1|')"
LIST_BUCKETS_JSON="$(curl -sS -H "Authorization: $AUTH_TOKEN" "$API_URL/b2api/v2/b2_list_buckets?accountId=$ACCOUNT_ID&bucketName=$BUCKET_NAME" )"
BUCKET_ID="$(echo "$LIST_BUCKETS_JSON" | grep -E -o '"bucketId": "([^"]+)"' | sed -E 's|"bucketId": "([^"]+)"|\1|')"
UPLOAD_URL_JSON="$(curl -sS -H "Authorization: $AUTH_TOKEN" "$API_URL/b2api/v2/b2_get_upload_url?bucketId=$BUCKET_ID" )"
UPLOAD_URL="$(echo "$UPLOAD_URL_JSON" | grep -E -o '"uploadUrl": "([^"]+)"' | sed -E 's|"uploadUrl": "([^"]+)"|\1|')"
AUTH_TOKEN="$(echo "$UPLOAD_URL_JSON" | grep -E -o '"authorizationToken": "([^"]+)"' | sed -E 's|"authorizationToken": "([^"]+)"|\1|')"
CONTENT_SHA1="$(cat "$FILE_NAME" | sha1sum | awk '{ print $1 }')"
curl -sS -X POST \
2 years ago
-H "Authorization: $AUTH_TOKEN" \
-H "X-Bz-File-Name: $FILE_PATH" \
-H "X-Bz-Content-Sha1: $CONTENT_SHA1" \
-H "Content-Type: text/plain" \
"$UPLOAD_URL" --data-binary @"$FILE_NAME"