3
# Mads Chr. Olesen <mads@mchro.dk>
4
# Kees Cook <kees@ubuntu.com>
8
if [ "$1" = "--force" ]; then
11
if [ "$(id -u)" != 0 ] ; then
17
# check time when we did the last check
18
stamp="/var/lib/update-notifier/fsck-at-reboot"
19
if [ -e "$stamp" ]; then
20
stampt=$(stat -c %Y $stamp)
25
# check time when we last booted
26
last_boot=$(date -d "now - $(awk '{print $1}' /proc/uptime) seconds" +%s)
29
if [ $(($stampt + 3600)) -lt $now ] || [ $stampt -gt $now ] \
30
|| [ $stampt -lt $last_boot ]
32
#echo $stampt $now need update
36
# output something for update-motd
37
if [ -n "$NEEDS_FSCK_CHECK" ]; then
41
ext_partitions=$(mount | awk '$5 ~ /^ext(2|3|4)$/ { print $1 }')
42
for part in $ext_partitions; do
43
dumpe2fs_out=$(dumpe2fs -h $part 2>/dev/null)
44
mount_count=$(echo "$dumpe2fs_out" | grep "^Mount count:"|cut -d':' -f 2-)
45
if [ -z "$mount_count" ]; then mount_count=0; fi
46
max_mount_count=$(echo "$dumpe2fs_out" | grep "^Maximum mount count:"|cut -d':' -f 2-)
47
if [ -z "$max_mount_count" ]; then max_mount_count=0; fi
48
check_interval=$(echo "$dumpe2fs_out" | grep "^Check interval:" | cut -d':' -f 2- | cut -d'(' -f 1)
49
if [ -z "$check_interval" ]; then check_interval=0; fi
50
next_check_date=$(echo "$dumpe2fs_out" | grep "^Next check after:" | cut -d':' -f 2-)
51
if [ -z "$next_check_interval" ]; then next_check_interval=0; fi
52
next_check_tstamp=$(date -d "$next_check_date" +%s)
54
#echo "next_check_date=\"$next_check_date\" next_check_tstamp=\"$next_check_tstamp\""
55
#echo "part=\"$part\" mount_count=\"$mount_count\" / max=\"$max_mount_count\" "
58
# Check based on mount counts?
59
if [ "$max_mount_count" -gt 0 -a \
60
"$mount_count" -ge "$max_mount_count" ]; then
63
# Check based on time passed?
64
if [ "$check_interval" -gt 0 -a \
65
"$next_check_tstamp" -lt "$now" ]; then
68
if [ -n "$check_occur" ]; then
70
mountpoint=$(mount | grep "^$part" | cut -d ' ' -f 3)
71
pass=$(grep -v '^#' /etc/fstab | tr -s ' ' '\t' | cut -s -f 2,6 | grep -w "$mountpoint" | cut -f 2)
72
if [ "$pass" = "0" ]; then
73
echo "*** $part should be checked for errors ***"
75
echo "*** $part will be checked for errors at next reboot ***"
79
if [ -n "$check_occur_any" ]; then
85
# output what we have (either cached or newly generated)