#!/bin/bash # ################################################## ## ipchange: version .00000005 ## ## Purpose: ## ## To switch ip settings quickly ## ## ## ## Requires: ## ## Config files for each location ## ## which have been created by yast. ## ## i.e. /etc/pcmcia/network.opts. ## ## ## ## Setup: ## ## For each location, ## ## setup network for a given location is yast ## ## cp /etc/pcmcia/network.opts \ ## ## /etc/pcmcia/network.opts. ## ## ## ## COPYRIGHT NOTICE: ## ## Copyright 2000 All Rights Reserved. ## ## Created by: John Streeton Stile ## ## email: john@stilen.com ## ## ## ## Context: ## ## This must be run with all mighty root. ## ################################################## ####################################################### # check to see if they are root # # if they are not root, they can't edit the files # ####################################################### function am_i_root { Me=`whoami` if [[ $Me != "root" ]] then echo -e "\nGotta be su to run this ...." sleep 3 exit 1 fi } function slash_screen { BOLD=$(tput smso) NOBOLD=$(tput rmso) clear cat <<- EOT ${BOLD}Made for SUSE Linux${NOBOLD} Switch ip settings at work and home This requries config files for each location stored in /etc/pcmcia/network.opts. Press any key to continue. EOT read bla } function non_interactive { if [ -n "$blabla" ] then for network in $networks do if [ "$blabla" = `echo $network | awk -F. '{ print $3}'` ] then # echo -n "Setting network scheme '$blabla' ... " Location="$blabla" activate_location exit 0 fi done #echo "$blabla Isn't my list" > /dev/stderr fi } ################################################ # Main Menu, options to see/change settings # Every function should return to this menu. ################################################ function menu { BOLD=$(tput smso) NOBOLD=$(tput rmso) while true do clear cat <<- ENDMENU ${BOLD}SuSE Linux ipchange.bash (v..00000004)${NOBOLD} Location: `echo $Location` ${BOLD}Variables${NOBOLD} ${BOLD}Settings${NOBOLD} 1) Activate Location 4) Remove Location 2) Modify Location 5) Rename Location 3) Add New Location 6) Display Location X) Exit ENDMENU echo -e "Enter Choice: \c" read choice case "$choice" in 1 ) # Activate Location locations activate_location menu exit 0 ;; 2 ) # Modify Location locations modify_location menu exit 0 ;; 3 ) # Add Location add_location menu exit 0 ;; 4 ) # Remove Location locations remove_locaion menu exit 0 ;; 5 ) # Rename Locaion locations rename_locaion menu exit 0 ;; 6 ) # Display Location locations display_location menu exit 0 ;; [xX] ) exit 0 ;; * ) echo "$choice" exit 1 ;; esac done } ################################################ # Locations - ask which location to look at # It checks to see if input was valid # Then return to the the next line in menu ################################################ function locations { # # Updated 2001 06 26 : "select" takes a list, # numbers each entery on , then it # prompts with PS3, for the user to make a selection. # If valid, it executes the code before the "done" # Make the prompt message. PS3old="$PS3" PS3="Choose Location: " # Make a list of available networks options=`ls /etc/pcmcia/network.opts.* |awk -F'.' '{print $3}'` export options # Number the options, and let them choose select Location in $options; do # Set the variable echo "$Location" export Location # Return the Prompt PS3="$PS3old" return done } ################################################ # 1) activate location - calls locations, # - copies current to last # - moves Location to current # - returns to the menu ################################################ function activate_location { echo "Activating location $Location" cp /etc/pcmcia/network.opts /etc/pcmcia/network.opts.last cp /etc/pcmcia/network.opts.$Location /etc/pcmcia/network.opts /etc/init.d/pcmcia restart } ################################################ # 2) modify location - cp Location to Location-