From 418e65bb684d78ad5eb196c16c8f0ff154020f14 Mon Sep 17 00:00:00 2001 From: Frederik Lindenaar Date: Tue, 4 Oct 2016 16:27:22 +0200 Subject: [PATCH] renamed fileto to filestore (makes more sense) resolved issue with determining upon upload whether we're dealing with the startup-config, this is now based on the destination file name (which is correct), fixes #5 --- sync-router | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) mode change 100644 => 100755 sync-router diff --git a/sync-router b/sync-router old mode 100644 new mode 100755 index cdd9025..e5fd69c --- a/sync-router +++ b/sync-router @@ -29,7 +29,7 @@ router=`basename \`dirname $0 | pwd\`` # name of router - based on directory dhcpfiles=dhcp-\* # list/pattern of dhcp lease files imagefiles=c??00-universalk9-mz.SPA.\* # list/pattern of IOS image files -fileto=flash # location of dhcp/IOS files on cisco +filestore=flash # location of dhcp/IOS files on cisco ### Implementation ### echo updating with $router @@ -41,9 +41,10 @@ echo updating with $router router_file_download() { fromfile=${1?ERROR: at least one filename is required to copy from router} tofile=${2:-$fromfile} - filesrc=$fileto if [ "$fromfile" == startup-config ]; then filesrc=nvram + else + filesrc=$filestore fi echo downloading $tofile from router $filesrc scp -q $router:$filesrc:$fromfile $tofile @@ -57,9 +58,10 @@ router_file_download() { router_file_upload() { fromfile=${1?ERROR: at least one filename is required to copy to router} tofile=${2:-$fromfile} - filedst=$fileto - if [ "$fromfile" == startup-config ]; then + if [ "$tofile" == startup-config ]; then filedst=nvram + else + filedst=$filestore fi echo uploading new/updated $tofile to router $filedst scp -q $fromfile $router:$filedst:$tofile @@ -74,7 +76,7 @@ router_file_upload() { router_file_remove() { delfile=${1?ERROR: need a filename to remove from router} echo removing $delfile as it is no longer in the repository - ssh -q $router "delete /force $fileto:$delfile" + ssh -q $router "delete /force $filestore:$delfile" } @@ -161,9 +163,9 @@ done # Update the boot images in the startup-config file if we're updating any images if git status -s "$imagefiles" | egrep -q ^[MADR]; then - fgrep -n "boot system $fileto" startup-config | cut -d: -f1 > .startup-config.$$.lines + fgrep -n "boot system $filestore" startup-config | cut -d: -f1 > .startup-config.$$.lines head -$[ `head -1 .startup-config.$$.lines` -1 ] startup-config > .startup-config.$$ - git ls-files $imagefiles | sort -r | sed "s/^/boot system $fileto /g" >> .startup-config.$$ + git ls-files $imagefiles | sort -r | sed "s/^/boot system $filestore /g" >> .startup-config.$$ tail +$[ `tail -1 .startup-config.$$.lines` +1 ] startup-config >> .startup-config.$$ rm .startup-config.$$.lines router_file_upload .startup-config.$$ startup-config