3 # Report on project fsck status.
4 # Output can be sent as email to admin with -m
5 # Automatically runs with nice and ionice (if available)
7 # Usage: project-fsck-status [-m]
9 # With -m mail the report to $cfg_admin instead of sending it to stdout
11 # Shows fsck status for all projects with details for any issues
13 # Note that only projects listed in $cfg_chroot/etc/group are checked
17 datefmt
='%Y-%m-%d %H:%M:%S %z'
18 startdate
="$(date "+$datefmt")"
23 if [ "$1" = "-m" ]; then
29 command -v nice
> /dev
/null
&& hasnice
=1
31 command -v ionice
> /dev
/null
&& hasionice
=1
36 projlist
="$(cut -d : -f 1 < "$cfg_chroot/etc
/group
")"
39 echo "$projlist" |
grep -q -e "^$1$"
43 # if packed-refs is empty and no files in refs then empty
44 # we do NOT want to run any git command in case the repo is bad
45 _pd
="$cfg_reporoot/$1.git"
46 if [ -f "$_pd/packed-refs" -a -s "$_pd/packed-refs" ]; then
47 if [ $
(LC_ALL
=C
sed -n '/^#/!p' <"$_pd/packed-refs" | LC_ALL
=C
wc -l) -gt 0 ]; then
51 test $
(find "$_pd/refs" -type f
-print 2>/dev
/null |
head -n 1 | LC_ALL
=C
wc -l) -eq 0
55 cd "$cfg_reporoot/$1.git" ||
{
56 echo "no such directory: $cfg_reporoot/$1.git"
59 # using --strict changes "zero-padded file modes" from a warning into an error
60 # which we do NOT want so we do NOT use --strict
62 [ -z "$var_have_git_1710" ] || cmd
="$cmd --no-dangling"
63 # no need for --no-progress (v1.7.9+) since stderr will not be a tty
65 [ -n "$hasionice" ] && cmd
="ionice -c 3 $cmd"
66 [ -n "$hasnice" ] && cmd
="nice -n 19 $cmd"
68 fsckoutput
="$(eval "$cmd")" || fsckresult
=$?
69 if [ -z "$var_have_git_1710" ]; then
70 # strip lines starting with "dangling" since --no-dangling is not supported
71 # note that "dangling" is NOT translated
72 fsckoutput
="$(printf '%s\n' "$fsckoutput" | LC_ALL=C sed -n '/^dangling/!p')"
74 [ -z "$fsckoutput" ] ||
printf '%s\n' "$fsckoutput"
79 # howmany is how many fsck was run on plus how many were empty
81 # mtcount is how many were empty
83 # okcount is how many fsck returned 0 status for
85 # warncount is how many fsck returned 0 status but non-empty output
87 # errresults are results from fsck non-0 status fsck runs
89 # warnresults are non-empty results from 0 status fsck runs
91 while IFS
='' read -r proj
; do
94 is_listed_proj
"$proj" && is_git_dir
"$cfg_reporoot/$proj.git" ||
continue
95 [ -d "$proj.git/objects" ] ||
continue
96 howmany
="$(( $howmany + 1 ))"
97 if is_empty_proj
"$proj"; then
98 mtcount
="$(( $mtcount + 1 ))"
102 output
="$(get_fsck_proj "$proj")" || ok
=
103 [ -z "$ok" ] || okcount
="$(( $okcount + 1 ))"
104 [ -n "$ok" -o -n "$output" ] || output
="git fsck failed with no output"
105 if [ -n "$output" ]; then
106 output
="$(printf '%s\n' "$output" | LC_ALL=C sed 's/^/ /')$nl"
107 if [ -n "$ok" ]; then
109 warncount
="$(( $warncount + 1 ))"
110 [ -z "$warnresults" ] || warnresults
="$warnresults$nl"
111 warnresults
="$warnresults$proj: (warnings only)$nl$output"
113 [ -z "$errresults" ] || errresults
="$errresults$nl"
114 errresults
="$errresults$proj: (errors found)$nl$output"
118 $(find . -type d \( -path ./_recyclebin -o -name '*.git' -print \) -prune 2>/dev/null)
121 enddate
="$(date "+$datefmt")"
123 [ -n "$mailresult" ] && domail
='mail -s "[$cfg_name] Project Fsck Status Report" "$cfg_admin"'
126 Project Fsck Status Report
127 ==========================
129 Start Time: $startdate
132 Projects Checked: $howmany
133 Projects Okay: $(( $okcount + $mtcount )) (passed + warned + empty)
135 Projects Passed: $(( $okcount - $warncount ))
136 Projects Warned: $warncount
137 Projects Empty: $mtcount
138 Projects Failed: $(( $howmany - $mtcount - $okcount ))
142 if [ -n "$errresults" ] ||
[ -n "$warnresults" ]; then
147 printf '%s' "$errresults"
148 [ -z "$errresults" -o -z "$warnresults" ] ||
echo ""
149 printf '%s' "$warnresults"