3 # Copyright (C) 2012 Georgia Public Library Service
4 # Chris Sharp <csharp@georgialibraries.org>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 OSRF_CONF_DIR="/openils/conf"
21 LIB_IPS_TXT="$OSRF_CONF_DIR/lib_ips.txt"
22 BRICK_HEADS="6" # number of brick heads you have - script assumes you're running on brick01-head
23 EDITOR="/usr/bin/editor"
25 [[ $(whoami) != "opensrf" ]] && echo "Must be opensrf user to run this utility." && exit
28 echo "Would you like to query by library name or by IP address?"
30 echo "[1] Library name"
33 read -p "Please choose option 1 or 2: " CHOICE
34 if [ "$CHOICE" = "1" ]; then
35 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
36 grep -i "$SHORTNAME" $LIB_IPS_TXT | sort;
37 elif [ "$CHOICE" = "2" ]; then
38 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
39 grep $IP_ADDR $LIB_IPS_TXT | sort;
41 echo "No valid response received. Aborting."
48 echo "This function currently only adds new libraries and ranges."
50 read -p "Please enter the library shortname (e.g., WGRL-HQ): " NEW_SHORTNAME
51 read -p "Please enter the start IP of the range (if a single IP, just enter that): " START_IP
52 read -p "Please enter the end IP of the range (if a single IP, just enter that again): " END_IP
54 echo "The new line will be:"
55 echo -e "$NEW_SHORTNAME\t$START_IP\t$END_IP"
57 read -p "Is this correct? (y/n) " ANSWER
58 if [ "$ANSWER" = "y" ]; then
59 echo "Backing up the original file..."
60 cp $LIB_IPS_TXT $LIB_IPS_TXT.`date +%Y%m%d%H%M%S`
61 echo "Adding the new entry to the file..."
62 echo "$NEW_SHORTNAME $START_IP $END_IP" >> "$LIB_IPS_TXT"
63 echo "Re-sorting file with new entry in place..."
64 sort $LIB_IPS_TXT -o $LIB_IPS_TXT
73 # works best if the opensrf user is keyed for opensrf on the other brick heads
75 echo "Copying file to the other brick heads..."
76 for i in `seq 2 $BRICK_HEADS`; do
77 ssh opensrf@brick0$i-head cp $LIB_IPS_TXT $LIB_IPS_TXT.`date +%Y%m%d%H%M%S`;
78 scp $LIB_IPS_TXT opensrf@brick0$i-head:$LIB_IPS_TXT;
79 echo "brick0$i-head complete";
81 echo "You will need to restart Apache on all brick heads for the changes to take effect."
85 cp $LIB_IPS_TXT $LIB_IPS_TXT.`date +%Y%m%d%H%M%S`
87 read -p "Would you like to copy the file to the other brick heads? (y/n) " COPYFILE
88 if [ "$COPYFILE" = "y" ]; then
90 elif [ "$COPYFILE" = "n" ]; then
91 echo "Not copying file."
94 echo "No valid response received. Not copying file."
99 echo "This program allows you to query and/or update the Evergreen Library IP redirection file on each of the application bricks."
101 echo "What would you like to do?"
103 echo "[1] Query the lib_ips.txt file by library name or IP address"
104 echo "[2] Update the file with a new entry"
105 echo "[3] Manually edit, then optionally copy the file to the other brick heads"
107 read -p "Please choose option 1, 2 or 3: " RESPONSE
108 if [ "$RESPONSE" = "1" ]; then
110 elif [ "$RESPONSE" = "2" ]; then
111 UpdateFile && echo "The file is updated" && CopyFile
112 elif [ "$RESPONSE" = "3" ]; then
115 echo "No valid response received. Aborting."