]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - scrub/e2scrub_all_cron.in
libext2fs: fix potential divide by zero bug caused by a lxcfs bug
[thirdparty/e2fsprogs.git] / scrub / e2scrub_all_cron.in
CommitLineData
a2df5894
DW
1#!/bin/bash
2
3# Copyright (C) 2018 Oracle. All Rights Reserved.
4#
5# Author: Darrick J. Wong <darrick.wong@oracle.com>
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation; either version 2
10# of the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it would 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, write the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20
21# Run e2scrub_all from a cronjob if we don't have systemd and we're not
22# running on AC power.
23
24on_ac_power() {
25 local any_known=no
26
27 # try sysfs power class first
28 if [ -d /sys/class/power_supply ]; then
29 for psu in /sys/class/power_supply/*; do
30 if [ -r "$psu/type" ]; then
31 type=$(cat "$psu/type")
32
33 # ignore batteries
34 [ "$type" = "Battery" ] && continue
35
36 online=$(cat "$psu/online")
37
38 [ "$online" = 1 ] && return 0
39 [ "$online" = 0 ] && any_known=yes
40 fi
41 done
42
43 [ "$any_known" = "yes" ] && return 1
44 fi
45
46 # else fall back to AC adapters in /proc
47 if [ -d /proc/acpi/ac_adapter ]; then
48 for ac in /proc/acpi/ac_adapter/*; do
49 if [ -r "$ac/state" ]; then
50 grep -q on-line "$ac/state" && return 0
51 grep -q off-line "$ac/state" && any_known=yes
52 elif [ -r "$ac/status" ]; then
53 grep -q on-line "$ac/status" && return 0
54 grep -q off-line "$ac/status" && any_known=yes
55 fi
56 done
57
58 [ "$any_known" = "yes" ] && return 1
59 fi
60
61 # Can't tell, just assume we're on AC.
62 return 0
63}
64
0f886f42 65test -e @root_sbindir@/e2scrub_all || exit 0
a2df5894
DW
66test -e /run/systemd/system && exit 0
67on_ac_power || exit 0
68
6ec2060a 69exec @root_sbindir@/e2scrub_all