Image

Image

Search This Blog

Thursday, December 10, 2009

Fax setup

#!/bin/bash

# greetings from neXt :)

#cd /etc/initsetup
vardt=/etc/initsetup/vardt
log=/etc/initsetup/setup.log

if [ -f $log ]; then
oldexp=`grep expd $log | cut -d= -f2`
fi
. $vardt

echo -en "Starting setup: " > $log
date > $log
cat $vardt >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 1/10" \
--inputbox "Enter your domain name" 8 60 $fakedom 2>/tmp/input.$$
sel=$?
dom=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo dom=$dom >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 2/10" \
--inputbox "Enter your IP address" 8 60 $fakeip 2>/tmp/input.$$
sel=$?
ipif=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipif=$ipif >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 3/10" \
--inputbox "Enter the MailServer IP address" 8 60 $fakemail 2>/tmp/input.$$
sel=$?
ipmail=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipmail=$ipmail >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 4/10" \
--inputbox "Enter the Gateway IP address" 8 60 $fakegw 2>/tmp/input.$$
sel=$?
ipgw=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipgw=$ipgw >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 5/10" \
--inputbox "Enter the DNS IP address" 8 60 $fakedns 2>/tmp/input.$$
sel=$?
ipdns=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipdns=$ipdns >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 6/10" \
--inputbox "Enter the Range of IP address" 8 60 $fakenet 2>/tmp/input.$$
sel=$?
ipnet=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipnet=$ipnet >> $log

/bin/sed -i s/$fakedom/$dom/g /etc/hosts
/bin/sed -i s/$fakedom/$dom/g /etc/squirrelmail/config.php
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/transport
/bin/sed -i s/$fakedom/$dom/g /etc/sysconfig/network
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/main.cf
/bin/sed -i s/$fakeip/$ipif/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s/$fakeip/$ipif/g /etc/initsetup/getbackup
/bin/sed -i s/$fakedns/$ipdns/g /etc/resolv.conf
/bin/sed -i s/$fakedns/$ipdns/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s^$fakenet^$ipnet^g /etc/postfix/main.cf
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/transport
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/main.cf
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network-scripts/ifcfg-eth0

echo -en "Files modified, restarting network..."
/sbin/service network restart >> $log
echo -en " Wait a second, network config still active..."
sleep 10
echo "Changing default route" >> $log
/sbin/route del default
/sbin/route add default gw $ipgw
export HOSTNAME=HFAX.$dom

cp -f /etc/inittab.nofax /etc/inittab.fax
uncfg=1
while [ $uncfg -lt 99 ]; do
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "Step 9/10" \
--inputbox "To what port did you connected your fax-modem to the server?" 10 40 $fakeport 2>/tmp/input.$$
sel=$?
port=`cat /tmp/input.$$`
rm -f /tmp/input.$$
fakeport=$port
echo port=$port >> $log
case $sel in
0) cp -f /etc/inittab.nofax /etc/inittab
/sbin/init q
killall faxgetty
faxsetup
/sbin/service hylafax-server stop
killall faxq
sleep 5
faxaddmodem $port
if cat /var/spool/fax/etc/config.$port | grep -v grep | grep DynamicConfig >> $log
then
echo "$port already configured for avantfax" >>$log
else
echo "FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true" >> /var/spool/fax/etc/config.$port
fi
if cat /etc/inittab.fax | grep -v grep | grep 'respawn:/usr/sbin/faxgetty $port' >> $log
then
echo "$port already configured for receiving" >>$log
else
echo "m$uncfg:2345:respawn:/usr/sbin/faxgetty $port" >> /etc/inittab.fax
fi
let uncfg++
sleep 5
/sbin/service hylafax-server start
cp -f /etc/inittab.fax /etc/inittab
/sbin/init q
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "ExtraStep 9.1/10" \
--yes-label End --no-label Add_Modem \
--yesno "Did you finished, or there are still modems connected?" 10 40
sel=$?
case $sel in
0) uncfg=999
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
done
echo > $vardt
echo fakedom=$dom >> $vardt
echo fakeip=$ipif >> $vardt
echo fakemail=$ipmail >> $vardt
echo fakegw=$ipgw >> $vardt
echo fakedns=$ipdns >> $vardt
echo fakenet=$ipnet >> $vardt
echo fakeport=$port >> $vardt
echo >> $vardt

echo -en "Last step: Restarting services..."
/etc/init.d/run
/sbin/service hylafax-server restart 1>>$log 2>&1
/sbin/service postfix restart 1>>$log 2>&1
dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 9/10" \
--msgbox "Let's add users for the fax now. point a browser to http://HFAX/admin login as
admin with the usual password, go to 'NewUser'.
Don't forget to go also to Configure Modems and to setup the default fax-to-email recipient!
Then, from each client, browse the network to \\HFAX\public folder and install ghostscript and yajhfc.
Start YajHFC, setup credentials and choose the coverpage from \\HFAX\public\cover.ps" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Final info" \
--infobox "The system config and variables are backed-up daily in /etc/initsetup/backup.tgz. In order to save the backup on the unix machine just use the /etc/initsetup/getbackup ftp commands file.
Copy the file to the unix server (you can do that by ftp: as ftpuser:trsf on this box) get /tmp/getbackup /some/path/to/getbackup) and add the following line to cron:
50 21 * * * ftp -n /dev/null

If the server is windows, use the same getbackup script, started daily at 21:50 from getbackup.cmd via Task Scheduler.

THIS IS THE END OF SETUP (see logs in setup.log)" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

echo "Welcome to FaxServer" > /etc/motd
echo "DONE!"
exit 0

No comments:

Post a Comment

Blog Archive