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
This commit is contained in:
16
sync-router
Normal file → Executable file
16
sync-router
Normal file → Executable file
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user