#!/bin/bash

# sourcing our current rc.conf requires this to be a bash script
. /usr/lib/rc/functions
. /etc/rc/rc.conf

cleaning(){
    install -m0664 -o root -g utmp /dev/null /run/utmp
    if [ ! -e /var/log/wtmp ]; then
        install -m0664 -o root -g utmp /dev/null /var/log/wtmp
    fi
    if [ ! -e /var/log/btmp ]; then
        install -m0600 -o root -g utmp /dev/null /var/log/btmp
    fi

    rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot

    [ "$CLEANTMP" = y ] && rm -rf /tmp/*
}

case "$1" in
    start)
        stat_busy "Starting cleanup"
        cleaning
        add_daemon cleanup
        stat_done
        ;;
    stop)
        stat_busy "Stopping cleanup"
        halt -w || stat_die
        rm_daemon cleanup
        stat_done
        ;;
    *)
        echo "usage: $0 {start|stop}"
        exit 1
        ;;
esac
