191853Sluigi#!/bin/sh 291853Sluigi# $FreeBSD$ 391853Sluigi# 491853Sluigi# rc.conf for picobsd. This is sourced from /etc/rc1, and is supposed to 591853Sluigi# contain only shell functions that are used later in /etc/rc1. 691853Sluigi 791853Sluigi# set default values for variables. Boolean values should be either 891853Sluigi# NO or YES -- other values are not guaranteed to work. 991853Sluigi 1091853Sluigirc_conf_set_defaults() { 1191853Sluigihostname="" # Should not need to set it 1291853Sluigisyslogd_enable="NO" 1391853Sluigipccard_enable="NO" 1491853Sluigiswapfile="" # name of swapfile if aux swapfile desired. 1591853Sluigi 1691853Sluigi# Network interface configurations: ifconfig_${interface}[_aliasNN] 1791853Sluigiifconfig_lo0="inet 127.0.0.1" # default loopback device configuration. 1891853Sluigi#ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample alias entry. 1991853Sluigi 2091853Sluigi### Network daemons options: they are only run if present. 2191853Sluigisshd_enable="YES" # if present... 2291853Sluigiinetd_enable="YES" # Run the network daemon dispatcher (or NO) 2391853Sluigiinetd_flags="" # Optional flags to inetd 2491853Sluigisnmpd_enable="NO" # Run the SNMP daemon (or NO) 2591853Sluigisnmpd_flags="-C -c /etc/snmpd.conf" # Optional flags to snmpd 2691853Sluigi 2791853Sluigi### Network routing options: ### 2891853Sluigidefaultrouter="NO" # Set to default gateway (or NO). 2991853Sluigistatic_routes="" # Set to static route list (or leave empty). 3091853Sluigigateway_enable="NO" # Set to YES if this host will be a gateway. 3191853Sluigiarpproxy_all="" # replaces obsolete kernel option ARP_PROXYALL. 3291853Sluigidefault_mask="0xffffff00" 3391853Sluigi 3491949Sluigi### Other network features 3591853Sluigifirewall_enable="NO" 3691853Sluigifirewall_quiet="NO" # be quiet if set. 3791853Sluigifirewall_type="" # Standard types or absolute pathname. 3891853Sluigitcp_extensions="NO" # Allow RFC1323 & RFC1644 extensions (or NO). 3991949Sluigi 4091949Sluigi### Overrides for some files in /etc. Leave empty if no override, 4191949Sluigi### set variable (remember to use multiple lines) to override content. 4291949Sluigi 4391949Sluigihost_conf="hosts 4491949Sluigibind" 4591949Sluigiresolv_conf="" 4691853Sluigi} 4791853Sluigi 4891853Sluigi# Try to identify the system by using the MAC address and name of the 4991853Sluigi# first ethernet interface, made available as $main_eth $main_if 5091853Sluigifind_system_id() { 5191853Sluigi main_ether="" 5291853Sluigi for main_if in `ifconfig -l` ; do 5391853Sluigi set `ifconfig $main_if` 5491853Sluigi while [ "$1" != "" ] ; do 5591853Sluigi if [ $1 = "ether" ] ; then 5691853Sluigi main_ether=$2 5791853Sluigi break 2 5891853Sluigi else 5991853Sluigi shift 6091853Sluigi fi 6191853Sluigi done 6291853Sluigi done 6391853Sluigi} 6491853Sluigi 6591853Sluigi# the following lets the user specify a name and ip for his system 6691853Sluigiread_address() { 6791853Sluigi echo "Please enter a hostname and IP address for your system $main_ether" 6891853Sluigi read hostname the_ip 6991853Sluigi if [ "${hostname}" != "" ] ; then 7091853Sluigi echo "# $main_ether $hostname" >> /etc/hosts 7191853Sluigi echo "$the_ip $hostname" >> /etc/hosts 7291853Sluigi else 7391853Sluigi hostname=default 7491853Sluigi fi 7591853Sluigi} 7691853Sluigi 7791853Sluigi# set "ether" using $1 (interface name) as search key 7891853Sluigiget_ether() { 7991853Sluigi local key 8091853Sluigi key=$1 8191853Sluigi ether="" 8291853Sluigi set `ifconfig ${key}` 8391853Sluigi while [ "$1" != "" ] ; do 8491853Sluigi if [ "$1" = "ether" ] ; then 8591853Sluigi ether=$2 8691853Sluigi break 8791853Sluigi else 8891853Sluigi shift 8991853Sluigi fi 9091853Sluigi done 9191853Sluigi} 9291853Sluigi 9391853Sluigi# read content from /etc/hosts into a couple of arrays 9491853Sluigi# (needed later in fetch_hostname) 9591853Sluigiread_hosts() { 9691853Sluigi local i a b c key junk 9791853Sluigi i="" 9891853Sluigi while read a b c junk ; do 9991853Sluigi if [ "$a" = "#ethertable" ] ; then 10091853Sluigi i=0 10191853Sluigi elif [ "$i" != "" -a "$a" = "#" -a "$b" != "" ] ; then 10291853Sluigi eval eth_${i}=$b 10391853Sluigi eval eth_host_${i}=$c 10491853Sluigi i=$(($i+1)) 10591853Sluigi fi 10691853Sluigi done < /etc/hosts 10791853Sluigi} 10891853Sluigi 10991853Sluigi# set ${hostname} using $1 (MAC address) as search key in /etc/hosts 11091853Sluigi# Returns empty value if $1 is empty 11191853Sluigifetch_hostname() { 11291853Sluigi local i b key 11391853Sluigi hostname="" 11491853Sluigi [ "$1" = "" ] && return 11591853Sluigi key=$1 11691853Sluigi i=0 11791853Sluigi b="x" 11891853Sluigi [ "${eth_0}" = "" ] && read_hosts # fill cache. 11991853Sluigi while [ "$b" != "" -a "${hostname}" = "" ] ; do 12091853Sluigi eval b=\${eth_${i}} 12191853Sluigi case X${key} in 12291853Sluigi X${b} ) # so we can use wildcards 12391853Sluigi eval hostname=\${eth_host_${i}} 12491853Sluigi break 12591853Sluigi ;; 12691853Sluigi esac 12791853Sluigi i=$(($i+1)) 12891853Sluigi done 12991853Sluigi echo "fetch_hostname for <${key}> returns <${hostname}>" 13091853Sluigi} 13191853Sluigi 13291853Sluigi# sets "mask" using $1 (netmask name) as the search key in /etc/networks 13391853Sluigifetch_mask() { 13491853Sluigi local a b key junk 13591853Sluigi key=$1 # search key, typically hostname-netmask 13691853Sluigi mask="" 13791853Sluigi while read a b junk; do # key mask otherstuff 13891853Sluigi case X${key} in 13991853Sluigi X${a} ) # The X is so we can use wildcards in ${a} 14091853Sluigi mask=$b 14191853Sluigi break 14291853Sluigi ;; 14391853Sluigi esac 14491853Sluigi done < /etc/networks 14591853Sluigi if [ "${mask}" = "" ] ; then 14691853Sluigi mask=${default_mask} 14791853Sluigi fi 14891853Sluigi echo "fetch_mask for <${key}> returns <${mask}>" 14991853Sluigi} 15091853Sluigi 15191853Sluigi# set hostname, and ifconfig_${main_if} (whose MAC is ${main_ether}) 15291853Sluigi# if not found, read from console 15391853Sluigiset_main_interface() { 15491853Sluigi if [ -z "${hostname}" ] ; then 15591853Sluigi if [ -z "${main_ether}" ] ; then 15691853Sluigi echo "No ethernets found, using localhost" 15791853Sluigi hostname=localhost 15891853Sluigi return 15991853Sluigi fi 16091853Sluigi fetch_hostname ${main_ether} 16191853Sluigi fi 16291853Sluigi 16391853Sluigi [ -z "${hostname}" -o "${hostname}" = "." ] && read_address 16491853Sluigi 16591853Sluigi fetch_mask ${hostname}-netmask 16691853Sluigi 16791853Sluigi eval ifconfig_${main_if}=\" \${hostname} netmask \${mask}\" 16891853Sluigi network_interfaces=`ifconfig -l` 16991853Sluigi} 17091853Sluigi 17191853Sluigi# set ifconfig_${interface} for all other interfaces 17291853Sluigiset_all_interfaces() { 17391853Sluigi local i ether hostname mask 17491853Sluigi 17591853Sluigi for i in `ifconfig -l` ; do 17691853Sluigi if [ "$i" != "${main_if}" ] ; then 17791853Sluigi get_ether $i 17891853Sluigi fetch_hostname ${ether} 17991853Sluigi fetch_mask ${hostname}-netmask 18091853Sluigi [ -n "${ether}" -a -n "${hostname}" ] && \ 18191853Sluigi eval ifconfig_${i}=\" \${hostname} netmask \${mask}\" 18291853Sluigi fi 18391853Sluigi done 18491853Sluigi} 185