-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap-weechat.sh
executable file
·136 lines (114 loc) · 3.97 KB
/
bootstrap-weechat.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
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
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
run_weechat_commands() {
while read -r line; do
set -- "$@" -r "$line"
done
weechat -a "$@" -r '/quit' </dev/tty
}
escape_semicolons() {
sed -e 's/;/\\;/g'
}
expand_keepass() {
keepass_args=$1
keepass_args=${keepass_args#'(keepass '}
keepass_args=${keepass_args%')'}
set -f
IFS=' ' # a space and a tab
# `$keepass_args` should contain two space-separated arguments; the
# attribute and the entry name
# shellcheck disable=SC2016,SC2086
keepassxc-cli show "$keepass_db" -sa $keepass_args </dev/tty |
sed -e 's/\$/${raw:$}/g'
}
expand_or_escape_dollars() {
while IFS= read -r line; do
IFS=\$
set -f
set -- $line''
# $keepass_db not given; skip lines that contain $(keepass ...)
if [ -z "$keepass_db" ]; then
# the first argument does not have a dollar sign preceding it
has_dollar=false
for part; do
if $has_dollar; then
case "$part" in
'(keepass '*) continue 2
esac
fi
has_dollar=true
done
fi
printf '%s' "$1"
shift
for part; do
case "$part" in
'(keepass '*)
trailing=${part#(*)}
expand_keepass "${part%"$trailing"}"
printf '%s' "$trailing"
;;
'eval:'*) printf '$%s' "${part#'eval:'}" ;;
*) printf '${raw:$}%s' "$part" ;;
esac
done
printf '\n'
done
}
import_weechat() {
# filter out empty lines and comments (lines starting with a '#')
grep -v -e '^[ \t]*$' -e '^[ \t]*#' |
expand_or_escape_dollars |
escape_semicolons |
run_weechat_commands
}
usage() {
printf 'usage: %s -h\n' "$0"
printf ' %s [-k KEEPASS_DB]\n' "$0"
exit "${1-0}"
}
while getopts 'hk:' flag; do
case "$flag" in
k) keepass_db="$OPTARG" ;;
h) usage ;;
*) usage 1 ;;
esac
done
if [ -n "$keepass_db" ]; then
mkdir ~/.secrets
chmod 0700 ~/.secrets
keepassxc-cli attachment-export "$keepass_db" irc.oftc.net \
oftc.pem ~/.secrets/oftc.pem
fi
# TODO: change `irc.default_server.username` and `irc.default_server.nicks`
# TODO: try using `keepasxc-proxy` to avoid typing my password 6 separate times
# TODO: try using `keepasxc-proxy` somehow as WEECHAT_PASSPHRASE
# TODO: try using `keepasxc-proxy` to get the credentials directly and skip the
# weechat secure storage alltogether
# also see: https://gist.github.com/pascalpoitras/8406501
import_weechat <<'EOF'
/mouse enable
/set irc.look.server_buffer independent
/set irc.look.new_pv_position near_server
/set irc.look.new_channel_position near_server
/set weechat.plugin.autoload "*,!ruby,!tcl,!guile,!perl,!lua,!spell"
/set logger.level.irc 3
/set logger.file.path ${env:HISTDIR}/weechat
/secure passphrase $(keepass password Weechat)
/secure set libera_pass $(keepass password irc.libera.chat)
/secure set libera_user $(keepass username irc.libera.chat)
/secure set libera_nicks $(keepass nicknames irc.libera.chat)
/secure set oftc_cert_pass $(keepass cert-password irc.oftc.net)
/secure set oftc_nicks $(keepass nicknames irc.oftc.net)
/server add libera irc.libera.chat/6697 -ssl -ssl_verify -autoconnect
/set irc.server.libera.nicks ${sec.data.libera_nicks}
/set irc.server.libera.sasl_mechanism PLAIN
/set irc.server.libera.sasl_username ${sec.data.libera_user}
/set irc.server.libera.sasl_password ${sec.data.libera_pass}
/set irc.server.libera.autojoin "#archlinux,#foot,#fennel,#neovim"
/server add oftc irc.oftc.net/6697 -ssl -ssl_verify -autoconnect
/set irc.server.oftc.nicks ${sec.data.oftc_nicks}
/set irc.server.oftc.ssl_cert "~/.secrets/oftc.pem"
/set irc.server.oftc.ssl_password ${sec.data.oftc_cert_pass}
/set irc.server.oftc.autojoin "#alpine-linux,#suckless"
/filter addreplace irc_smart * irc_smart_filter *
EOF