Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function help() {
- echo "Usage: $0 [ DIR | files ]"
- echo "Options:"
- echo " DIR - root directory where are subdirs for labs"
- echo " files - files to be converted"
- echo "Examples:"
- echo " $0 \"./CCNP/Configs for Trouble Tickets\""
- echo " $0 ./Lab101-ALS1-TT-A-Cfg.txt Laby1-R3-TT-B-Cfg.txt"
- }
- # $1 ... path to original config file
- # $2 ... original FastEthernet interface number (0/1, 1/1/1)
- # $3 ... IOU Ethernet interface number
- FastEthToEth() {
- if [ "$#" -ne 3 ]; then
- echo "Invalid args in FastEthToEth function call"
- exit 1
- fi
- oldiface=$(sed 's#/#\\/#' <<< $2)
- newiface=$(sed 's#/#\\/#' <<< $3)
- sed -i 's/FastEthernet'$oldiface'/Ethernet'$newiface'/g' "$1"
- }
- # $1 path to config file
- # $2 interface number to delete from config
- delete_FastEth() {
- iface=$(sed 's#/#\\/#' <<< $2)
- sed -i '/interface FastEthernet'$iface'/,/!/d' "$1"
- }
- # $1 path to config file
- # $2 interface number to delete from config
- delete_GigaEth() {
- iface=$(sed 's#/#\\/#' <<< $2)
- sed -i '/interface GigabitEthernet'$iface'/,/!/d' "$1"
- }
- # $1 ... path to original config file
- parse_file() {
- dn=$(dirname "$1")
- # Create new dir in iou_configs
- if [ ! -d "./iou_configs/$dn" ]; then
- mkdir -p "./iou_configs/$dn"
- fi
- fn=$(basename "$1")
- # Copy original to iou_configs dir
- cp "$1" "./iou_configs/$dn/$fn"
- new_file_path="./iou_configs/$dn/$fn"
- # Mappings of Lab interfaces to IOU interfaces
- # TODO
- # 1. Delete unused FastEthernet && GigabitEthernet ifs
- # 2. Rename some of the FastEthernet to corresponding unused Ethernet ifs
- if [[ $1 == *"-DLS1-"* ]]; then
- FastEthToEth "$new_file_path" 0/1 0/1
- FastEthToEth "$new_file_path" 0/2 0/0
- FastEthToEth "$new_file_path" 0/3 0/3
- FastEthToEth "$new_file_path" 0/4 0/2
- FastEthToEth "$new_file_path" 0/5 1/0
- FastEthToEth "$new_file_path" 0/6 1/1
- elif [[ $1 == *"-DLS2-"* ]]; then
- FastEthToEth "$new_file_path" 0/1 0/1
- FastEthToEth "$new_file_path" 0/2 0/0
- FastEthToEth "$new_file_path" 0/3 0/3
- FastEthToEth "$new_file_path" 0/4 0/2
- FastEthToEth "$new_file_path" 0/5 1/0
- FastEthToEth "$new_file_path" 0/18 1/1
- elif [[ $1 == *"-ALS1-"* ]]; then
- delete_FastEth "$new_file_path" 0/5
- delete_FastEth "$new_file_path" 0/6
- delete_FastEth "$new_file_path" 0/7
- delete_FastEth "$new_file_path" 0/8
- delete_FastEth "$new_file_path" 0/9
- delete_FastEth "$new_file_path" 0/10
- delete_FastEth "$new_file_path" 0/11
- delete_FastEth "$new_file_path" 0/12
- delete_FastEth "$new_file_path" 0/13
- delete_FastEth "$new_file_path" 0/14
- delete_FastEth "$new_file_path" 0/15
- delete_FastEth "$new_file_path" 0/16
- delete_FastEth "$new_file_path" 0/17
- delete_FastEth "$new_file_path" 0/19
- delete_FastEth "$new_file_path" 0/20
- delete_FastEth "$new_file_path" 0/21
- delete_FastEth "$new_file_path" 0/22
- delete_FastEth "$new_file_path" 0/23
- delete_FastEth "$new_file_path" 0/24
- delete_GigaEth "$new_file_path" 0/1
- delete_GigaEth "$new_file_path" 0/2
- FastEthToEth "$new_file_path" 0/1 0/1
- FastEthToEth "$new_file_path" 0/2 0/0
- FastEthToEth "$new_file_path" 0/3 0/3
- FastEthToEth "$new_file_path" 0/4 0/2
- FastEthToEth "$new_file_path" 0/18 1/1
- elif [[ $1 == *"-R1-"* ]]; then
- echo TODO
- elif [[ $1 == *"-R2-"* ]]; then
- echo TODO
- elif [[ $1 == *"-R3-"* ]]; then
- echo TODO
- else
- echo "Invalid path $1"
- fi
- }
- ###### MAIN ######
- # If no args supplied, print help and exit
- if [ "$#" -eq 0 ]; then
- help
- exit 1
- fi
- # If not created already, create folder for storing result configs
- if [ ! -d "./iou_configs" ]; then
- mkdir "./iou_configs"
- fi
- # If dir is supplied as arg, process it recursively
- if [ -d "$1" ]; then
- echo
- # If list of files is supplied as args, process them sequentialy
- else
- for file in "$@"; do
- if [ -f "$file" ]; then
- parse_file "$file"
- fi
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement