#!/usr/bin/env bash set -o errexit set -o pipefail set -o xtrace if [ $(dpkg --print-architecture) = "amd64" ]; then ARCH="amd64" else ARCH="arm64" fi function waitfor_boot_finished { export DEBIAN_FRONTEND=noninteractive echo "args: ${ARGS}" # Wait for cloudinit on the surrogate to complete before making progress while [[ ! -f /var/lib/cloud/instance/boot-finished ]]; do echo 'Waiting for cloud-init...' sleep 1 done } function install_packages { apt-get update && sudo apt-get install software-properties-common e2fsprogs nfs-common -y add-apt-repository --yes --update ppa:ansible/ansible && sudo apt-get install ansible -y ansible-galaxy collection install community.general } function execute_playbook { tee /etc/ansible/ansible.cfg </dev/null LOCALE_ARCHIVE=/usr/lib/locale/locale-archive LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" LC_ALL="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" EOF } function setup_locale { cat <>/etc/locale.gen en_US.UTF-8 UTF-8 EOF cat </etc/default/locale LANG="C.UTF-8" LC_CTYPE="C.UTF-8" EOF locale-gen en_US.UTF-8 } sed -i 's/- hosts: all/- hosts: localhost/' ansible/playbook.yml waitfor_boot_finished install_packages setup_postgesql_env setup_locale execute_playbook #################### # stage 2 things #################### function install_nix() { sudo su -c "curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm \ --extra-conf \"substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com\" \ --extra-conf \"trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=\" " -s /bin/bash root . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh } function execute_stage2_playbook { sudo tee /etc/ansible/ansible.cfg <