2021-03-23 19:07:26 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
2022-09-29 21:58:48 +02:00
|
|
|
#! nix-shell -i bash -p bitwarden-cli git gnupg jq nix
|
2023-08-31 12:41:17 +02:00
|
|
|
# shellcheck shell=bash
|
2021-03-23 19:07:26 +01:00
|
|
|
|
|
|
|
# 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
|
2023-04-16 20:52:15 +02:00
|
|
|
get_doc "SysAdmin/SSH" "agenix-public" "$HOME/.ssh/agenix.pub" 644
|
|
|
|
get_doc "SysAdmin/SSH" "agenix-private" "$HOME/.ssh/agenix" 600
|
2021-03-23 19:07:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2021-04-07 19:55:26 +02:00
|
|
|
BW_SESSION="$(bw login --raw || bw unlock --raw)"
|
2021-03-23 19:07:26 +01:00
|
|
|
export BW_SESSION
|
|
|
|
|
|
|
|
get_ssh
|
|
|
|
get_pgp
|
|
|
|
}
|
|
|
|
|
|
|
|
[ -z "$NOCREDS" ] && get_creds
|
|
|
|
|
|
|
|
nix --experimental-features 'nix-command flakes' develop
|