Working from the Console or Shell
System Configuration
sysconfig is single data store configuration and interface program to manipulate the data store.
A simple and consistent interface was developed for the UI interface without having to develop a different parsing method for each system configuration file. The system configuration uses templates to substitutes the configurable variables to produce the resulting configuration file used by the processes and system services.
This allows system script could interface to the data store in a consistent way and attempts to keep configuration of command line users and GUI users in sync.
The data store is located at /conf/sysconfig
Configuration Templates
The system application uses a set of templates to generate the configurations file to be used by the individual system services. It is by this method that the system and the administrator can interact with the system to change the behavior without requiring a change in the application software.
The administor can find these files in /conf/templates/
dhcpfwd.conf.tpl
dnsmasq.conf.tpl
firewall.conf.tpl
hostapd.conf.tpl
keepalived.conf.tpl
ntpdate.conf.tpl
olsrd.conf.tpl
rc.conf.tpl
resolv.conf.tpl
snmpd.local.conf.tpl
tspc.conf.tpl
udhcpd.conf.tpl
wpai_supplicant.conf.tpl
xwired.conf.tpl
sysconfig the Programs
/bin/sysconfig is the command line program that manipulates /conf/sysconfig - the data store. sysconfig is a command line tool that can pass the configuration parameters to the scripts. These parameters are updated and shared by the GUI application.
profile_setup -- a helper function for first time boot discovery of
interface names, MACi address assignments, and profile to interface
assignments to initialize sysconfig profile settings.
/var/run/rc.conf is generated from this data directly using `sysconfig -c rc`
The same is true for the following custom conf files that do not conform to key/value approach to variables and parameters. Or just a lazy programmer that did not want to develop a UI for every know parameter.
sysconfig -c rc
rc /var/run/rc.conf
tspc /conf/tspc.conf
resolv /etc/resolv.conf
dhcpi /conf/udhcpd.conf
firewall /conf/firewall.conf
ntpi /conf/ntpdate.conf
hostap /conf/hostapd.{interface}.confwpa /conf/wpasupplicant.conf
all Generate all of the above.
Other command line interface options for sysconfig are as follows:
sysconfig -f
Create or reset to factory defaults
sysconfig -p -s System -v hostname
Print the value from "hostname" from section [System]
sysconfig -w -s System -v hostname=bugsbunny
Write the value "bugsbunny" from "hostname" from section [System]
sysconfig -l -s process
List entire section as key/value pairs
sysconfig -c all | rc | tspc | resolv | dhcp | firewall | ntp | hostapd | wap [-o /path/fn]
Create custom .conf files
sysconfig -z
Convert from INI format to filesystem tree format -- not use yet.
Writing Scripts Using sysconfig
Typically a script can include a conf file of key/value pairs such as
#!/bin/sh
. /conf/ntpdate.conf
The same thing can be accomplished using sysconfig as follows:
#!/bin/sh
sysconfig -l -s ntp > /var/tmp/tmp.$$$
. /var/tmp/tmp.$$$
To retrieve a single value from a key:
TZ=`sysconfig -p -s ntp -v tz`
For example , to lists ntp section of key value pairs to stdout :
# sysconfig -l -s ntp
enabled="TRUE"
type="dyndns"
host="xwire.homeip.net"
user="user"
passwd="password"
To produce a custom file for /etc/resolv.conf
# sysconfig -c resolv
search xwire.com
nameserver 192.168.4.2
nameserver 192.168.4.3
To change the country code in the [System] section:
# sysconfig -w -s system -v countrycode="TO"
# sysconfig -l -s system
version="Xwire-1.0.38-Linux-2.4.27-xw"
hostname="Xmesh"
domainname="xwire.com"
location="123 Main Street"
countrycode="TO"
citycode="AMS"
postalcode="1017DM"
originalmac="00:00:00:00:00:01"
current_mac="00:00:00:00:00:01"
dns1="192.168.3.6"
dns2="192.168.3.7"
dmz="10.10.10.10"
Scripting Examples
The following sample scripts provide some useful tasks based on sysconfig configuration.
The following script changes the WWAN profile to act as client wireless device and connect to another APi using WEPi encryption and provide a wireless uplink. This might be considered a range extending profile.
#!/bin/sh
. /etc/init.d/functions
IPTABLES=/sbin/iptables
SC=/bin/sysconfig
get_ifname()
{
$SC -p -s profile -v $1
}
WWAN_IF=`get_ifname wwan`
/etc/scripts/rc.inet stop wwan
echo -n "Changing the system the configuration ..."
#+ Turn off unneeded stuff
#+ Turn off routing
$SC -w -s process -v zebra_enable=No
$SC -w -s process -v ospfd_enable=No
$SC -w -s process -v ospfd_enable=No
$SC -w -s process -v olsrd_enable=No
#+ Turn off xwired
$SC -w -s xwired -v enable=FALSE
#+ Change WWAN profile to act as client
#+ Wireless mode managed
$SC -w -s wwan -v mode=managed
#+ Autoip DHCP client
$SC -w -s wwan -v autoip=1
#+ Enable NATi and disable SNATi
$SC -w -s wwan -v nat=TRUE
$SC -w -s wwan -v snat=FALSE
#+ Enable encryption -- CHANGE ME!!
$SC -w -s wwan -v encryption_method=1
$SC -w -s wwan -v wep_default_tx_key=1
$SC -w -s wwan -v wep_key_size=64
$SC -w -s wwan -v wep_key1=7877697265
$SC -w -s wwan -v wep_key2=7877697265
$SC -w -s wwan -v wep_key3=7877697265
$SC -w -s wwan -v wep_key3=7877697265
$SC -w -s wwan -v wep_key4=7877697265
/etc/scripts/rc.inet start wwan
$IPTABLES -t nat -A POSTROUTING -o $WWAN_IF -j MASQUERADE
The following script overrides the default factory reset script to save the current PPPoEi and DDNSi configuration and restores these value after all configuration has been set to factory defaults. This script does reside on the filesystem at /bin/customfactoryreset.sh and is activated if copy to /conf
#!/bin/sh
# Example custom reset. Copy to /conf to override default
pppoe_enabled=`sysconfig -p -s PPPoE -v status` #FIXME: enabled
ddns_enabled=`sysconfig -p -s ddns -v enabled`
if [ $ddns_enabled = TRUE ]; then
ddns_user=`sysconfig -p -s ddns -v user`
ddns_password=`sysconfig -p -s ddns -v passwd`
ddns_type=`sysconfig -p -s ddns -v type`
ddns_host=`sysconfig -p -s ddns -v host`
fi
if [ $pppoe_enabled = TRUE ]; then
pppoe_user=`sysconfig -p -s PPPoE -v username`
pppoe_password=`sysconfig -p -s PPPoE -v password`
pppoe_keepalive=`sysconfig -p -s PPPoE -v keepalive`
pppoe_maxidle=`sysconfig -p -s PPPoE -v maxidle`
fi
rm -rfi /conf/.xwirefirstboot
rm -rf /conf/.htpasswd
rm -rf /conf/*
if [ $ddns_enabled = TRUE ]; then
sysconfig -w -s ddns -v enabled=TRUE
sysconfig -w -s ddns -v user=$ddns_user
sysconfig -w -s ddns -v passwd=$ddns_password
sysconfig -w -s ddns -v type=$ddns_type
sysconfig -w -s ddns -v host=$ddns_host
fi
if [ $pppoe_enabled = TRUE ]; then
sysconfig -w -s PPPoE -v status=TRUE
sysconfig -w -s PPPoE -v username=$pppoe_user
sysconfig -w -s PPPoE -v password=$pppoe_password
sysconfig -w -s PPPoE -v keepalive=$pppoe_keepalive
sysconfig -w -s PPPoE -v maxidle=$pppoe_maxidle
fi
sync
sleep 5
/sbin/reboot
The following script was the result of developing with various wireless cards and swapping them in and out. This script quickly resets the interface profiles and adjusts all services and configuration files that act on the changed interface. The actual script is located at /bin/changewnics.sh and used as /bin/changewnics.sh WWAN [ WLANi ] . For example,
/bin/changewnics.sh ath1 ath0
#!/bin/sh
# Quickie script to swap or change wireless nics
if [ ! -n "$2" -a ! -n "$1" ]; then
echo "Not enough parameters."
echo "$0 wwan_if [wlan_if]"
echo "Example: $0 eth2 ath0"
exit 1;
fi
if [ -n "$2" ]; then
echo "$0: Changing wlan_if to $2"
/etc/scripts/rc.inet stop wlan
sysconfig -w -s Profile -v wlan=$2
/etc/scripts/rc.inet start wlan
fi
if [ -n "$1" ]; then
echo "$0: Changing wwan_if to $1"
/etc/scripts/rc.inet stop wwan
sysconfig -w -s Profile -v wwan=$1
killall olsrd
sysconfig -c olsrd
/sbin/olsrd -f /conf/olsrd.conf
/etc/scripts/rc.inet start wwan
spy1=`sysconfig -p -s Profile -v wlan`
spy2=`sysconfig -p -s Profile -v wwan`
scan=`sysconfig -p -s Profile -v wwan`
sysconfig -w -s Xwire -v InterfaceSpy="$spy1 $spy2"
sysconfig -w -s Xwire -v InterfaceScan="$scan"
enabled=`sysconfig -p -s Process -v xwired_enabled`
sysconfig -c xwired
iptables -t nat -A POSTROUTING -o $spy2 -j MASQUERADE
killall xwired
if [ $enabled = TRUE ]; then
/sbin/xwire -c /conf/xwired.conf
fi
fi