-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_helpers.sh
More file actions
62 lines (50 loc) · 1.3 KB
/
_helpers.sh
File metadata and controls
62 lines (50 loc) · 1.3 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
# ----------------
# Helper functions
# ----------------
# Sign in to 1Password.
require_1password() {
if [[ ! $(which op) ]]; then
echo "! Please install 1Password before continuing."
exit 1
fi
# If we have a valid session there's no need to sign in again.
if $(env | grep ^OP_SESSION --quiet); then
return 0
fi
if ! $(op account list | grep my > /dev/null); then
op account add --address my.1password.com --email "$(get_email_address)"
fi
local token=$(op signin --account my --raw)
if [[ $? -ne 0 ]]; then
echo "Error: signing in to 1Password failed!"
fi
# App integration is enabled. Authentication happens via 1Password app.
if [[ -z "$token" ]]; then
return 0
else
eval $(op signin --session "$token")
fi
}
# Find user e-mail address.
get_email_address() {
local email=$(defaults read MobileMeAccounts Accounts | grep AccountID | cut -d \" -f2)
if [[ -z "$email" ]]; then
read -p "Please enter your e-mail address: " email
fi
if [[ -z "$email" ]]; then
echo "Error: please enter an e-mail address."
exit
fi
echo "$email"
}
# Run specific setup script.
do_install() {
shortname=$(basename "$1")
if [[ ! -e "$1" ]]; then
echo "! $1 not found."
exit 1
fi
echo "\033[1;32m=> \033[1;37mRunning \033[1;33m$shortname\033[1;37m...\033[0m"
cd "$DIR" > /dev/null
source "$1"
}