-
Notifications
You must be signed in to change notification settings - Fork 2
/
pre-commit
executable file
·69 lines (56 loc) · 1.98 KB
/
pre-commit
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
#!/usr/bin/env -S bash -i
account="[email protected]"
get_user() {
secret-tool search account ${account} 2>&1 | \
grep -E "^attribute\.UserName" | \
cut -d " " -f3
}
get_pass() {
secret-tool search account ${account} 2>&1 | \
grep -E "^secret" | \
cut -d " " -f3
}
get_managesieve_port() {
secret-tool search account ${account} 2>&1 | \
grep -E "^attribute\.managesieve_port" | \
cut -d " " -f3
}
get_managesieve_addr() {
secret-tool search account ${account} 2>&1 | \
grep -E "^attribute\.managesieve_addr" | \
cut -d " " -f3
}
main() {
# Since I use centralized hooks, I need to ensure that this one only runs in the sieve-susede repository
[[ "$(basename $(git rev-parse --show-toplevel))" == "sieve-susede" ]] || {
echo -e "Skipped\n"
return 0
}
# If sieveshell is not installed skip this check w/o blocking the commit
type sieveshell >/dev/null 2>&1 || return 0
# Push all the *.sieve files in this repo to the managesieve server
find $(git rev-parse --show-toplevel) -type f -name "*.sieve" -printf "put %p %f\n" | sort -nr | \
sieveshell --user $(get_user) \
--passwd $(get_pass) \
--use-tls \
--port $(get_managesieve_port) \
$(get_managesieve_addr)
# Check if 00-Init is active, otherwise activate it
if ! echo "list" | sieveshell \
--user $(get_user) \
--passwd $(get_pass) \
--use-tls \
--port $(get_managesieve_port) \
$(get_managesieve_addr) | \
grep > /dev/null 2>&1 "00-Init.sieve[[:space:]]*<<--[[:space:]]*active"; then
# Activate 00-Init.sieve
echo >&2 "[*] Activating 00-Init.sieve"
echo "activate 00-Init.sieve" | \
sieveshell --user $(get_user) \
--passwd $(get_pass) \
--use-tls \
--port $(get_managesieve_port) \
$(get_managesieve_addr)
fi
}
main