~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to data/update-motd-fsck-at-reboot

  • Committer: Balint Reczey
  • Date: 2020-06-11 18:46:02 UTC
  • Revision ID: balint.reczey@canonical.com-20200611184602-2rv1zan3xu723x2u
Moved to git at https://git.launchpad.net/update-notifier

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# Authors:
3
 
#   Mads Chr. Olesen <mads@mchro.dk>
4
 
#   Kees Cook <kees@ubuntu.com>
5
 
set -e
6
 
 
7
 
# poor mans force
8
 
if [ "$1" = "--force" ]; then
9
 
    NEEDS_FSCK_CHECK=yes
10
 
else
11
 
    if [ "$(id -u)" != 0 ] ; then
12
 
        exit
13
 
    fi
14
 
    NEED_FSCK_CHECK=no
15
 
fi
16
 
 
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)
21
 
else
22
 
    stampt=0
23
 
fi
24
 
 
25
 
# check time when we last booted
26
 
last_boot=$(date -d "now - $(awk '{print $1}' /proc/uptime) seconds" +%s)
27
 
 
28
 
now=$(date +%s)
29
 
if [ $(($stampt + 3600)) -lt $now ] || [ $stampt -gt $now ] \
30
 
   || [ $stampt -lt $last_boot ]
31
 
then
32
 
    #echo $stampt $now need update 
33
 
        NEEDS_FSCK_CHECK=yes
34
 
fi
35
 
 
36
 
# output something for update-motd
37
 
if [ -n "$NEEDS_FSCK_CHECK" ]; then
38
 
  {
39
 
    check_occur_any=
40
 
 
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)
53
 
 
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\" "
56
 
 
57
 
        check_occur=
58
 
        # Check based on mount counts?
59
 
        if [ "$max_mount_count" -gt 0 -a \
60
 
             "$mount_count" -ge "$max_mount_count" ]; then
61
 
            check_occur=yes
62
 
        fi
63
 
        # Check based on time passed?
64
 
        if [ "$check_interval" -gt 0 -a \
65
 
             "$next_check_tstamp" -lt "$now" ]; then
66
 
            check_occur=yes
67
 
        fi
68
 
        if [ -n "$check_occur" ]; then
69
 
            check_occur_any=yes
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 ***"
74
 
            else
75
 
                echo "*** $part will be checked for errors at next reboot ***"
76
 
            fi
77
 
        fi
78
 
    done
79
 
    if [ -n "$check_occur_any" ]; then
80
 
        echo ""
81
 
    fi
82
 
  } > $stamp
83
 
fi
84
 
 
85
 
# output what we have (either cached or newly generated)
86
 
cat $stamp