|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +if [[ $# -lt 1 ]]; then |
| 6 | + echo "Usage: $0 <coder URL>" |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +# Allow toggling verbose output |
| 11 | +[[ -n ${VERBOSE:-} ]] && set -x |
| 12 | + |
| 13 | +CODER_URL=$1 |
| 14 | +CONFIG_DIR="${PWD}/.coderv2" |
| 15 | +ARCH="$(arch)" |
| 16 | +PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')" |
| 17 | + |
| 18 | +mkdir -p "${CONFIG_DIR}" |
| 19 | +echo "Fetching Coder CLI for first-time setup!" |
| 20 | +curl -fsSL "${CODER_URL}/bin/coder-${PLATFORM}-${ARCH}" -o "${CONFIG_DIR}/coder" |
| 21 | +chmod +x "${CONFIG_DIR}/coder" |
| 22 | + |
| 23 | +set +o pipefail |
| 24 | +RANDOM_ADMIN_PASSWORD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c16) |
| 25 | +set -o pipefail |
| 26 | +CODER_FIRST_USER_EMAIL="admin@coder.com" |
| 27 | +CODER_FIRST_USER_USERNAME="coder" |
| 28 | +CODER_FIRST_USER_PASSWORD="${RANDOM_ADMIN_PASSWORD}" |
| 29 | +CODER_FIRST_USER_TRIAL=false |
| 30 | +echo "Running login command!" |
| 31 | +${CONFIG_DIR}/coder login "${CODER_URL}" \ |
| 32 | + --global-config="${CONFIG_DIR}" \ |
| 33 | + --first-user-username="${CODER_FIRST_USER_USERNAME}" \ |
| 34 | + --first-user-email="${CODER_FIRST_USER_EMAIL}" \ |
| 35 | + --first-user-password="${CODER_FIRST_USER_PASSWORD}" \ |
| 36 | + --first-user-trial=false |
| 37 | + |
| 38 | +echo "Writing credentials to coder.env" |
| 39 | +cat <<EOF > ./coder.env |
| 40 | +CODER_FIRST_USER_EMAIL=admin@coder.com |
| 41 | +CODER_FIRST_USER_USERNAME=coder |
| 42 | +CODER_FIRST_USER_PASSWORD="${RANDOM_ADMIN_PASSWORD}" |
| 43 | +CODER_FIRST_USER_TRIAL=false |
| 44 | +EOF |
| 45 | + |
| 46 | +echo "Importing kubernetes template" |
| 47 | +"${CONFIG_DIR}/coder" templates create --global-config="${CONFIG_DIR}" \ |
| 48 | + --directory "${CONFIG_DIR}/templates/kubernetes" --yes kubernetes |
0 commit comments