Debian Codegraph @

libexec/container/log

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Copyright (C) 2014-2026 Daniel Baumann <[email protected]>
4 #
5 # SPDX-License-Identifier: GPL-3.0+
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 set -e
21
22 PROJECT="open-infrastructure"
23 SOFTWARE="compute-tools"
24 PROGRAM="container"
25 COMMAND="$(basenamescip-shell system . . basename. ${0})"
26
27 HOOKS="/etc/${SOFTWARE}/hooks"
28 LOG="/var/log/${SOFTWARE}/${PROGRAM}.log"
29
30 Parametersscip-shell shell shell-project 0.0.0 Parameters(). ()
31 {
32 GETOPT_LONGOPTIONS="name:,date:,"
33 GETOPT_OPTIONS="n:,d:,"
34
35 PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
36
37 if [scip-shell system . . `[`. "${?}" != "0" ]
38 then
39 echoscip-shell system . . echo. "'${COMMAND}': getopt exit" >&2
40 exit 1
41 fi
42
43 eval set -- "${PARAMETERS}"
44
45 while truescip-shell system . . true.
46 do
47 case "${1}" in
48 -d|--date)
49 DATE="${2}"
50 shift 2
51 ;;
52
53 -n|--name)
54 NAME="${2}"
55 shift 2
56 ;;
57
58 -u|--user)
59 USER="${2}"
60 shift 2
61 ;;
62
63 --)
64 shift 1
65 break
66 ;;
67
68 *)
69 echoscip-shell system . . echo. "'${COMMAND}': getopt error" >&2
70 exit 1
71 ;;
72 esac
73 done
74 }
75
76 Usagescip-shell shell shell-project 0.0.0 Usage(). ()
77 {
78 echoscip-shell system . . echo. "Usage: ${PROGRAM} ${COMMAND} [-n|--name NAME] [-d|--date DATE|today|today-N|yesterday] [-u|--user USER]" >&2
79 echoscip-shell system . . echo.
80 echoscip-shell system . . echo. "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
81
82 exit 1
83 }
84
85 Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}"
86
87 # Pre hooks
88 for FILE in "${HOOKS}/pre-${COMMAND}".*
89 do
90 if [scip-shell system . . `[`. -x "${FILE}" ]
91 then
92 "${FILE}"
93 fi
94 done
95
96 # Run
97 case "${DATE}" in
98 today-*)
99 DAYS="$(echoscip-shell system . . echo. ${DATE} | awkscip-shell system . . awk. -F- '{ print $2 }')"
100
101 START="$(datescip-shell system . . date. -d "${DAYS} day ago" '+%Y-%m-%d')"
102 END="$(datescip-shell system . . date. +%Y-%m-%d)"
103
104 DATE="(${START}"
105
106 while truescip-shell system . . true.
107 do
108 DATE="${DATE}|${START}"
109
110 if [scip-shell system . . `[`. "${START}" = "${END}" ]
111 then
112 break
113 fi
114
115 START="$(datescip-shell system . . date. +%Y-%m-%d --date "${START} +1 day")"
116 done
117
118 DATE="${DATE})"
119 ;;
120
121 today)
122 DATE="$(datescip-shell system . . date. +%Y-%m-%d)"
123 ;;
124
125 yesterday)
126 DATE="$(datescip-shell system . . date. -d '1 day ago' '+%Y-%m-%d')"
127 ;;
128 esac
129
130 if lsscip-shell system . . ls. "${LOG}"-*.gz > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
131 then
132 LOGS="$(lsscip-shell system . . ls. ${LOG}-*.gz) ${LOG}"
133 else
134 LOGS="${LOG}"
135 fi
136
137 for LOG in ${LOGS}
138 do
139 case "${LOG}" in
140 *.gz)
141 GREP="zgrep"
142 ;;
143
144 *)
145 GREP="grep"
146 ;;
147 esac
148
149 case "${NAME}" in
150 "")
151 ${GREP} -E "^${DATE}" "${LOG}" || truescip-shell system . . true.
152 ;;
153
154 *)
155 ${GREP} -E "^${DATE}" "${LOG}" | grepscip-shell system . . grep. " ${NAME}" || truescip-shell system . . true.
156 ;;
157 esac
158 done
159
160 # Post hooks
161 for FILE in "${HOOKS}/post-${COMMAND}".*
162 do
163 if [scip-shell system . . `[`. -x "${FILE}" ]
164 then
165 "${FILE}"
166 fi
167 done