1#!/bin/sh
2# $FreeBSD$
3#
4# rc.conf for picobsd. This is sourced from /etc/rc1, and is supposed to
5# contain only shell functions that are used later in /etc/rc1.
6
7# set default values for variables. Boolean values should be either
8# NO or YES -- other values are not guaranteed to work.
9
10rc_conf_set_defaults() {
11hostname=""			# Should not need to set it
12syslogd_enable="NO"
13pccard_enable="NO"
14swapfile=""			# name of swapfile if aux swapfile desired.
15
16# Network interface configurations: ifconfig_${interface}[_aliasNN]
17ifconfig_lo0="inet 127.0.0.1"	# default loopback device configuration.
18#ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample alias entry.
19
20### Network daemons options: they are only run if present.
21sshd_enable="YES"		# if present...
22inetd_enable="YES"		# Run the network daemon dispatcher (or NO)
23inetd_flags=""			# Optional flags to inetd
24snmpd_enable="NO"		# Run the SNMP daemon (or NO)
25snmpd_flags="-C -c /etc/snmpd.conf"	# Optional flags to snmpd
26
27### Network routing options: ###
28defaultrouter="NO"		# Set to default gateway (or NO).
29static_routes=""		# Set to static route list (or leave empty).
30gateway_enable="NO"		# Set to YES if this host will be a gateway.
31arpproxy_all=""			# replaces obsolete kernel option ARP_PROXYALL.
32default_mask="0xffffff00"
33
34### Other network features
35firewall_enable="NO"
36firewall_quiet="NO"		# be quiet if set.
37firewall_type=""		# Standard types or absolute pathname.
38tcp_extensions="NO"		# Allow RFC1323 & RFC1644 extensions (or NO).
39
40### Overrides for some files in /etc. Leave empty if no override,
41### set variable (remember to use multiple lines) to override content.
42
43host_conf="hosts
44bind"
45resolv_conf=""
46}
47
48# Try to identify the system by using the MAC address and name of the
49# first ethernet interface, made available as $main_eth $main_if
50find_system_id() {
51    main_ether=""
52    for main_if in `ifconfig -l` ; do
53	set `ifconfig $main_if`
54	while [ "$1" != "" ] ; do
55	    if [ $1 = "ether" ] ; then
56		main_ether=$2
57		break 2
58	    else
59		shift
60	    fi
61	done
62    done
63}
64
65# the following lets the user specify a name and ip for his system
66read_address() {
67    echo "Please enter a hostname and IP address for your system $main_ether"
68    read hostname the_ip
69    if [ "${hostname}" != "" ] ; then
70	echo "# $main_ether $hostname" >> /etc/hosts
71	echo "$the_ip $hostname" >> /etc/hosts
72    else
73	hostname=default
74    fi
75}
76
77# set "ether" using $1 (interface name) as search key
78get_ether() {
79    local key
80    key=$1
81    ether=""
82    set `ifconfig ${key}`
83    while [ "$1" != "" ] ; do
84        if [ "$1" = "ether" ] ; then
85            ether=$2
86            break
87        else
88            shift
89        fi
90    done
91}
92
93# read content from /etc/hosts into a couple of arrays
94# (needed later in fetch_hostname)
95read_hosts() {
96    local i a b c key junk
97    i=""
98    while read a b c junk ; do
99        if [ "$a" = "#ethertable" ] ; then
100            i=0
101        elif [ "$i" != "" -a "$a" = "#" -a "$b" != "" ] ; then
102            eval eth_${i}=$b
103            eval eth_host_${i}=$c
104            i=$(($i+1))
105        fi
106    done < /etc/hosts
107}
108
109# set ${hostname} using $1 (MAC address) as search key in /etc/hosts
110# Returns empty value if $1 is empty
111fetch_hostname() {
112    local i b key
113    hostname=""
114    [ "$1" = "" ] && return
115    key=$1
116    i=0
117    b="x"
118    [ "${eth_0}" = "" ] && read_hosts # fill cache.
119    while [ "$b" != "" -a "${hostname}" = "" ] ; do
120        eval b=\${eth_${i}}
121        case X${key} in
122        X${b} ) # so we can use wildcards
123            eval hostname=\${eth_host_${i}}
124            break
125            ;;
126        esac
127        i=$(($i+1))
128    done
129    echo "fetch_hostname for <${key}> returns <${hostname}>"
130}
131
132# sets "mask" using $1 (netmask name) as the search key in /etc/networks
133fetch_mask() {
134    local a b key junk
135    key=$1	# search key, typically hostname-netmask
136    mask=""
137    while read a b junk; do # key mask otherstuff
138	case X${key} in
139	X${a} )	# The X is so we can use wildcards in ${a}
140	    mask=$b
141	    break
142	    ;;
143	esac
144    done < /etc/networks
145    if [ "${mask}" = "" ] ; then
146	mask=${default_mask}
147    fi
148    echo "fetch_mask for <${key}> returns <${mask}>"
149}
150
151# set hostname, and ifconfig_${main_if} (whose MAC is ${main_ether})
152# if not found, read from console
153set_main_interface() {
154    if [ -z "${hostname}" ] ; then
155	if [ -z "${main_ether}" ] ; then
156	    echo "No ethernets found, using localhost"
157	    hostname=localhost
158	    return
159	fi
160	fetch_hostname ${main_ether}
161    fi
162
163    [ -z "${hostname}" -o "${hostname}" = "." ] && read_address
164    
165    fetch_mask ${hostname}-netmask
166
167    eval ifconfig_${main_if}=\" \${hostname} netmask \${mask}\"
168    network_interfaces=`ifconfig -l`
169}
170
171# set ifconfig_${interface} for all other interfaces
172set_all_interfaces() {
173    local i ether hostname mask
174
175    for i in `ifconfig -l` ; do
176	if [ "$i" != "${main_if}" ] ; then
177	    get_ether $i
178	    fetch_hostname ${ether}
179	    fetch_mask ${hostname}-netmask
180	    [ -n "${ether}" -a -n "${hostname}" ] && \
181		eval ifconfig_${i}=\" \${hostname} netmask \${mask}\"
182	fi
183    done
184}
185