|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +github_token="$GITHUB_TOKEN" |
| 4 | +if [[ -z "$github_token" ]]; then |
| 5 | + echo "Please provide a GitHub token. You can create one at:" |
| 6 | + echo " https://github.com/settings/tokens/new?scopes=repo,read:user,user:email,write:packages" |
| 7 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 8 | + echo "GitHub token: " |
| 9 | + read -s github_token |
| 10 | +fi |
| 11 | + |
| 12 | +github_user_name="$GITHUB_USER_NAME" |
| 13 | +if [[ -z "$github_user_name" ]]; then |
| 14 | + github_user_name="$(git config --global user.name)" |
| 15 | +fi |
| 16 | +if [[ -z "$github_user_name" ]]; then |
| 17 | + echo "Please provide a GitHub user name. You can also configure it with:" |
| 18 | + echo " git config --global user.name \"Your Name\"" |
| 19 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 20 | + echo "GitHub user name: " |
| 21 | + read github_user_name |
| 22 | +fi |
| 23 | + |
| 24 | +github_user_email="$GITHUB_USER_EMAIL" |
| 25 | +if [[ -z "$github_user_email" ]]; then |
| 26 | + github_user_email="$(git config --global user.email)" |
| 27 | +fi |
| 28 | +if [[ -z "$github_user_email" ]]; then |
| 29 | + echo "Please provide a GitHub user email. You can also configure it with:" |
| 30 | + echo " git config --global user.email \"Your Email\"" |
| 31 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 32 | + echo "GitHub user email: " |
| 33 | + read github_user_email |
| 34 | +fi |
| 35 | + |
| 36 | +if [[ -z "$NO_GPG" ]]; then |
| 37 | + gpg_id="$GPG_ID" |
| 38 | + if [[ -z "$gpg_id" ]]; then |
| 39 | + gpg_id="$(git config --global user.signingkey)" |
| 40 | + fi |
| 41 | + if [[ -z "$gpg_id" ]]; then |
| 42 | + echo "Please provide a GPG ID. You can also configure it by following:" |
| 43 | + echo " https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key" |
| 44 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 45 | + echo "GPG ID: " |
| 46 | + read gpg_id |
| 47 | + fi |
| 48 | + if [[ -n "$gpg_id" ]]; then |
| 49 | + gpg_passphrase="$GPG_PASSPHRASE" |
| 50 | + if [[ -z "$gpg_passphrase" ]]; then |
| 51 | + echo "Please provide a GPG passphrase for the key $gpg_id." |
| 52 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 53 | + echo "GPG passphrase: " |
| 54 | + read -s gpg_passphrase |
| 55 | + fi |
| 56 | + if [[ -n "$gpg_passphrase" ]]; then |
| 57 | + gpg_key="$GPG_KEY" |
| 58 | + if [[ -z "$gpg_key" ]]; then |
| 59 | + gpg_key="$(gpg --armor --pinentry-mode=loopback --passphrase "$gpg_passphrase" --export-secret-key "$gpg_id" -w0 | base64 -w0)" |
| 60 | + fi |
| 61 | + fi |
| 62 | + fi |
| 63 | +fi |
| 64 | + |
| 65 | +if [[ -z "$NO_MATRIX" ]]; then |
| 66 | + matrix_url="$MATRIX_URL" |
| 67 | + if [[ -z "$matrix_url" ]]; then |
| 68 | + echo "Please provide a Matrix URL. For example: https://matrix-client.matrix.org/" |
| 69 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 70 | + echo "Matrix URL: " |
| 71 | + read matrix_url |
| 72 | + fi |
| 73 | + matrix_user="$MATRIX_USER" |
| 74 | + if [[ -z "$matrix_user" ]]; then |
| 75 | + echo "Please provide a Matrix username." |
| 76 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 77 | + echo "Matrix username: " |
| 78 | + read matrix_user |
| 79 | + fi |
| 80 | + |
| 81 | + matrix_password="$MATRIX_PASSWORD" |
| 82 | + if [[ -z "$matrix_password" ]]; then |
| 83 | + echo "Please provide a Matrix password." |
| 84 | + echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later." |
| 85 | + echo "Matrix password: " |
| 86 | + read -s matrix_password |
| 87 | + fi |
| 88 | +fi |
| 89 | + |
| 90 | +export GITHUB_TOKEN="$github_token" |
| 91 | +export GITHUB_USER_NAME="$github_user_name" |
| 92 | +export GITHUB_USER_EMAIL="$github_user_email" |
| 93 | + |
| 94 | +export NO_GPG="$NO_GPG" |
| 95 | +export GPG_ID="$gpg_id" |
| 96 | +export GPG_PASSPHRASE="$gpg_passphrase" |
| 97 | +export GPG_KEY="$gpg_key" |
| 98 | + |
| 99 | +export NO_MATRIX="$NO_MATRIX" |
| 100 | +export MATRIX_URL="$matrix_url" |
| 101 | +export MATRIX_USER="$matrix_user" |
| 102 | +export MATRIX_PASSWORD="$matrix_password" |
| 103 | + |
| 104 | + |
| 105 | +# cat $ENV_TEMPLATE or fall back to .env.template |
| 106 | +cat "${ENV_TEMPLATE:-.env.template}" | envsubst > .env |
0 commit comments