-
Notifications
You must be signed in to change notification settings - Fork 0
/
gofed-notify.sh
executable file
·116 lines (104 loc) · 2.85 KB
/
gofed-notify.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
#!/bin/bash
#
# gofed-notify.sh - a simple notify script for gofed
# Copyright (C) 2015 Fridolin Pokorny, <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# ####################################################################
#set -x
VERSION="v0.1"
# Output file
FOUT="/dev/stdout"
# Recipients
declare -A EMAIL
# Subject used in email; adjust if needed or run with:
# GOFED_NOTIFY_SUBJECT="Custom subject" gofed-notify.sh email email@me
[ -z ${GOFED_NOTIFY_SUBJECT+x} ] && \
SUBJECT="[gofed-notify]: Update log from `date '+%F %H:%M'`"
# My name
PROG=`basename $0`
function printHelp {
echo "$1 - A simple notify script for gofed"
echo "Synopsis: $1 command [arg1 [arg2 ...]]"
echo ""
echo "command:"
echo " email notify via e-mail"
echo " print print update to stdout or a file"
echo ""
echo "$VERSION"
}
function printHelpPrint {
echo "Usage: $1 [FILE]"
echo ""
echo " FILE"
echo " output file; otherwise stdout is used"
}
function printHelpEmail {
echo "Usage: $1 OPTION [DST]"
echo ""
echo "Available options:"
echo " email"
echo " send e-mail report to DST, DST is list of recipients (required)"
echo " print"
echo " log report to file DST (if DST is not present, stdout is used)"
}
function doUpdate {
echo -e ">>> New packages scan:\n" && \
gofed scan-packages -n 2>&1 && \
echo -e "\n>>> Add new packages to database:\n" && \
gofed scan-packages -u 2>&1 && \
echo -e "\n>>> Update local database:\n" && \
gofed scan-imports -c 2>&1
return $?
}
case "$1" in
"help")
shift
printHelp "${PROG}"
exit 0
;;
"email")
shift
[ "$1" == "-h" -o "$1" == "--help" ] && {
printHelpEmail "${PROG}"
exit 0
}
[ -z "$*" ] && { printHelp "${PROG}"; exit 1; }
EMAIL=$@
;;
"print")
shift
[ "$1" == "-h" -o "$1" == "--help" ] && {
printHelpPrint "${PROG}"
exit 0
}
[ -n "$1" ] && { FOUT="$1"; truncate -s 0 "${FOUT}"; shift; }
[ -n "$*" ] && { printHelp "${PROG}"; exit 1; }
;;
*)
printHelp "${PROG}"
exit 1
;;
esac
OUTPUT="$(doUpdate)"
RET=$?
echo "${SUBJECT}" >> "${FOUT}"
echo "${OUTPUT}" >> "${FOUT}"
for rec in ${EMAIL}; do
echo ">>> Sending log to '${rec}'"
echo "${OUTPUT}" | mailx -s "$SUBJECT" "$rec"
done
exit ${RET} # bye!