#!/usr/bin/perl # SCRIPT: FoxPro For FreeBSD Unix Install Script # PURPOSE: Install FoxPro on FreeBSD Unix. (Painlessly) # AUTHOR: Peter Elsner # COPYRIGHT 2013 AT-Vantage Software, LLC # ORIGINALLY CREATED ON : 4/4/2003 # LAST MODIFIED: 12/27/2012 - Added check for missing library files, and # version/machine type check # # MODIFIED: 10/24/2013 - Thanks to Kevin Day in the FreeBSD Hackers Mailing List # this should now work on FreeBSD 8.1 and above. # (Added security.bsd.map_at_zero=1 to /etc/sysctl.conf) # MODIFIED: 2/8/2014 - Added script ibcs2kernel.sh to kldload the ibcs2 modules (no longer does this by default) at reboot. $FOXPTARBALL="fpu26_FreeBSD.tgz"; # Default Directories (Change these only if you know what you are doing) $FOXPRO_DIR="/usr/local/lib/foxpro"; $TERMINFO_DIR="/usr/local/share/terminfo"; $COMPAT_DIR="/usr/compat/ibcs2/dev"; system("clear"); # Verify that user is logged in as root (or su'd to root). $UID=`id -un`; chomp($UID); if ($UID eq "root") { print "User is root.\n"; } else { print "You must be root to install FoxPro 2.6a.\n"; exit 15; } # Check OS to make sure it is FreeBSD $OS=`uname`; chomp($OS); if ($OS eq "FreeBSD") { print "Operating System Detected $OS.\n"; } else { print "FreeBSD Operating System NOT Detected.\n"; exit 15; } # Foxpro will not work on any OS past 7.4 $OSVER=`uname -r`; $OSVER=substr($OSVER,0,3); if ($OSVER > 7.4) { print "FreeBSD Version $OSVER Detected - Modifying sysctl.conf file\n"; open(SYSCTL,">>/etc/sysctl.conf"); print SYSCTL "security.bsd.map_at_zero=1\n"; close(SYSCTL); system("sysctl security.bsd.map_at_zero=1"); } else { print "FreeBSD Version $OSVER Detected.\n"; } # Foxpro won't work on amd64. Must be i386 because amd64 doesn't have the ibcs2 kld's $MACHINE=`uname -m`; chomp($MACHINE); if ($MACHINE ne "i386") { print "FreeBSD machine type must be i386!\n"; exit 15; } else { print "FreeBSD machine type $MACHINE Detected.\n"; } # If we get here, all system requirements have been met, continue with install # Check to make sure FoxPro is not already installed. if (-f "$FOXPRO_DIR/foxpro.pr") { ## foxpro.pr file found! print "FoxPro appears to already be installed.\n"; print "Continue (y/N): "; $CONTINUE=; $CONTINUE=uc($CONTINUE); chomp($CONTINUE); if ($CONTINUE ne "Y") { print "Installation aborted by user!\n"; exit 15; } } # Get required tarball files... (uses fetch) $URL="http://www.at-vantage.com/foxfiles"; chdir("/tmp"); if (-e "/tmp/$FOXPTARBALL") { print "Tarball Found.\n"; } else { ## GO GET IT system("fetch $URL/$FOXPTARBALL"); } # Now create directories (if needed) # FoxPro Directory $MKFOXDIR=qx[ mkdir -p $FOXPRO_DIR ]; # Terminfo Directory $MKTERMDIR=qx[ mkdir -p $TERMINFO_DIR ]; # compatibility Directory (ibcs2/dev) $MKCOMPATDIR=qx[ mkdir -p $COMPAT_DIR ]; # Create null file in $COMPAT_DIR chdir("$COMPAT_DIR"); system("touch null"); # Untar the tarball chdir("/tmp"); system("mv $FOXPTARBALL $FOXPRO_DIR"); chdir("$FOXPRO_DIR"); system("tar xzfp $FOXPTARBALL"); # FoxPro for SCO looks for terminfo in the /usr/lib directory, # so we need to symlink FreeBSD's terminfo directory to /usr/lib chdir("/usr/lib"); system("ln -fs $TERMINFO_DIR terminfo"); # Check for existance of f directory under $TERMINFO directory... # Create it if it doesn't exist... chdir("$TERMINFO_DIR"); $MKFDIR=qx[ mkdir -p "$TERMINFO_DIR/f" ] unless(-e("$TERMINFO_DIR/f")); system("chmod 777 $TERMINFO_DIR/f"); chdir("$FOXPRO_DIR"); system("mv fansi.src $TERMINFO_DIR/f"); # Check for existance of tic file in /usr/bin and move it there if not found. if (! -e "/usr/bin/tic") { system("mv tic /usr/bin"); } # Check for missing lib files (libc.so.3 and libmytinfo.so.2) which are required for # tic to work. if (! -e "/lib/libc.so.3") { system("mv libc.so.3 /lib"); } if (! -e "/usr/lib/libmytinfo.so.2") { system("mv libmytinfo.so.2 /usr/lib"); } # Compile fansi.src into terminfo binary... chdir("$TERMINFO_DIR/f"); system("tic fansi.src"); chdir("/tmp"); # Now check to see if ibcs2 modules are loaded, load if not. $ibcs2_1=qx[ kldstat | grep ibcs2.ko ]; $ibcs2_2=qx[ kldstat | grep ibcs2_coff.ko ]; if ($ibcs2_1) { print "ibcs2 module loaded\n"; } else { print "Loading ibcs2.ko module into memory\n"; $loadit=qx[ kldload ibcs2.ko ]; } if ($ibcs2_2) { print "ibcs2_coff module loaded\n"; } else { print "Loading ibcs2_coff.ko module into memory\n"; $loadit=qx[ kldload ibcs2_coff.ko ]; } open(IBCS2BOOT,">/etc/rc.d/ibcs2kernel"); print IBCS2BOOT <; close(RCCONF); $FOUND=0; foreach $LINE(@RCCONF) { chomp($LINE); if ($LINE =~ m/ibcs2_enable="YES"/i) { $FOUND=1; last; } } if ($FOUND == 0) { open(RCCONF,">>/etc/rc.conf"); print RCCONF "# IBCS2 Module Added By FoxPro Install Script.\n"; print RCCONF "# Copyright 2013 - AT-Vantage Software, LLC..\n"; print RCCONF "IBCS2_ENABLE=\"YES\""; close RCCONF; } } # Uncompress and create the foxpro.pr binary file... chdir("$FOXPRO_DIR"); $BINFILE="foxpro.pr"; print "Uncompressing FoxPro binary...\n"; $I=0; while ($I < 5) { system("mv $BINFILE.0$I $BINFILE.0$I.Z"); system("uncompress $BINFILE.0$I.Z"); $I++; } print "Creating FoxPro binary...\n"; system("cat $BINFILE.?? > $BINFILE"); system("rm foxpro.pr.0?"); system("chmod 755 foxpro.pr"); print "\n"; print "DONE!\n"; # Move fox and foxpro to /usr/local/bin chdir("$FOXPRO_DIR"); system("mv fox /usr/local/bin"); system("mv foxpro /usr/local/bin"); # Call the tzget.sh shell script to set timezone. system("/usr/local/lib/foxpro/tzget.sh"); print "Installation of FoxPro 2.6a for FreeBSD completed!\n\n"; exit;