-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsak_github.sh
More file actions
executable file
·49 lines (40 loc) · 1.17 KB
/
sak_github.sh
File metadata and controls
executable file
·49 lines (40 loc) · 1.17 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
#!/usr/bin/env bash
PATH="/bin:/usr/bin"
age() { echo $(( $(/usr/bin/date +%s) - $(/usr/bin/date -r "$1" +%s) )); }
fetchkeys() {
# Download the keyfile to a tmp file
/usr/bin/curl -s --fail --max-time 5.5 -o "${2}.tmp" "https://github.com/${1}.keys"
if [ $? -gt 0 ]; then
/bin/cat "$2" 2>/dev/null
exit $?
else
/bin/cat "${2}.tmp" && \
/bin/mv "${2}.tmp" "${2}" && \
/usr/bin/logger -t sak_github -p info "Fetched keys for user [$1] to keyfile [$2]" && \
exit 0
/usr/bin/logger -t sak_github -p error "Failed to fetch keys for user [$1] to keyfile [$2]."
exit 1
fi
}
# Don't do checks on user accounts that don't exist locally
if ! /usr/bin/id -u "$1" >/dev/null 2>&1; then
exit 0
fi
# Map a provided user to a github user
case "$1" in
"root") gituser="tekicode";;
# Catch-all
*) gituser="tekicode";;
esac
keyfile="/var/tmp/${gituser}.pubkeys"
if [ -f "$keyfile" ]; then
ageist=$(age "$keyfile")
if [ "${ageist:-9999}" -gt 900 ]; then
/usr/bin/logger -t sak_github -p info "Refreshing pubkeys for user [$1] keys [$keyfile] age: [$ageist]"
fetchkeys "${gituser}" "$keyfile"
else
cat $keyfile 2>/dev/null
exit $?
fi
fi
fetchkeys "$gituser" "$keyfile"