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

« back to all changes in this revision

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

  • Committer: dann frazier
  • Date: 2020-02-04 02:27:07 UTC
  • Revision ID: dannf@ubuntu.com-20200204022707-37vu1ltkpx2m2t5x
tests/test_motd.py: Fix cut & paste error in comment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh -e
2
 
#Author: Mads Chr. Olesen <mads@mchro.dk>
 
1
#!/bin/sh
 
2
# Authors:
 
3
#   Mads Chr. Olesen <mads@mchro.dk>
 
4
#   Kees Cook <kees@ubuntu.com>
 
5
set -e
3
6
 
4
7
# poor mans force
5
8
if [ "$1" = "--force" ]; then
6
9
    NEEDS_FSCK_CHECK=yes
 
10
else
 
11
    if [ "$(id -u)" != 0 ] ; then
 
12
        exit
 
13
    fi
 
14
    NEED_FSCK_CHECK=no
7
15
fi
8
16
 
9
17
# check time when we did the last check
14
22
    stampt=0
15
23
fi
16
24
 
 
25
# check time when we last booted
 
26
last_boot=$(date -d "now - $(awk '{print $1}' /proc/uptime) seconds" +%s)
 
27
 
17
28
now=$(date +%s)
18
 
if [ $(($stampt + 3600)) -lt $now ]; then
 
29
if [ $(($stampt + 3600)) -lt $now ] || [ $stampt -gt $now ] \
 
30
   || [ $stampt -lt $last_boot ]
 
31
then
19
32
    #echo $stampt $now need update 
20
33
        NEEDS_FSCK_CHECK=yes
21
34
fi
22
35
 
23
36
# output something for update-motd
24
37
if [ -n "$NEEDS_FSCK_CHECK" ]; then
25
 
    echo -n "" > $stamp
 
38
  {
 
39
    check_occur_any=
26
40
 
27
 
    ext_partitions=$(mount | egrep 'ext(2|3|4)' | cut -f 1 -d \ )
 
41
    ext_partitions=$(mount | awk '$5 ~ /^ext(2|3|4)$/ { print $1 }')
28
42
    for part in $ext_partitions; do
29
43
        dumpe2fs_out=$(dumpe2fs -h $part 2>/dev/null)
30
 
        mount_count=$(echo "$dumpe2fs_out" | grep "Mount count:"|cut -d':' -f 2-)
31
 
        max_mount_count=$(echo "$dumpe2fs_out" | grep "Maximum mount count:"|cut -d':' -f 2-)
32
 
        next_check_date=$(echo "$dumpe2fs_out" | grep "Next check after:" | cut -d':' -f 2-)
 
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
33
52
        next_check_tstamp=$(date -d "$next_check_date" +%s)
34
53
 
35
54
        #echo "next_check_date=\"$next_check_date\" next_check_tstamp=\"$next_check_tstamp\""
36
55
        #echo "part=\"$part\" mount_count=\"$mount_count\" / max=\"$max_mount_count\" "
37
56
 
38
 
        if [ "$mount_count" -ge "$max_mount_count" -o \
 
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 \
39
65
             "$next_check_tstamp" -lt "$now" ]; then
40
66
            check_occur=yes
41
 
            echo "*** $part will be checked for errors at next reboot ***" >> $stamp
 
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
42
77
        fi
43
78
    done
44
 
    if [ -n "$check_occur" ]; then
45
 
        echo "" >> $stamp
 
79
    if [ -n "$check_occur_any" ]; then
 
80
        echo ""
46
81
    fi
 
82
  } > $stamp
47
83
fi
48
84
 
49
85
# output what we have (either cached or newly generated)
50
86
cat $stamp
51
 
 
52
 
 
53
 
 
54