Inhaltsverzeichnis

sbreconfig

Introduction

An adjustable configuration switcher.

This script can be used to switch between several different preconfigured settings. Use it for example to quickly adjust the network settings of your notebook for office or home use.

FIXME add more info!

Howto by Example

We want to use the script to switch between office and home network settings. On Slackware for example you could also use netconfig for this task (or Yast on Suse) but this is too cumbersome for daily usage. Fortunately on linux under the hood all configuration settings are read from text files and netconfig does nothing more than to edit some of them. sbreconfig does the same, but just copies the content from template files. We'll stick with netconfig in this example, but any other config tool on any other linux distro could also be used.

cp /etc/rc.d/rc.inet1.conf /etc/rc.d/rc.inet1.conf.home
cp /etc/HOSTNAME /etc/HOSTNAME.home
cp /etc/hosts /etc/hosts.home
cp /etc/networks /etc/networks.home
cp /etc/resolv.conf /etc/resolv.conf.home
 
cp /etc.bak/rc.d/rc.inet1.conf /etc/rc.d/rc.inet1.conf.office
cp /etc.bak/HOSTNAME /etc/HOSTNAME.office
cp /etc.bak/hosts /etc/hosts.office
cp /etc.bak/networks /etc/networks.office
cp /etc.bak/resolv.conf /etc/resolv.conf.office

Note: It is also possible to create default template config files. They have the extension .dflt. They will be read if the specific template config file is not found. Thus the same config file can be used for different configurations. For the hostname the default template config file would be/etc/HOSTNAME.dflt. But this feature is only useful for more than 2 different configurations.

#!/bin/bash 
# /etc/sbreconfig/network 
 
# "public" is meant to access an open public wlan without password
# With "public" only dflt shall be used
# For access to a new wpa encrypted WLAN, it is only necessary to create a
# wpa_supplicant.conf.<newname> file. Everything else shall be .dflt
 
# List of allowed configurations. This corresponds to the extensions of the 
# config template files 
conflist='public home.wired home.wlan office' 
 
# List of configuration files to be manipulated 
filelist='/etc/wpa_supplicant.conf /etc/rc.d/rc.inet1.conf /etc/HOSTNAME /etc/hosts /etc/networks /etc/resolv.conf' 
 
# optional: What to do before copying the files: 
dobefore='' 
 
# optional: What to do after copying the files: 
doafter='/etc/rc.d/rc.inet1 restart' # restart the network to apply the changes

From now on you can switch to office network settings just by issuing the command sbreconfig network office and back to home network settings by sbreconfig network home.

sbreconfig does this by copying the template files to their real counterparts specified in the filelist variable. In this expample cp /etc/rc.d/rc.inet1.conf.home /etc/rc.d/rc.inet1.conf; cp /etc/HOSTNAME.home /etc/HOSTNAME; …

If you need a 3rd network setting later, just create a bunch of config files with a proper extension: /etc/rc.d/rc.inet1.conf.melanie /etc/HOSTNAME.melanie …

Source

FIXME