10696600cSBjoern A. Zeeb#!/bin/sh 20696600cSBjoern A. Zeeb# 30696600cSBjoern A. Zeeb# Copyright (c) 1999 Matt Dillon 40696600cSBjoern A. Zeeb# All rights reserved. 50696600cSBjoern A. Zeeb# 60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions 80696600cSBjoern A. Zeeb# are met: 90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 100696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 120696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 130696600cSBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 140696600cSBjoern A. Zeeb# 150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 180696600cSBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 250696600cSBjoern A. Zeeb# SUCH DAMAGE. 260696600cSBjoern A. Zeeb# 270696600cSBjoern A. Zeeb# 280696600cSBjoern A. Zeeb 290696600cSBjoern A. Zeeb# PROVIDE: var 300696600cSBjoern A. Zeeb# REQUIRE: mountcritlocal 310696600cSBjoern A. Zeeb 320696600cSBjoern A. Zeeb# NFS /var is not supported, unless NFS /var is part of diskless NFS / 330696600cSBjoern A. Zeeb 340696600cSBjoern A. Zeeb. /etc/rc.subr 350696600cSBjoern A. Zeeb 360696600cSBjoern A. Zeebname="var" 370696600cSBjoern A. Zeebdesc="Populate /var directory" 380696600cSBjoern A. Zeebstop_cmd=':' 390696600cSBjoern A. Zeeb 400696600cSBjoern A. Zeebload_rc_config $name 410696600cSBjoern A. Zeeb 42*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: mounting 43*f99f0ee1SAlexander Leidingervar_svcj="NO" 44*f99f0ee1SAlexander Leidinger 450696600cSBjoern A. Zeebpopulate_var() 460696600cSBjoern A. Zeeb{ 470696600cSBjoern A. Zeeb /usr/sbin/mtree -deiU -f /etc/mtree/BSD.var.dist -p /var > /dev/null 480696600cSBjoern A. Zeeb case ${sendmail_enable} in 490696600cSBjoern A. Zeeb [Nn][Oo][Nn][Ee]) 500696600cSBjoern A. Zeeb ;; 510696600cSBjoern A. Zeeb *) 520696600cSBjoern A. Zeeb /usr/sbin/mtree -deiU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null 530696600cSBjoern A. Zeeb ;; 540696600cSBjoern A. Zeeb esac 550696600cSBjoern A. Zeeb} 560696600cSBjoern A. Zeeb 570696600cSBjoern A. Zeeb# If we do not have a writable /var, create a memory filesystem for /var 580696600cSBjoern A. Zeeb# unless told otherwise by rc.conf. We don't have /usr yet so use mkdir 590696600cSBjoern A. Zeeb# instead of touch to test. We want mount to record its mounts so we 600696600cSBjoern A. Zeeb# have to make sure /var/db exists before doing the mount -a. 610696600cSBjoern A. Zeeb# 620696600cSBjoern A. Zeebcase "${varmfs}" in 630696600cSBjoern A. Zeeb[Yy][Ee][Ss]) 640696600cSBjoern A. Zeeb mount_md ${varsize} /var "${varmfs_flags}" 650696600cSBjoern A. Zeeb ;; 660696600cSBjoern A. Zeeb[Nn][Oo]) 670696600cSBjoern A. Zeeb ;; 680696600cSBjoern A. Zeeb*) 690696600cSBjoern A. Zeeb if /bin/mkdir -p /var/.diskless 2> /dev/null; then 700696600cSBjoern A. Zeeb rmdir /var/.diskless 710696600cSBjoern A. Zeeb else 720696600cSBjoern A. Zeeb mount_md ${varsize} /var "${varmfs_flags}" 730696600cSBjoern A. Zeeb fi 740696600cSBjoern A. Zeebesac 750696600cSBjoern A. Zeeb 760696600cSBjoern A. Zeeb 770696600cSBjoern A. Zeeb# If we have an empty looking /var, populate it, but only if we have 780696600cSBjoern A. Zeeb# /usr available. Hopefully, we'll eventually find a workaround, but 790696600cSBjoern A. Zeeb# in realistic diskless setups, we're probably ok. 800696600cSBjoern A. Zeebcase "${populate_var}" in 810696600cSBjoern A. Zeeb[Yy][Ee][Ss]) 820696600cSBjoern A. Zeeb populate_var 830696600cSBjoern A. Zeeb ;; 840696600cSBjoern A. Zeeb[Nn][Oo]) 850696600cSBjoern A. Zeeb exit 0 860696600cSBjoern A. Zeeb ;; 870696600cSBjoern A. Zeeb*) 880696600cSBjoern A. Zeeb if [ -d /var/run -a -d /var/db -a -d /var/empty ] ; then 890696600cSBjoern A. Zeeb true 900696600cSBjoern A. Zeeb elif [ -x /usr/sbin/mtree ] ; then 910696600cSBjoern A. Zeeb populate_var 920696600cSBjoern A. Zeeb else 930696600cSBjoern A. Zeeb # We need mtree to populate /var so try mounting /usr. 940696600cSBjoern A. Zeeb # If this does not work, we can not boot so it is OK to 950696600cSBjoern A. Zeeb # try to mount out of order. 960696600cSBjoern A. Zeeb mount /usr 970696600cSBjoern A. Zeeb if [ ! -x /usr/sbin/mtree ] ; then 980696600cSBjoern A. Zeeb exit 1 990696600cSBjoern A. Zeeb else 1000696600cSBjoern A. Zeeb populate_var 1010696600cSBjoern A. Zeeb fi 1020696600cSBjoern A. Zeeb fi 1030696600cSBjoern A. Zeeb ;; 1040696600cSBjoern A. Zeebesac 1050696600cSBjoern A. Zeeb 1060696600cSBjoern A. Zeeb# Make sure we have /var/log/utx.lastlogin and /var/log/utx.log files 1070696600cSBjoern A. Zeebif [ ! -f /var/log/utx.lastlogin ]; then 1080696600cSBjoern A. Zeeb cp /dev/null /var/log/utx.lastlogin 1090696600cSBjoern A. Zeeb chmod 644 /var/log/utx.lastlogin 1100696600cSBjoern A. Zeebfi 1110696600cSBjoern A. Zeebif [ ! -f /var/log/utx.log ]; then 1120696600cSBjoern A. Zeeb cp /dev/null /var/log/utx.log 1130696600cSBjoern A. Zeeb chmod 644 /var/log/utx.log 1140696600cSBjoern A. Zeebfi 115