switchconf/0000755000175000017500000000000011323413245011303 5ustar calcalswitchconf/TODO0000644000175000017500000000040411323363420011770 0ustar calcal* Move svn repository from personal computer to alioth. * Setup a english page for anyone that is looking for it. * Make a proper config and install, so it can be installed from source. * Define a policy for accepting new plugins and when to run them. switchconf/build-stamp0000644000175000017500000000000011323365654013447 0ustar calcalswitchconf/examples/0000755000175000017500000000000011302342214013113 5ustar calcalswitchconf/examples/home/0000755000175000017500000000000011302344641014051 5ustar calcalswitchconf/examples/home/etc/0000755000175000017500000000000011302345402014620 5ustar calcalswitchconf/examples/home/etc/resolv.conf0000644000175000017500000000005410351331202016774 0ustar calcalsearch myhome.org nameserver 192.168.0.254 switchconf/examples/home/etc/network/0000755000175000017500000000000011302345670016320 5ustar calcalswitchconf/examples/home/etc/network/interfaces0000644000175000017500000000025110351331202020351 0ustar calcalauto lo iface lo inet loopback iface eth0 inet static address 192.168.0.16 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.254 switchconf/examples/home/etc/hosts0000644000175000017500000000007210351331202015676 0ustar calcal127.0.0.1 localhost 192.168.0.16 myhost.myhome.org myhost switchconf/examples/work/0000755000175000017500000000000011302344641014103 5ustar calcalswitchconf/examples/work/etc/0000755000175000017500000000000011302345402014652 5ustar calcalswitchconf/examples/work/etc/resolv.conf0000644000175000017500000000005310351331202017025 0ustar calcalsearch mycompany.com nameserver 10.0.0.1 switchconf/examples/work/etc/network/0000755000175000017500000000000011302345670016352 5ustar calcalswitchconf/examples/work/etc/network/interfaces0000644000175000017500000000023410351331202020404 0ustar calcalauto lo iface lo inet loopback iface eth0 inet static address 10.0.1.42 netmask 255.0.0.0 network 10.0.0.0 broadcast 10.255.255.255 gateway 10.0.0.1 switchconf/examples/work/etc/hosts0000644000175000017500000000007210351331202015730 0ustar calcal127.0.0.1 localhost 10.0.1.42 myhost.mycompany.com myhost switchconf/plugins.before/0000755000175000017500000000000011302342214014217 5ustar calcalswitchconf/plugins.before/20pcmcia0000755000175000017500000000024310505303262015546 0ustar calcal#!/bin/sh if [ -x /etc/init.d/pcmcia ] ; then if which invoke-rc.d >/dev/null 2>&1; then invoke-rc.d pcmcia stop else /etc/init.d/pcmcia stop fi fi switchconf/conf0000644000175000017500000000126511323413245012157 0ustar calcal# Where are located the different configurations conf_top_dirs=/etc/switchconf # What is the top level directory of the installation dest_dir=/ # What is the name of the exec directory (all files included will # be executed before or after configuration changes) exec_dir_before=before.d exec_dir_after=after.d # What is the path to run-parts. Leave empty if you want to use the # internal implementation run_parts=/bin/run-parts # defines how to copy files to their configuration place. # 'softlink' - uses soft linking to copy the files # 'hardlink' - uses hardlinks to copy the files # 'copy' - uses cp to copy the files # 'softlink' is the default value config_method=softlink switchconf/test10000755000175000017500000000520410656210304012271 0ustar calcal#!/bin/bash -x set -e function gen-conf () { CONFDIR="$1" DESTDIR="$2" METHOD="$3" cat >"/etc/switchconf/conf" < "$CONFDIR/test1a/test1" echo test1b > "$CONFDIR/test1b/test1" # Test switch by cp gen-conf "$CONFDIR" "$DESTDIR" copy if test -e "$DESTDIR/test1" ; then echo "Failed to setup test1" exit 1 fi ./switchconf test1a if ! test -e "$DESTDIR/test1" ; then echo "Failed to create file" exit 1 fi if ! grep test1a "$DESTDIR/test1" ; then echo "Failed to put the right file in place" exit 1 fi if ! test -e "$DESTDIR/test1" ; then echo "Failed to setup test1" exit 1 fi ./switchconf test1a if ! test -e "$DESTDIR/test1" ; then echo "Failed to create file" exit 1 fi if ! grep test1a "$DESTDIR/test1" ; then echo "Failed to put the right file in place" exit 1 fi # Test switch by softlink gen-conf "$CONFDIR" "$DESTDIR" softlink rm -f "$DESTDIR/test1" if test -e "$DESTDIR/test1" ; then echo "Failed to setup test1" exit 1 fi ./switchconf test1a if ! test -e "$DESTDIR/test1" ; then echo "Failed to create file" exit 1 fi if ! test -L "$DESTDIR/test1" ; then echo "Failed to create link" exit 1 fi if ! grep test1a "$DESTDIR/test1" ; then echo "Failed to put the right file in place" exit 1 fi if ! test -e "$DESTDIR/test1" ; then echo "Failed to setup test1" exit 1 fi ./switchconf test1a if ! test -e "$DESTDIR/test1" ; then echo "Failed to create file" exit 1 fi if ! test -L "$DESTDIR/test1" ; then echo "Failed to create link" exit 1 fi if ! grep test1a "$DESTDIR/test1" ; then echo "Failed to put the right file in place" exit 1 fi # Test switch by hardlink gen-conf "$CONFDIR" "$DESTDIR" hardlink rm -f "$DESTDIR/test1" if test -e "$DESTDIR/test1" ; then echo "Failed to setup test1" exit 1 fi ./switchconf test1a if ! test -e "$DESTDIR/test1" ; then echo "Failed to create file" exit 1 fi if ! grep test1a "$DESTDIR/test1" ; then echo "Failed to put the right file in place" exit 1 fi if ! test -e "$DESTDIR/test1" ; then echo "Failed to setup test1" exit 1 fi ./switchconf test1b if ! test -e "$DESTDIR/test1" ; then echo "Failed to create file" exit 1 fi if ! grep test1b "$DESTDIR/test1" ; then echo "Failed to put the right file in place" exit 1 fi switchconf/test20000755000175000017500000000217610656210304012277 0ustar calcal#!/bin/bash set -e # test the funcionality of init.d # Check if the Setup for the test work CODE=`grep conf= debian/init.d` CMDLINE=`mktemp` cp /proc/cmdline $CMDLINE chmod u+w $CMDLINE eval $CODE conf=${conf:-vazio} if [ $conf != "vazio" ] ; then echo "Failed to setup test" echo "conf=$conf" echo "$CMDLINE=" `cat $CMDLINE` exit 1 fi echo "switchconf=end" >>$CMDLINE eval $CODE if [ A$conf != "Aend" ] ; then echo "Failed to read option from end" echo "conf=$conf" echo "$CMDLINE=" `cat $CMDLINE` exit 1 fi echo "switchconf=start" > $CMDLINE cat /proc/cmdline >> $CMDLINE eval $CODE if [ A$conf != "Astart" ] ; then echo "Failed to read option from start" echo "conf=$conf" echo "$CMDLINE=" `cat $CMDLINE` exit 1 fi echo "test middle2 switchconf=middle test4" > $CMDLINE eval $CODE if [ A$conf != "Amiddle" ] ; then echo "Failed to read option from middle" echo "conf=$conf" echo "$CMDLINE=" `cat $CMDLINE` exit 1 fi echo "switconf=start test middle2 switchconf=middle test4 switchconf=end" > $CMDLINE eval $CODE echo "For multiple options in cmdline conf=$conf" rm $CMDLINE switchconf/switchconf.80000644000175000017500000000534411322222352013545 0ustar calcal.TH switchconf 8 "April 2002" "Version 0.0.1" .UC 8 .SH "NAME" switchconf \- Change system configuration to one of many predefined .SH SYNOPSIS .sp \fBswitchconf\fR [ \fI-list\fR | \fIconfig_scheme\fR ] .SH "DESCRIPTION" .PP \fBswitchconf\fR is a command line tool that helps nomad laptop users to easily change their configuration. .SH "OPTIONS" .PP \fBswitchconf\fR takes only one argument. If this argument is \fI-list\fR, a list of all known configuration schemes is returned (found in $conf_top_dirs). If the argument is a configuration scheme, this configuration will be installed on the laptop. .SH "CONFIGURATION FILE" .PP The configuration file (\fI/etc/switchconf/conf\fR) is simple. The following entries are defined: .TP \fIconf_top_dirs\fR This specify where are located the configurations schemes. .TP \fIdest_dir\fR This specify in which top directory you want to install the new configuration. This option is pretty useful if you want to debug your configuration without overwritting the actual one. .TP \fIexec_dir_before\fR, \fIexec_dir_after\fR This specify the name of the exec directory : all files included will be executed before or after configuration changes .TP \fIrun_parts\fR This specify the path to the run-parts command, that is used to execute the scripts. Leave it empty to use the internal implementation of run-parts. .TP \fIconfig_method\fR This specify the method to use to copy the configuration files, to their places: softlink, hardlink, copy .PP \fI/etc/switchconf/conf\fR should be written so it is parsable as a shell script - There should be no spaces between the variable name and its value. .SH "SCHEMES" You should create a directory for each configuration scheme you define, including all the files it should set in the system. Inside /etc/switchconf the directories you should create the files including the full path (i.e., \fI/etc/switchconf/home/etc/network/interfaces\fR for \fI/etc/network/interfaces\fR). .PP No scheme should be named as either the exec_dir_before or the exec_dir_after, unless the conf_top_dirs is moved out of its default directory, \fI/etc/switchconf\fI. .PP Although it is not really necessary, you should probably ensure that all the files existing in one of the schemes exist on every other scheme, in order to ensure you do not end up in a hybrid state. .SH "FILES" .TP \fB\fI/etc/switchconf/conf\fB\fR Configuration file. .TP \fB\fI/var/lib/misc/switchconf.lastcfg\fB\fR Memory file, has the name of the current active scheme .SH "BUGS" Actually no bugs are reported. .SH "AUTHOR" .PP \fBswitchconf\fR was written by Sebastien J. Gross \fBswitchconf\fR was contributed by Julien Ducros \fBswitchconf\fR was maintained by Jose Calhariz switchconf/init.d0000644000175000017500000000676210673233150012430 0ustar calcal#!/bin/sh ### BEGIN INIT INFO # Provides: switchconf # Required-Start: $local_fs # Required-Stop: # Default-Start: S # Default-Stop: # Short-Description: Switchconf at boot time based on kernel options # Description: This file should be used to construct scripts to be # placed in /etc/init.d. ### END INIT INFO # Author: Eric Lavarde # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="switching configuration using kernel option" NAME=switchconf DAEMON=/usr/sbin/$NAME DAEMON_ARGS="--options args" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME CMDLINE="/proc/cmdline" # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. [ -r /lib/lsb/init-functions ] && . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started if [ ! -f $CMDLINE ] ; then log_failure_msg "File '$CMDLINE' does not exist." return 2; fi if [ ! -r $CMDLINE ] ; then log_failure_msg "File '$CMDLINE' not readable." return 2; fi conf="$(sed -rne 's/(.*[[:space:]]|^)switchconf=([^[:space:]]+).*/\2/p' "$CMDLINE" | tr -d \\n)" if [ -z "${conf}" ] ; then [ "$VERBOSE" != no ] && log_action_msg " No switchconf kernel option" return 0; else log_action_msg " Switching to config '${conf}'" $DAEMON "${conf}" >/dev/null || log_end_msg 2 return 0 fi # Add code here, if necessary, that waits for the process to be ready # to handle requests from services started subsequently which depend # on this one. As a last resort, sleep for some time. } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred : Nothing to be done... # Wait for children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. # If the above conditions are not satisfied then add some other code # that waits for the process to drop all resources that could be # needed by services started subsequently. A last resort is to # sleep for some time. # Many daemons don't delete their pidfiles when they exit. return 0 } case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0) log_end_msg 0 ;; 1|2) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" exit 3 ;; esac switchconf/README0000644000175000017500000000052110615652063012167 0ustar calcalAs of 2005/04/27 I am officially taking over of developing switchconf. This program was created by Sebastien J. Gross and had contributions from: Julien Ducros , Eric Lavarde -- Jose Calhariz , Wed Apr 27 00:13:25 2005 switchconf/plugins.after/0000755000175000017500000000000011302342214014056 5ustar calcalswitchconf/plugins.after/20pcmcia0000755000175000017500000000024510505303261015406 0ustar calcal#!/bin/sh if [ -x /etc/init.d/pcmcia ] ; then if which invoke-rc.d >/dev/null 2>&1; then invoke-rc.d pcmcia start else /etc/init.d/pcmcia start fi fi switchconf/logrotate0000644000175000017500000000012410673233150013225 0ustar calcal/var/log/switchconf { weekly missingok rotate 2 compress create 640 root adm } switchconf/switchconf0000755000175000017500000000640511323361511013403 0ustar calcal#!/bin/sh # switchconf -- Easy configuration switch # # (c) 2002 Sebastien J. Gross # (c) 2005 Jose Calhariz # Please see the COPYRIGHT file included in the package. # $Id: switchconf,v 1.9 2002/04/22 19:04:45 jul Exp $ # logfile="/var/log/switchconf" memfile="/var/lib/misc/switchconf.lastcfg" lockfile="/var/lock/switchconf" if [ -f /etc/switchconf/conf ]; then . /etc/switchconf/conf elif [ -f ./conf ]; then . ./conf else echo "Configuration file not found" exit fi help() { echo "Syntax: switchconf [ configuration | -list | -help ]" exit 0 } list() { cd ${conf_top_dirs} find -maxdepth 1 -type d | sed 's/^\.\/\?//' | grep -v "\(^\$\|${exec_dir_before}\|${exec_dir_after}\)" | sort exit 0 } run_scripts(){ local scriptsdir=$1 shift if test -x "${run_parts}" ; then echo "Executing scripts: "; ${run_parts} --arg "${conf}" -v "$scriptsdir" 2>&1 | tee -a ${logfile} echo "Executing scripts done."; else echo "Executing scripts: "; for r in `find ${scriptsdir} -type f -perm +1 | sort`; do echo "$r" | tee -a ${logfile} ${r} "${conf}" 2>&1 | tee -a ${logfile} done echo "Executing scripts done."; fi } run_scripts_before(){ run_scripts ${conf_top_dirs}/${exec_dir_before} } run_scripts_after(){ run_scripts ${conf_top_dirs}/${exec_dir_after} } # validates configuration file config_method=${config_method:=softlink} case ${config_method} in softlink) ;; hardlink) ;; copy) ;; *) echo "Check you configuration" echo "config_method option have unsupported value'$config_method'" exit esac [ $# -eq 1 ] || help conf=$1 case ${conf} in -list | -l ) list ;; -help | -h ) help ;; esac cd ${conf_top_dirs} if [ ! -d ${conf} ]; then echo "Configuration ${conf} not found" fi # Check last run of switchconf have stoped if ! dotlockfile -p -l -r 1 "${lockfile}" ; then echo "There is another switchconf still runing" | tee -a ${logfile} echo "Aborting" | tee -a ${logfile} exit 1; fi # executing each scripts before run_scripts_before for f in `find ${conf} ! -type d | sed "s/^${conf}\///"`; do dir=`dirname ${dest_dir}/${f}` [ -d ${dir} ] || mkdir -p ${dir} case ${config_method} in copy) if test -e ${dest_dir}/${f} ; then mv -f ${dest_dir}/${f} ${dest_dir}/${f}.SWITCHCONF && \ cp -fa ${conf_top_dirs}/${conf}/${f} ${dest_dir}/${f} && \ rm -f ${dest_dir}/${f}.SWITCHCONF else cp -fa ${conf_top_dirs}/${conf}/${f} ${dest_dir}/${f} fi ;; hardlink) if test -e ${dest_dir}/${f} ; then mv -f ${dest_dir}/${f} ${dest_dir}/${f}.SWITCHCONF && \ cp -fal ${conf_top_dirs}/${conf}/${f} ${dest_dir}/${f} && \ rm -f ${dest_dir}/${f}.SWITCHCONF else cp -fal ${conf_top_dirs}/${conf}/${f} ${dest_dir}/${f} fi ;; softlink|*) if test -e ${dest_dir}/${f} ; then mv -f ${dest_dir}/${f} ${dest_dir}/${f}.SWITCHCONF && \ ln -s ${conf_top_dirs}/${conf}/${f} ${dest_dir}/${f} && \ rm -f ${dest_dir}/${f}.SWITCHCONF else ln -s ${conf_top_dirs}/${conf}/${f} ${dest_dir}/${f} fi esac done # executing each scripts after run_scripts_after echo "${conf}" > ${memfile} # remove lock dotlockfile -u "${lockfile}" exit 0 switchconf/changelog0000644000175000017500000000173610353527744013200 0ustar calcal2005-12-18 Jose Calhariz * New version 0.0.5.1 to fix an error handling orig.tar.gz 2005-10-16 Jose Calhariz * New version to close Debian bugs #332916, #332918 and #332920 * 20pcmcia: renamed from pcmcia to make easy to control the order of running the plugins. 2005-04-27 Jose Calhariz * README: Indicating I am now taking over of switchconf * debian/copyright: Indicating the old author and I am the new author. * debian/README.Debian: removed * switchconf: Added a copyright of myself. * switchconf.8: Adding myself as maintainer. 2005-04-25 Jose Calhariz * TODO: updated * Makefile: is more powerfull to help me mantain the softare. * debian/copyright: reflets that I am now upstream. * debian/README.Debian: explain how switchconf can be used with pointers for discussion in debian-developers, so ftpmasters can accept it again into Debian. switchconf/Makefile0000644000175000017500000000216010772221416012746 0ustar calcal#!/usr/bin/make -f # -*- makefile -*- PACKNAME=switchconf BINDIR=/usr/sbin ETCDIR=/etc/$(PACKNAME) MANDIR=/usr/share/man/man8 LOGROTATEDIR=/etc/logrotate.d INITDIR=/etc/init.d all: echo $(PACKNAME) configure: build: install: [ -d $(DESTDIR)/$(MANDIR) ] || mkdir -p $(DESTDIR)/$(MANDIR) cp $(PACKNAME).8 $(DESTDIR)/$(MANDIR) [ -d $(DESTDIR)/$(ETCDIR) ] || mkdir -p $(DESTDIR)/$(ETCDIR) [ -d $(DESTDIR)/$(ETCDIR)/before.d ] || mkdir -p $(DESTDIR)/$(ETCDIR)/before.d [ -d $(DESTDIR)/$(ETCDIR)/after.d ] || mkdir -p $(DESTDIR)/$(ETCDIR)/after.d [ -d $(DESTDIR)/$(LOGROTATEDIR)/ ] || mkdir -p $(DESTDIR)/$(LOGROTATEDIR) cp logrotate $(DESTDIR)/$(LOGROTATEDIR)/$(PACKNAME) cp conf $(DESTDIR)/$(ETCDIR) cp plugins.before/* $(DESTDIR)/$(ETCDIR)/before.d/ cp plugins.after/* $(DESTDIR)/$(ETCDIR)/after.d/ install -D init.d $(DESTDIR)/$(INITDIR)/$(PACKNAME) install -D $(PACKNAME) $(DESTDIR)/$(BINDIR)/$(PACKNAME) test: ./test1 ./test2 clean: find -name '*~' -exec rm {} \; #rm -f configure-up-stamp unpack-up-stamp build-up-stamp install-up-stamp .PHONY: build clean binary-indep binary-arch binary install configure