Home | History | Annotate | Line # | Download | only in rc.d
      1   1.1     lukem #!/bin/sh
      2   1.1     lukem #
      3  1.26       kre # $NetBSD: sysdb,v 1.26 2023/12/25 08:38:32 kre Exp $
      4   1.1     lukem #
      5   1.1     lukem 
      6   1.5     lukem # PROVIDE: sysdb
      7   1.3     lukem # REQUIRE: mountcritremote
      8   1.9   thorpej # BEFORE:  DAEMON
      9   1.1     lukem 
     10  1.14   mycroft $_rc_subr_loaded . /etc/rc.subr
     11   1.1     lukem 
     12   1.1     lukem name="sysdb"
     13  1.20    dyoung rcvar=$name
     14   1.1     lukem start_cmd="sysdb_start"
     15   1.1     lukem stop_cmd=":"
     16  1.16  christos extra_commands="devdb utmp services netgroup password"
     17  1.11    atatat devdb_cmd="build_devdb"
     18  1.11    atatat utmp_cmd="build_utmp"
     19  1.16  christos services_cmd="build_services"
     20  1.16  christos netgroup_cmd="build_netgroup"
     21  1.16  christos password_cmd="build_password"
     22  1.16  christos echo=:
     23   1.1     lukem 
     24   1.1     lukem sysdb_start()
     25   1.1     lukem {
     26  1.16  christos 	echo -n "Building databases:"
     27  1.16  christos 	echo=echo
     28  1.16  christos 	comma=" "
     29  1.12    atatat 	$devdb_cmd
     30  1.12    atatat 	$utmp_cmd
     31  1.16  christos 	$services_cmd
     32  1.16  christos 	$netgroup_cmd
     33  1.16  christos 	$password_cmd
     34  1.22   mbalmer 	echo "."
     35  1.16  christos }
     36  1.16  christos 
     37  1.16  christos check_file()
     38  1.16  christos {
     39  1.16  christos 	local src="$1"
     40  1.16  christos 	local db="$2"
     41  1.18  christos 
     42  1.16  christos 	shift 2
     43  1.26       kre 	if ! [ -e "$src" ]; then
     44  1.18  christos 		return
     45  1.18  christos 	fi
     46  1.26       kre 	if ! [ -f "$db" ] || [ "$src" -nt "$db" ]; then
     47  1.25  dholland 		$echo -n "$comma${src##*/}"
     48  1.16  christos 		comma=", "
     49  1.16  christos 		"$@"
     50  1.16  christos 	fi
     51  1.16  christos }
     52  1.16  christos 
     53  1.16  christos build_services()
     54  1.16  christos {
     55  1.23  nakayama 	check_file /etc/services /var/db/services.cdb services_mkdb -q
     56  1.16  christos }
     57  1.16  christos 
     58  1.16  christos build_netgroup()
     59  1.16  christos {
     60  1.17  christos 	check_file /etc/netgroup /var/db/netgroup.db netgroup_mkdb
     61  1.11    atatat }
     62   1.4     lukem 
     63  1.11    atatat build_devdb()
     64  1.11    atatat {
     65  1.16  christos 	check_file /dev /var/run/dev.db dev_mkdb
     66  1.24     joerg 	check_file /dev /var/run/dev.cdb dev_mkdb
     67  1.16  christos }
     68  1.16  christos 
     69  1.16  christos build_password()
     70  1.16  christos {
     71  1.16  christos 	local p=/etc/master.passwd
     72  1.21  christos 	check_file $p /etc/spwd.db pwd_mkdb -w $p
     73  1.11    atatat }
     74  1.11    atatat 
     75  1.11    atatat build_utmp()
     76  1.11    atatat {
     77  1.10     perry 	#	Re-create /var/run/utmp and /var/run/utmpx, which are
     78  1.10     perry 	#	deleted by mountcritlocal but can't be recreated by it
     79  1.10     perry 	#	because install and chown may not be available then
     80  1.10     perry 	#	(possibly no /usr).
     81   1.4     lukem 	#
     82  1.16  christos 	local i
     83  1.16  christos 	for i in "" x; do
     84  1.26       kre 		if ! [ -f /var/run/utmp$i ]; then
     85  1.16  christos 			$echo -n "${comma}utmp$i"
     86  1.16  christos 			comma=", "
     87  1.16  christos 			install -c -m 664 -g utmp /dev/null /var/run/utmp$i
     88  1.16  christos 		fi
     89  1.16  christos 	done
     90   1.1     lukem }
     91   1.1     lukem 
     92   1.2     lukem load_rc_config $name
     93   1.1     lukem run_rc_command "$1"
     94