-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·92 lines (71 loc) · 1.97 KB
/
bootstrap.sh
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
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p bitwarden-cli git gnupg jq nix
# shellcheck shell=bash
# Command failure is script failure
set -e
BOLD_RED="\e[0;1;31m"
BOLD_BLUE="\e[0;1;34m"
BOLD_GREEN="\e[0;1;32m"
RESET="\e[0m"
BW_SESSION=""
warn() {
echo -e "${BOLD_RED}$1${RESET}"
}
info() {
echo -e "${BOLD_BLUE}$1${RESET}"
}
success() {
echo -e "${BOLD_GREEN}$1${RESET}"
}
set_perm() {
# $1: destination
# $2: permissions
chmod "$2" "$1" && success "--> Set permission of $1 to $2"
}
get_doc() {
# $1: name of folder which contains the wanted document
# $2: name of the document
# $3: destination
# $4: permissions
local FOLDER_ID
local NOTES
FOLDER_ID="$(bw list folders |
jq '.[] | select(.name == "'"$1"'") | .id' |
cut -d'"' -f2)"
NOTES="$(bw list items --folderid "$FOLDER_ID" |
jq '.[] | select(.name == "'"$2"'") | .notes' |
cut -d'"' -f2)"
printf "%b" "$NOTES" > "$3"
set_perm "$3" "$4"
}
get_ssh() {
mkdir -p "$HOME/.ssh" && info "-> Creating .ssh folder."
chmod 700 "$HOME/.ssh" && info "--> Modifying permissions of .ssh folder."
get_doc "SysAdmin/SSH" "shared-key-public" "$HOME/.ssh/shared_rsa.pub" 644
get_doc "SysAdmin/SSH" "shared-key-private" "$HOME/.ssh/shared_rsa" 600
get_doc "SysAdmin/SSH" "agenix-public" "$HOME/.ssh/agenix.pub" 644
get_doc "SysAdmin/SSH" "agenix-private" "$HOME/.ssh/agenix" 600
}
get_pgp() {
local KEY
KEY=key.asc
get_doc "SysAdmin/PGP" "pgp-key-private" "$KEY" 644
gpg \
--pinentry-mode loopback \
--import "$KEY"
printf '5\ny\n' |
gpg \
--command-fd 0 \
--pinentry-mode loopback \
--edit-key 'Bruno BELANYI' \
trust
rm "$KEY"
}
get_creds() {
BW_SESSION="$(bw login --raw || bw unlock --raw)"
export BW_SESSION
get_ssh
get_pgp
}
[ -z "$NOCREDS" ] && get_creds
nix --experimental-features 'nix-command flakes' develop