#!/bin/sh # # The following script adds a rudamentary phone book to my grandstream GXP2100 # data is stored in a .dat file which is a CSV (firstname, lastname, phone) # function enter_phone_number { echo "Enter Name" read name firstname=`echo $name | awk '{ print $1 }'` lastname=`echo $name | awk '{ print $2 }'` echo "firstname: $firstname" echo "lastname: $lastname" echo "does this look reasonable?" read yn case $yn in [nN]*) return; ;; esac echo "enter phonenumber" read phone echo "firstname: $firstname" echo "lastname: $lastname" echo "phone: $phone" echo "does this look reasonable?" read yn case $yn in [nN]*) return; ;; esac echo "$firstname,$lastname,$phone" >> $HOME/bin/phonebook.dat } function generate_phonebook { PHONEBOOK="${HOME}/OBSCURED/gs_phonebook.xml mkdir -p ${HOME}/OBSCURED echo "" > $PHONEBOOK echo "" >> $PHONEBOOK cat $HOME/bin/phonebook.dat | while read i do firstname=`echo $i| awk -F, '{ print $1 }'` lastname=`echo $i | awk -F, '{ print $2 }'` phone=`echo $i | awk -F, '{ print $3 }'` echo "" >> $PHONEBOOK echo " ${lastname}" >> $PHONEBOOK echo " ${firstname}" >> $PHONEBOOK echo " " >> $PHONEBOOK echo " ${phone}" >> $PHONEBOOK echo " 0" >> $PHONEBOOK echo " " >> $PHONEBOOK echo "" >> $PHONEBOOK done echo "" >> $PHONEBOOK return; } while : do cat << END GRANDSTREAM PHONEBOOK GENERATOR V 1.0 1. ENTER PHONE NUMBER 2. DISPLAY ALL PHONE NUMBERS 3. GENERATE PHONEBOOK 4. EXIT END read i case $i in "1") enter_phone_number; ;; "2") cat $HOME/bin/phonebook.dat ;; "3") generate_phonebook; ;; "4") exit 0 ;; esac done