|
| 1 | +#!/usr/bin/env bash |
| 2 | +# vim:ts=4:sts=4:sw=4:et |
| 3 | +# |
| 4 | +# Author: Hari Sekhon |
| 5 | +# Date: Mon Feb 22 17:42:01 2021 +0000 |
| 6 | +# |
| 7 | +# https://github.com/HariSekhon/SQL-scripts |
| 8 | +# |
| 9 | +# License: see accompanying Hari Sekhon LICENSE file |
| 10 | +# |
| 11 | +# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish |
| 12 | +# |
| 13 | +# https://www.linkedin.com/in/HariSekhon |
| 14 | +# |
| 15 | + |
| 16 | +# ============================================================================ # |
| 17 | +# D i r E n v |
| 18 | +# ============================================================================ # |
| 19 | + |
| 20 | +# https://direnv.net/man/direnv-stdlib.1.html |
| 21 | + |
| 22 | +# See Also: |
| 23 | +# |
| 24 | +# .envrc-aws |
| 25 | +# .envrc-gcp |
| 26 | +# .envrc-kubernetes |
| 27 | + |
| 28 | +# direnv stdlib - loads .envrc from parent dir up to / |
| 29 | +# |
| 30 | +# useful to accumulate parent and child directory .envrc settings eg. adding Kubernetes namespace, ArgoCD app etc. |
| 31 | +# |
| 32 | +# bypasses security authorization though - use with care |
| 33 | +#source_up |
| 34 | +# |
| 35 | +# source_up must be loaded before set -u otherwise gets this error: |
| 36 | +# |
| 37 | +# direnv: loading .envrc |
| 38 | +# /bin/bash: line 226: $1: unbound variable |
| 39 | + |
| 40 | +set -euo pipefail |
| 41 | +[ -n "${DEBUG:-}" ] && set -x |
| 42 | +srcdir="$(cd "$(dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd)" |
| 43 | + |
| 44 | +# ============================================================================ # |
| 45 | +# P r e - C o m m i t |
| 46 | +# ============================================================================ # |
| 47 | + |
| 48 | +# Automatically install Pre-Commit Git hooks if not already present |
| 49 | + |
| 50 | +if [ -f .pre-commit-config.yaml ]; then |
| 51 | + if [ -d .git ]; then |
| 52 | + if ! [ -f .git/hooks/pre-commit ]; then |
| 53 | + pre-commit install |
| 54 | + fi |
| 55 | + fi |
| 56 | +fi |
| 57 | + |
| 58 | +# ============================================================================ # |
| 59 | +# D o c k e r C o m p o s e |
| 60 | +# ============================================================================ # |
| 61 | + |
| 62 | +export COMPOSE_PROJECT_NAME="SQL-scripts" |
| 63 | + |
| 64 | +# ============================================================================ # |
| 65 | +# G i t H u b |
| 66 | +# ============================================================================ # |
| 67 | + |
| 68 | +#export GITHUB_ORGANIZATION=HariSekhon |
| 69 | + |
| 70 | +# ============================================================================ # |
| 71 | +# A n s i b l e |
| 72 | +# ============================================================================ # |
| 73 | + |
| 74 | +# use the local repo's ansible.cfg rather than: |
| 75 | +# |
| 76 | +# $PWD/ansible.cfg |
| 77 | +# ~/.ansible.cfg |
| 78 | +# /etc/ansible/ansible.cfg |
| 79 | +# |
| 80 | +# set this in project repos to ensure user environment ANSIBLE_CONFIG doesn't get used |
| 81 | +#export ANSIBLE_CONFIG="/path/to/ansible.cfg" |
| 82 | + |
| 83 | +# ============================================================================ # |
| 84 | +# C l o u d f l a r e |
| 85 | +# ============================================================================ # |
| 86 | + |
| 87 | +#export CLOUDFLARE_EMAIL=hari@... |
| 88 | +#export CLOUDFLARE_API_KEY=... # generate here: https://dash.cloudflare.com/profile/api-tokens |
| 89 | +#export CLOUDFLARE_TOKEN=... # used by cloudflare_api.sh but not by terraform module |
| 90 | + |
| 91 | +# export the variables for terraform |
| 92 | +#export TF_VAR_cloudflare_email="$CLOUDFLARE_EMAIL" |
| 93 | +#export TF_VAR_cloudflare_api_key="$CLOUDFLARE_API_KEY" # must be a key, not a token using the link above |
| 94 | + |
| 95 | +# ============================================================================ # |
| 96 | +# Python, AWS, GCP, Terraform |
| 97 | +# ============================================================================ # |
| 98 | + |
| 99 | + #.envrc-aws \ |
| 100 | + #.envrc-gcp \ |
| 101 | + #.envrc-terraform \ |
| 102 | +for envrc in \ |
| 103 | + .envrc-python \ |
| 104 | + ; do |
| 105 | + if [ -f "$srcdir/$envrc" ]; then |
| 106 | + echo |
| 107 | + echo "Loading $srcdir/$envrc" |
| 108 | + # shellcheck disable=SC1090,SC1091 |
| 109 | + . "$srcdir/$envrc" |
| 110 | + fi |
| 111 | +done |
| 112 | + |
| 113 | +# ============================================================================ # |
| 114 | +# K u b e r n e t e s |
| 115 | +# ============================================================================ # |
| 116 | + |
| 117 | +if [ -f "$srcdir/.envrc-python" ]; then |
| 118 | + echo |
| 119 | + echo "Loading $srcdir/.envrc-kubernetes" |
| 120 | + # XXX: safer to inline .envrc-kubernetes if you're worried about changes to it bypassing 'direnv allow' authorization |
| 121 | + # shellcheck disable=SC1090,SC1091 |
| 122 | + . "$srcdir/.envrc-kubernetes" docker-desktop |
| 123 | +fi |
| 124 | + |
| 125 | +# ============================================================================ # |
| 126 | + |
| 127 | +echo |
| 128 | +# read .env too |
| 129 | +#dotenv |
0 commit comments