#!/bin/bash

NOWDIR=`pwd`
BASEDIR=$HOME/macfidoip
NAME="SysOp"
AKA="2:5020/9999.9999"
SYS="PointSystem"
LOC="Moscow"
PASWD="9999qwer"
BAKA="2:5020/9999"
BIP="fidonode.in"

echo -ne "Enter your path to MacFidoIP basedir [ $BASEDIR ]: "
read TMP
if [ "$TMP" != "" ]; then BASEDIR=$TMP; fi

echo -ne "Enter your real name [ $NAME ]: "
read TMP
if [ "$TMP" != "" ]; then NAME=$TMP; fi

echo -ne "Enter your FTN-address [ $AKA ]: "
read TMP
if [ "$TMP" != "" ]; then AKA=$TMP; fi

echo -ne "Enter your location [ $LOC ]: "
read TMP
if [ "$TMP" != "" ]; then LOC=$TMP; fi

echo -ne "Enter your computer's name [ $SYS ]: "
read TMP
if [ "$TMP" != "" ]; then SYS=$TMP; fi

echo -ne "Enter your uplink FTN-address [ $BAKA ]: "
read TMP
if [ "$TMP" != "" ]; then BAKA=$TMP; fi

echo -ne "Enter your uplink ip or dns name [ $BIP ]: "
read TMP
if [ "$TMP" != "" ]; then BIP=$TMP; fi

echo -ne "Enter your uplink password [ $PASWD ]: "
read TMP
if [ "$TMP" != "" ]; then PASWD=$TMP; fi

if [ ! -d $BASEDIR ]; then mkdir $BASEDIR; fi
if [ ! -d $BASEDIR ]; then echo "Can't create $BASEDIR"; exit; fi
cd $BASEDIR
tar xfvz "$NOWDIR/macdata.tgz"

cat > $BASEDIR/etc/binkd.config <<EOF
domain fidonet $BASEDIR/out 2
address  $AKA@fidonet
sysname "$SYS"
location "$LOC"
sysop "$NAME"
nodeinfo 115200,TCP,BINKP
call-delay 20
rescan-delay 5
try 1
hold 5
send-if-pwd
log $BASEDIR/binkd.log
loglevel 4
conlog 4
percents
printq
inbound $BASEDIR/in.sec
inbound-nonsecure $BASEDIR/in
temp-inbound $BASEDIR/in.tmp
minfree 2048
minfree-nonsecure 2048
kill-dup-partial-files
kill-old-partial-files 86400
kill-old-bsy 43200
prescan
node $BAKA $BIP $PASWD
EOF
cat > $BASEDIR/etc/crashmail.prefs <<EOF

SYSOP "$NAME"
LOGFILE "$BASEDIR/crashmail.log"
LOGLEVEL 3
DUPEFILE "$BASEDIR/crashmail.dupes" 200
DUPEMODE KILL
LOOPMODE LOG+BAD
MAXPKTSIZE 50
MAXBUNDLESIZE 100
DEFAULTZONE 2
INBOUND      "$BASEDIR/in.sec"
OUTBOUND     "$BASEDIR/out"
TEMPDIR      "$BASEDIR/tmp"
CREATEPKTDIR "$BASEDIR/tmp"
PACKETDIR    "$BASEDIR/out"
STATSFILE "$BASEDIR/crashmail.stats"
FORCEINTL
ANSWERRECEIPT
ANSWERAUDIT
CHECKSEENBY
IMPORTSEENBY
ADDTID
CHANGE * 2:*/*.* Crash
PACKER "ZIP" "zip -D %a %f" "unzip %a" "PK"
AKA $AKA
DOMAIN "FidoNet"
NODE $BAKA "ZIP" "$PASWD" AUTOADD
ROUTE "*:*/*.*" "$BAKA.0" $AKA
JAM_HIGHWATER
JAM_LINK
JAM_QUICKLINK
JAM_MAXOPEN 5


NETMAIL	"NETMAIL"	"$AKA"	MSG	"$BASEDIR/netmail"
AREA 	"BAD"		$AKA		JAM	"$BASEDIR/bad"
AREA	"DEFAULT"	$AKA		JAM 	"$BASEDIR/echo/%a"

EOF

cat > $BASEDIR/etc/golded/golded.cfg <<EOF

username $NAME

Address $AKA

XLATPATH $BASEDIR/etc/golded/cfgs/charset/
XLATLOCALSET KOI8
XLATIMPORT CP866
XLATEXPORT CP866
XLATCHARSET KOI8 CP866 koi_866.chs
XLATCHARSET CP866 KOI8 866_koi.chs

IGNORECHARSET

CTRLINFONET   TEARLINE, ORIGIN
CTRLINFOECHO  TEARLINE, ORIGIN
CTRLINFOLOCAL TEARLINE, ORIGIN

TEARLINE ------

ORIGIN "OS X/Golded-NSF/CrashMail"

COLOR MENU   UNREAD     YELLOW  ON BLACK
HighlightUnread Yes
SEMAPHORE EXPORTLIST  $BASEDIR/echotoss.log
SEMAPHORE IMPORTLIST  $BASEDIR/import.log
AreaFile CrashMail    $BASEDIR/etc/crashmail.prefs
LOADLANGUAGE          $BASEDIR/etc/golded/goldlang.cfg
AREASCAN *
EditSoftCrXLat H
UseSoftCRxlat Yes ;EditCompletion "Н"  "H"
DispSoftCr Yes

TAGLINESUPPORT Yes
;TAGLINE @random.txt   
;VIEWHIDDEN YES
VIEWKLUDGE NO

TwitName Bad User
TwitName Urgy Spammer
TwitMode Skip
TwitTo Yes

UuDecodePath	$BASEDIR/uudecode

Invalidate Tearline     "" ""
Invalidate Origin       "" ""
EditCrlFTerm    No
ViewQuote       Yes
ImportBegin     -Cut On @file-
ImportEnd       -Cut Off @file-
OutPutFile      $BASEDIR/outfile/
AttribsNet      Loc Pvt
DispMsgSize     Kbytes
DispAttachSize  Kbytes
NodelistWarn    No
TemplatePath    $BASEDIR/etc/golded
Template        golded.tpl     "Основной шаблон"
include         $BASEDIR/etc/golded/gedcolor.cfg
;include         $BASEDIR/etc/golded/goldkeys.cfg
NodePath        $BASEDIR/nodelist
NODELIST        NODELIST		; NodeList  @FidoNet ZONE 2


RobotName AreaFix
RobotName AllFix
RobotName T-fix
RobotName FAQServer

LogFile $BASEDIR/golded.log

AddressMacro AreaFix,AreaFix,$BAKA,"$PASWD",K/S,Dir
AddressMacro FileFix,FileFix,$BAKA,"$PASWD",K/S,Dir

AddressBookAdd  Always

^B      READAddressBookAdd
@F10    READUserBase

AreaDef Netmail "Netmail" Q Net Opus $BASEDIR/netmail $AKA
ConfirmFile golded.cfm
ConfirmResponse  Ask

AREALISTGROUPID YES
AREALISTSORT YUG

PeekURLOptions FromTop
URLHANDLER -NoPause -NoKeepCtrl -Wipe /usr/bin/firefox `echo "@url" | /usr/bin/iconv -f CP866 -t UTF-8` > /dev/null 2>&1 &
DispHdrLocation Yes
DispHdrFGHIUrl  SHORT
MsgListHeader   1
URLBrackets     Yes

KeybExt         Yes

EOF
mkdir $BASEDIR/bin

cat > $BASEDIR/bin/ge <<EOF
#!/bin/sh

FROOT=$BASEDIR
CFG=\$FROOT/etc/golded/golded.cfg
BIN=\$FROOT/sbin/gedlnx
\$BIN -c\$CFG

EOF
chmod 755 $BASEDIR/bin/ge

cat > $BASEDIR/bin/poll <<EOF
#!/bin/sh
FROOT=$BASEDIR
CFG=\$FROOT/etc/binkd.config
BIN=\$FROOT/sbin/binkd
NODE=$BAKA
\$BIN -p -P \$NODE \$CFG

EOF
chmod 755 $BASEDIR/bin/poll

cat > $BASEDIR/bin/toss <<EOF
#!/bin/sh
FROOT=$BASEDIR
CFG=\$FROOT/etc/crashmail.prefs
BIN=\$FROOT/sbin/crashmail
\$BIN SETTINGS \$CFG NOSECURITY TOSS SCAN

EOF
chmod 755 $BASEDIR/bin/toss

cat <<EOF
Now you can run $BASEDIR/bin/ge for Golded, $BASEDIR/bin/poll for polling a node and $BASEDIR/bin/toss for tossing bundles
For Golded use Terminal with KOI8-R encoding and XTERM terminal type!
EOF
