-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
124 lines (99 loc) · 3.84 KB
/
bootstrap.sh
File metadata and controls
124 lines (99 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
# This file is specifically written for usage with Github Codespaces
# see more details here:
# https://docs.github.com/en/codespaces/setting-your-user-preferences/personalizing-github-codespaces-for-your-account#dotfiles
set -euo pipefail
trap 'echo "[dotfiles-bootstrap] error line $LINENO" >&2' ERR
export AWS_PAGER=""; export DEBIAN_FRONTEND=noninteractive
# Set DOTFILES_ROOT to the location of your dotfiles repo in the Codespace
# NOTE if there was an error cloning the dotfiles repo, check logs here:
# /workspaces/.codespaces/.persistedshare/EnvironmentLog.txt
DOTFILES_ROOT="${DOTFILES_ROOT:-/workspaces/.codespaces/.persistedshare/dotfiles}"
log(){ printf '[dotfiles-bootstrap] %s\n' "$*"; }
setup_aws(){
log "setting up AWS CLI bits"
mkdir -p "${HOME}/.aws"
cfg="${HOME}/.aws/config"
[[ -f "$cfg" ]] || : > "$cfg"
grep -q '^\[default\]' "$cfg" 2>/dev/null || cat >>"$cfg" <<CFG
[default]
region = ${AWS_DEFAULT_REGION:-us-east-1}
output = json
CFG
# ## corp AWS SSO profile setup (disabled for now, kept for reference)
# # Warn on missing critical envs (non-fatal)
# [[ -n "${AWS_SSO_START_URL:-}" ]] || log "WARN: AWS_SSO_START_URL is empty"
# [[ -n "${AWS_ROLE_NAME_DEV:-}" ]] || log "WARN: AWS_ROLE_NAME_DEV is empty"
# grep -q '^\[sso-session groupsense\]' "$cfg" 2>/dev/null || cat >>"$cfg" <<CFG
# [sso-session groupsense]
# sso_start_url = ${AWS_SSO_START_URL:-}
# sso_region = ${AWS_SSO_REGION:-us-east-1}
# sso_registration_scopes = sso:account:access
# CFG
# grep -q '^\[profile gs-tl\]' "$cfg" 2>/dev/null || cat >>"$cfg" <<CFG
# [profile gs-tl]
# sso_session = groupsense
# sso_account_id = ${AWS_ACCOUNT_ID_TL:-}
# sso_role_name = ${AWS_ROLE_NAME_DEV:-}
# region = ${AWS_DEFAULT_REGION:-us-east-1}
# output = json
# CFG
# grep -q '^\[profile gs-br\]' "$cfg" 2>/dev/null || cat >>"$cfg" <<CFG
# [profile gs-br]
# sso_session = groupsense
# sso_account_id = ${AWS_ACCOUNT_ID_BR:-}
# sso_role_name = ${AWS_ROLE_NAME_DEV:-}
# region = ${AWS_DEFAULT_REGION:-us-east-1}
# output = json
# CFG
# grep -q '^\[profile example\]' "$cfg" 2>/dev/null || cat >>"$cfg" <<CFG
# [profile example]
# sso_session = groupsense
# sso_account_id = ${AWS_ACCOUNT_ID_DEV:-}
# sso_role_name = ${AWS_ROLE_NAME_DEV:-}
# region = ${AWS_DEFAULT_REGION:-us-east-1}
# output = json
# CFG
chmod 700 "${HOME}/.aws" || true
chmod 600 "$cfg" || true
}
# setup_aws_helpers(){
# # Add a device-code alias; idempotent
# local rc
# if [[ -n "${ZSH_VERSION:-}" ]]; then rc="$HOME/.zshrc"; else rc="$HOME/.bashrc"; fi
# local line="alias aws-sso-login='aws sso login --use-device-code --no-browser'"
# grep -Fqx "$line" "$rc" 2>/dev/null || echo "$line" >> "$rc"
# }
# check_aws_sso(){
# command -v aws >/dev/null 2>&1 || { log "aws missing"; return 0; }
# timeout 5s AWS_PROFILE=example aws sts get-caller-identity >/dev/null 2>&1 \
# && log "AWS SSO active for profile 'example'" \
# || log "Not logged in. Run: aws sso login --sso-session groupsense --use-device-code"
# }
setup_aliases(){
log "setting up aliases"
local rc
if [[ -n "${ZSH_VERSION:-}" ]]; then rc="$HOME/.zshrc"; else rc="$HOME/.bashrc"; fi
local line="alias ll='ls -alFh'"
grep -Fqx "$line" "$rc" 2>/dev/null || echo "$line" >> "$rc"
}
link_dotfile() {
# symlink a file from your dotfiles repo to the Codespaces home dir
local src="$DOTFILES_ROOT/$1"
local dst="$HOME/$1"
[[ -e "$src" ]] || { log "skip link $1 (missing $src)"; return 0; }
[ -e "$src" ] || return 0
mkdir -p "$(dirname "$dst")"
ln -sfn "$src" "$dst" && log "successfully symlinked $src -> $dst"
}
on_create(){
log "[dotfiles-bootstrap] create phase"
setup_aws
setup_aliases
#setup_aws_helpers
# symlink in select files from dotfiles repo into the Codespaces home dir
link_dotfile .gitconfig
link_dotfile .vimrc
}
on_create || true
exit 0