-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_after_onchange_10-configure-1password.sh.tmpl
49 lines (43 loc) · 2.09 KB
/
run_after_onchange_10-configure-1password.sh.tmpl
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
#!/bin/sh
# ---------------------------------------------------------------------------- #
# Unofficial Bash Strict Mode #
# ---------------------------------------------------------------------------- #
# See http://redsymbol.net/articles/unofficial-bash-strict-mode/
# -e: exit on error
# -u: exit on unset variables
# -o pipefail: prevents errors in a pipeline from being masked
set -euo pipefail
# IFS (Internal Field Separator): controls what Bash calls word splitting.
# When set to a string, each character in the string is considered by Bash to separate words
IFS=$'\n\t'
# ----------------------------------- Logs ----------------------------------- #
log_color() {
wait
color_code="$1"
shift
printf "\033[${color_code}m%s\033[0m\n" "$*" >&2 }
# -------------------------------- Log colours ------------------------------- #
log_blue() { log_color "0;34" "$@" ; }
log_green() { log_color "0;32" "$@" ; }
log_orange() { log_color "0;33" "$@" ; }
log_red() { log_color "0;31" "$@" ; }
# --------------------------------- Log state -------------------------------- #
log_error() { log_red "❌ $@" ; }
log_success() { log_green "✅ $@" ; }
log_task() { log_blue "🔃 $@" ; }
log_warning() { log_orange "⚠️ $@" ; }
# ---------------------------- Log exit functions ---------------------------- #
error() { log_error "$@" ; exit 1 ; }
success() { log_success "$@" ; exit 0 ; }
# ---------------------------------------------------------------------------- #
# Script #
# ---------------------------------------------------------------------------- #
log_task "[1password] SETUP"
# ------------------ Exit if this is not a personal machine ------------------ #
{{- if not .personal -}}
return 0
{{- end -}}
# ---------------------- Add 1Password acount and signin --------------------- #
op account add --address {{ .op_domain }}.1password.com --email {{ .op_email | quote }} --secret-key {{ .op_secret | quote }}
eval $(op signin --account {{ .op_domain }})
log_success "[1password] DONE"