#!/bin/bash

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

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

    rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot
    ck_verbose && substat "Removed /etc/nologin, /forcefsck, /forcequotacheck, /fastboot"
}

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
