#!/bin/sh
#
# Check that we are using ext3, not ext2

if test -r /etc/debian-edu/config ; then
    . /etc/debian-edu/config
fi

LANG=C
export LANG

awk "/ext2/ { print \"error: $0: Using ext2 on\",\$2 }" /proc/mounts
awk "/ext3|ext4/ { print \"success: $0: Using ext3 on\",\$2 }" /proc/mounts

# Check if the filesystems on the mountpoints support acls
for f in `grep 'ext' /proc/mounts|awk '{print $1}'`; do
     if [ `chacl -l $f | grep 'cannot get'` ]; then
        echo "error: $0: $f doesn't support acls" 
     else
        echo "success: $0: $f supports acls"
     fi
done

# Make sure all ext3/ext4 mount points are online resizable
for p in `(df -Pt ext3 2>/dev/null;df -Pt ext4 2>/dev/null) | grep -v ^Filesystem |awk '{print $1}'`; do 
    if tune2fs -l $p| grep features | grep -q resize_inode ; then
	:
    else
	echo "error: $0: Missing resize_inode in ext3/ext4 fs $p"
    fi
done

if echo "$PROFILE" | grep -q Main-Server ; then
    # Make sure autofs do not hide the real file systems
    if [ -d /skole/tjener/home0/lost+found ] ; then
	echo "success: $0: Found lost+found in /skole/tjener/home0/"
    else
	echo "error: $0: No lost+found in /skole/tjener/home0/.  Blocked by autofs?"
    fi

    # Make sure home0 and backup have acl and user_xattr enabled.  See
    # if bug #638822 is present or not.
    for dir in /skole/tjener/home0 /skole/backup; do
	dev="$(LC_ALL=C df -P /var/log|awk '/%/ {print $1}')"
	for opt in acl user_xattr ; do
	    if LC_ALL=C tune2fs -l "$dev" | \
		grep 'Default mount' | \
		grep -qw $opt ; then
		echo "success: $0: Found option $opt in $dir."
	    else
		echo "error: $0: Did not find option $opt in $dir."
	    fi
	done
    done
fi

# Report too full file systems.  Should have at least 20% free to
# avoid warning from Nagios, preferably between 20% and 25%.
df -m -P -x tmpfs |
  awk '/\/dev\// { if ($3/$2 >= 0.80) print "error: Too full file system", $1, "uses", $3, "of", $2, "MiB" }'
