From e5a90c9bd0a74df23d84a4a56538a2a696433c58 Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Fri, 14 Dec 2012 09:26:42 -0500 Subject: [PATCH] adding utility to update lib_ips.txt in a multibrick environment --- update-libips.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 update-libips.sh diff --git a/update-libips.sh b/update-libips.sh new file mode 100755 index 0000000..5d7e553 --- /dev/null +++ b/update-libips.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# Copyright (C) 2012 Georgia Public Library Service +# Chris Sharp +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +OSRF_CONF_DIR="/openils/conf" +LIB_IPS_TXT="$OSRF_CONF_DIR/lib_ips.txt" +BRICK_HEADS="6" + +[[ $(whoami) != "opensrf" ]] && echo "Must be opensrf user to run this utility." && exit + +QueryFile () { +echo "Would you like to query by library name or by IP address?" +echo +echo "[1] Library name" +echo "[2] IP Address" +echo +read -p "Please choose option 1 or 2: " CHOICE +if [ "$CHOICE" = "1" ]; then + read -p "What is the partial or full library shortname (e.g., ECGR-CCO, WGRL) for which you'd like to see the IP range? " SHORTNAME + grep -i "$SHORTNAME" $LIB_IPS_TXT | sort; +elif [ "$CHOICE" = "2" ]; then + read -p "What is the partial or full IP address (e.g. 172.16.10.1, 10.1.1) for which you'd like to see the library name? " IP_ADDR + grep $IP_ADDR $LIB_IPS_TXT | sort; +else + echo "No valid response received. Aborting." + exit; +fi +} + +UpdateFile () { +echo +echo "This function currently only adds new libraries and ranges." +echo +read -p "Please enter the library shortname (e.g., WGRL-HQ): " NEW_SHORTNAME +read -p "Please enter the start IP of the range (if a single IP, just enter that): " START_IP +read -p "Please enter the end IP of the range (if a single IP, just enter that again): " END_IP +echo +echo "The new line will be:" +echo -e "$NEW_SHORTNAME\t $START_IP $END_IP" +echo +read -p "Is this correct? (y/n) " ANSWER +if [ "$ANSWER" = "y" ]; then + echo "Backing up the original file..." + cp $LIB_IPS_TXT $LIB_IPS_TXT.`date +%Y%m%d%H%M%S` + echo "Adding the new entry to the file..." + echo "$NEW_SHORTNAME $START_IP $END_IP" >> "$LIB_IPS_TXT" + echo "Re-sorting file with new entry in place..." + sort $LIB_IPS_TXT -o $LIB_IPS_TXT + echo "Done!" +else + echo "Aborting." + exit; +fi +} + +CopyFile () { +# works best if the opensrf user is keyed for opensrf on the other brick heads +echo +echo "Copying file to the other brick heads..." +for i in `seq 2 $BRICK_HEADS`; do + ssh opensrf@brick0$i-head cp $LIB_IPS_TXT $LIB_IPS_TXT.`date +%Y%m%d%H%M%S`; + scp $LIB_IPS_TXT opensrf@brick0$i-head:$LIB_IPS_TXT; + echo "brick$i-head complete"; +done; +} + +echo "This program allows you to query and/or update the Evergreen Library IP redirection file on each of the application bricks." +echo +echo "What would you like to do?" +echo +echo "[1] Query the lib_ips.txt file by library name or IP address" +echo "[2] Update the file with a new entry" +echo +read -p "Please choose option 1 or 2: " RESPONSE +if [ "$RESPONSE" = "1" ]; then + QueryFile +elif [ "$RESPONSE" = "2" ]; then + UpdateFile && echo "The file is updated" && CopyFile +else + echo "No valid response received. Aborting." + exit; +fi -- 2.11.0