soup4you2
July 11th, 2003, 09:23
Well i think i've almost finished this script... or at least for the time being.. it goal is to help new people out to freebsd in making daily stuff easy for them.. there's still a couple bugs but i'll get those as soon as i can.... feel free to tear through the code and let me know what you think... and yes i aparently have waaaay to much freetime to be doing projects like this...
the full script can be downloaded at:
http://bsdhound.com/~soup4you2/menu.sh
i would recommend downloading the actual script so you can get the ansi codes...
[code:1:3dbe4f2d76]
################################################## #
# Menu Magic Script Version 3.0
# Written By: Soup4you2
# Website: http://bsdhound.com
# Last Update: 03 July 2003
################################################## #
#TODO
#Fix idle function
#Fix Backup is a datestamp dir exists it automatically performs operation
################################################
# Set Global Vars
#
DATESTAMP=`date +%Y-%m-%d%n`
BACKUP='/public/archives/backups' #NO Trailing Slash Please
SNORTRULES='/usr/local/etc/snort/rules' #Where are your snort rules located a
t?
################################################
## NO EDITING REQUIRED BELOW HERE ##
################################################
VERSION='3.0.5'
LOCKFILE='/tmp/lazy.lock'
LAZYLOG='/tmp/lazy.log' #LOGFILE
set tty erase
# Starting Main Menu
function mainmenu {
echo
echo "Welcome $USER to Pure Lazyness $VERSION"
echo
echo "Allowed Commands Are:"
echo
echo "update - Update to the latest version of Pure Lazy"
echo "update ports - Update the ports tree"
echo "update sources - Update the FreeBSD source tree"
echo "portupgrade - Perform portupgrade"
echo "buildworld - Complete update of the BSD OS"
echo "snort - Update snort rules"
echo "tripwire - Update tripwire policy"
echo "state - View IPF State table"
echo "refresh - Refresh IPF/IPNAT/IPMON"
echo "portmon - Monitor Raw data to a specified port"
echo "rawdata - Monitor all raw data to a interface"
echo
echo "backup - Enter backup menu"
echo "postmaster - Enter Postfix postmaster menu"
echo
echo "exit - Quit this script"
echo
# Define Menu Functions
echo -n "COMMAND > "
read mmi
if [ "$mmi" = "update" ];then update
fi
if [ "$mmi" = "update ports" ];then ports
fi
if [ "$mmi" = "update sources" ];then sources
fi
if [ "$mmi" = "portupgrade" ];then portupgrade
fi
if [ "$mmi" = "buildworld" ];then build1
fi
if [ "$mmi" = "snort" ];then snort
fi
if [ "$mmi" = "tripwire" ];then tripwire
fi
if [ "$mmi" = "state" ];then mon_3
fi
if [ "$mmi" = "refresh" ];then mon_4
fi
if [ "$mmi" = "portmon" ];then mon_5
fi
if [ "$mmi" = "rawdata" ];then mon_6
fi
if [ "$mmi" = "backup" ];then bckupmnu
fi
if [ "$mmi" = "postmaster" ];then postmaster
fi
if [ "$mmi" = "idle" ]; then touch $LOCKFILE && idle
fi
if [ "$mmi" = "exit" ];then quitter
else
echo "Invalid Command"
sleep 2
mainmenu
fi
}
# Backup Menu
function bckupmnu {
echo
echo "www - Backup Website directory structure"
echo "home - Backup Home directory structure"
echo "system - Backup Common System Directories"
echo
echo "return - Return to main menu"
echo
# Define Menu Functions
echo -n "BACKUP > "
read bkup
if [ "$bkup" = "www" ];then bkupwww
fi
if [ "$bkup" = "home" ];then bkuphome
fi
if [ "$bkup" = "system" ];then bkupsys
fi
if [ "$bkup" = "return" ];then mainmenu
else
echo "Invalid Command"
sleep 2
bckupmnu
fi
}
# Postmaster menu
function postmaster {
echo
echo "queue - View Active queues"
echo "delqueue - Delete a queue"
echo "flush - Atempt to re-deliver queue"
echo "hold - Put a queue on hold"
echo "requeue - Requeue message"
echo "check - Structure check and structure repair."
echo "spam - View trapped messages in spam trap"
echo
echo "return - Return to main menu"
echo
# Define Menu Functions
echo -n "POSTMASTER > "
read pmopt
if [ "$pmopt" = "queue" ];then postqueue
fi
if [ "$pmopt" = "delqueue" ];then delqueue
fi
if [ "$pmopt" = "flush" ];then flushqueue
fi
if [ "$pmopt" = "hold" ];then queuehold
fi
if [ "$pmopt" = "requeue" ];then requeue
fi
if [ "$pmopt" = "check" ];then postcheck
fi
if [ "$pmopt" = "spam" ];then spam
fi
if [ "$pmopt" = "return" ];then mainmenu
else
echo "Invalid Command"
sleep 2
postmaster
fi
}
# Exit Procedures
function quitter {
echo
echo "Thanks for using my script.."
echo "Please be sure to check out http://bsdhound.com"
echo "For updates. or new projects"
echo
exit 0
}
####################################
# Update to latest version
####################################
function update {
echo "Please wait while i update this script"
if fetch http://bsdhound.com/~soup4you2/menu.sh ; echo -n "Update of script"
then pass
else fail
fi
echo
echo "Please dont forget to set the Variables in the top of the file"
echo -n "Setting Permissions"
chown root:wheel menu.sh && chmod 750 menu.sh && pass && echo "Please restart th
e script now" && exit 0
fail && exit 0
exit 0
}
####################################
# Update the ports tree
####################################
function ports {
# VERIFY PRE-REQS
echo -n "Checking for CVSUP"
ls /usr/local/bin/cvsup 1>/dev/null 2>&1 && pass && ports2
fail
echo
echo "Please install cvsup, Then try again"
echo
mainmenu
exit 1
}
function ports2 {
echo -n "Checking for prior supfile"
ls /usr/local/etc/ports-supfile 1>/dev/null 2>&1 && pass && upports
fail
# No Supfile Exists
echo
echo "I have failed to detect a ports-supfile"
echo "This script looks for it in /usr/local/etc/"
echo
echo -n "Would you like me to build you a ports-supfile? [Y/N] "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO TO SUPFILE CREATION SCRIPT
echo "Perhaps later on then.."
echo "Please wait while I return you to the main menu"
echo
echo -n "Update of ports tree" && fail
sleep 2
mainmenu
exit 0
;;
esac
# YES TO SUPFILE CREATION SCRIPT
findcvs
echo
echo "Your Ideal CVSUP server will be $avgminname"
echo
echo
echo -n "Creating /usr/local/etc/ports-supfile"
echo "*default host=$avgminname" >> /usr/local/etc/ports-supfile
echo "*default base=/usr" >> /usr/local/etc/ports-supfile
echo "*default prefix=/usr" >> /usr/local/etc/ports-supfile
echo "*default release=cvs tag=." >> /usr/local/etc/ports-supfile
echo "*default delete use-rel-suffix" >> /usr/local/etc/ports-supfile
echo "*default compress" >> /usr/local/etc/ports-supfile
echo "*default umask=002" >> /usr/local/etc/ports-supfile
echo "ports-all" >> /usr/local/etc/ports-supfile
pass
echo -n "Setting Permissions"
if chmod 600 /usr/local/etc/ports-supfile
then pass
else fail
fi
echo "Please wait while updating ports"
touch $LOCKFILE
echo
echo -n "Please Wait."
idle &
sleep 3
/usr/local/bin/cvsup -g /usr/local/etc/ports-supfile 1>/dev/null 2>&1 && rm -f $
LOCKFILE && echo && echo -n "Update of ports" && pass && sleep 3 && mainmenu
fail && exit 1
exit 0
}
# Supfile Exists Function
function upports {
echo
echo "Updating Ports with existing supfile"
echo
echo "Please wait while updating ports"
touch $LOCKFILE
echo
echo -n "Please Wait."
idle &
sleep 3
/usr/local/bin/cvsup -g /usr/local/etc/ports-supfile 1>/dev/null 2>&1 && rm -f $
LOCKFILE && echo && echo -n "Update of ports" && pass && sleep 3 && mainmenu
fail && exit 1
exit 0
}
#####################################
# Update The FreeBSD Sources
#####################################
function sources {
# VERIFY PRE-REQS
echo
echo -n "Checking for CVSUP"
ls /usr/local/bin/cvsup 1>/dev/null 2>&1 && pass && source2
fail
echo
echo "Please install cvsup, Then try again"
echo
mainmenu
exit 1
}
function source2 {
echo -n "Checking for prior supfile"
ls /usr/local/etc/cvs-supfile 1>/dev/null 2>&1 && pass && upcvs2
fail
# No Supfile Exists
echo
echo "I have failed to detect a cvs-supfile"
echo "This script looks for it in /usr/local/etc/"
echo
echo -n "Would you like me to build you a cvs-supfile? [Y/N] "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO TO SUPFILE CREATION SCRIPT
echo "Perhaps later on then.."
echo "Please wait while I return you to the main menu"
echo
echo -n "Update of source tree" && fail
sleep 2
mainmenu
exit 0
;;
esac
# YES TO SUPFILE CREATION SCRIPT
upcvs
exit 0
}
function upcvs {
findcvs
echo
echo "Your Ideal CVSUP server will be $avgminname"
echo
echo -n "What is your cvs tag to use? (ie. RELENG_5_1) >"
read release
echo -n "Creating /usr/local/etc/ports-supfile for $release"
echo "*default host=$avgminname" >> /usr/local/etc/cvs-supfile
echo "*default base=/usr" >> /usr/local/etc/cvs-supfile
echo "*default prefix=/usr" >> /usr/local/etc/cvs-supfile
echo "*default release=cvs tag=$release" >> /usr/local/etc/cvs-supfile
echo "*default delete use-rel-suffix" >> /usr/local/etc/cvs-supfile
echo "*default compress" >> /usr/local/etc/cvs-supfile
echo "*default umask=002" >> /usr/local/etc/cvs-supfile
echo "src-all" >> /usr/local/etc/cvs-supfile
pass
echo -n "Setting Permissions"
chmod 600 /usr/local/etc/cvs-supfile && pass
upcvs2
}
function upcvs2 {
echo "Please wait while updating ports"
echo
echo -n "Please Wait."
touch $LOCKFILE
idle &
sleep 3
/usr/local/bin/cvsup -g -L 2 /usr/local/etc/cvs-supfile 1>/dev/null 2>&1 && rm -
f $LOCKFILE && echo && echo -n "Update of sources" && pass && sleep 3 && mainmen
u
fail && exit 1
exit 0
}
##################################
# Portupgrade
##################################
function portupgrade {
# VERIFY PRE-REQS
echo -n "Checking for portupgrade"
ls /usr/local/sbin/portupgrade 1>/dev/null 2>&1 && pass && pu2
fail
echo
echo "Please install portupgrade, Then try again"
echo
exit 1
}
function pu2 {
echo
echo "Rebuilding package database"
/usr/local/sbin/pkgdb -F && echo -n "Database rebuilt" && pass
echo
echo "Listing packages to be updated"
echo
/usr/sbin/pkg_version -L =
echo
echo "some packages require certin variables"
echo "I would recommend if any of the packages listed above"
echo "require any to add the args to your pkg_tools.conf file"
echo
echo -n "Are you sure you wish to update all the packages above? [Y/N] >"
read yesnoanswer
case $yesnoanswer in
y | Y)
pu2=1
;;
n | N)
echo "OK Perhaps later on";
echo -n "Portupgrade" && fail
mainmenu
exit 1
;;
esac
echo
echo -n "Please Wait."
/usr/local/sbin/portupgrade -ra && echo -n "Finished portupgrade" && pass && ma
inmenu
echo -n "Finished portupgrade" && fail && mainmenu
exit 1
}
######################################
# Update the BSD OS
######################################
function build1 {
echo
echo "This script will do a series of tasks for you..."
echo "Here's the rundown on what it does.. Please make sure you read"
echo "this and understand before continuing.. it is verry important you"
echo "understand whats about to happen.. First of all Ensure you have Obtained"
echo "The latest sources.. with the correct tags. It's also important to know"
echo "That if you are updating to a new version that requires some extra steps"
echo "This will not perform them for you"
echo
echo "First were going to clean out that /usr/obj dir for you.."
echo "Then were going to create a fresh buildlog"
echo "Once we download the souces were going to do a buildworld (this takes"
echo "a long time to do so get some beer)"
echo "After that i'm going to compile your current kernel for the new OS"
echo "Then were going to atempt to install your new kernel (Check your "
echo "Security levels for this.. then we will install the new os and check"
echo "Various configuration files for changes."
echo
echo
echo -n "Would you like to continue? [y] or [n]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
update=1
;;
n* | n*)
echo "Ok perhaps later on then";
echo -n "Build the OS" && fail
mainmenu
exit 1
;;
esac
# Lets Get to know your system for a second
echo
echo -n "Gathering Information and setting Variables" && pass
echo
DATE=`date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"`
LOG=/var/log/buildlog
Obj=/usr/obj
echo -n "Creating /var/log/buildlog"
THERE=`ls -u /var/log | grep buildlog | wc -l`
KERN=`ls /sys/i386/conf | grep -e '[0123456789]'|tail -1`
pass
echo -n "Determining kernel name"
if [ "${KERN}" = "" ] ; then
KERN=GENERIC
fi
pass
echo "Kernel will be $KERN"
echo
echo -n "Cleansing /usr/src Dir" && pass
echo
# Now lets get rid of those outdated obj's
echo
echo "About to Clean up old distro"
echo
touch $LOCKFILE
echo -n "Please Wait."
idle &
sleep 3
cd $Obj
( chflags -R noschg * ; rm -rf * ) 1>/dev/null 2>&1
cd /usr/src ; make cleandir 1>/dev/null 2>&1 ; make cleandir 1>/dev/null 2>&1 &&
echo -n "Distro Clean" && pass
rm -f $LOCKFILE
# Delete old buildlogs
echo
echo -n "Deleting Old Buildlogs"
echo
if [ $THERE != 1 ] ; then
ing System: $DATE > $LOG
else
rm $LOG && echo Rebuilding System: $DATE > $LOG
pass
fi
# Do Buildworld now
echo
echo "Performing buildworld, This may take a long time.. Go buy some beer and w
ait.."
echo "This operation will take hours"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 7
if make buildworld 1>> $LOG 2>&1
rm -f $LOCKFILE
sleep 1
then echo -n "Buildworld done.." && pass
else echo -n "Buildworld stopped - log mailed to root" ; fail ; tail -30 $LOG |
mail -s "Buildworld failed" root
exit 1
fi
# Build that kernel (or smack 'dat hoe up )
echo
echo "Building new kernel"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 7
if make buildkernel "KERNCONF=${KERN}" 1>> $LOG 2>&1
rm -f $LOCKFILE
sleep 2
then echo -n "Buildkernel Completed" ; pass
else echo -n "Kernel Build stopped = your shit is all fucked up - Log mailed to
root" ; fail ; tail -30 &LOG | mail -s "Kernel Build Failed" root
exit 1
fi
# Remove any FS Restrictions that might get in our way
echo "Removing Filesystem Restrictions that might Cause Errors."
echo "Since your going to reboot after this you should not really care"
mount -u -o exec /tmp
mount -u -o exec /usr
mount -u -o exec /var
mount -u -o exec /
echo -n "Finished All Filesystems are marked as exec" ; pass
# Install that puppie
echo
echo "Installing new kernel"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 2
if make installkernel "KERNCONF=${KERN}" 1>> $LOG 2>&1 && rm -rf $LOCKFILE
then echo -n "Install Kernel Done.." ; pass
else echo -n "Kernel Install Failed.. Boot kernel.olf to recover - Log mailed to
root" ; fail ; tail -30 &LOG | mail -s "New kernel crapped out" root
exit 1
fi
# Doing installworld now
echo
echo "Installing the new BSD OS"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 2
if make installworld 1>> $LOG 2>&1 && rm -f $LOCKFILE
then echo -n "Installworld Completed" ; pass
else echo -n "Installworld Failed - Log mailed to root" ; fail ; tail -30 $LOG |
mail -s "Installworld crapped out" root
exit 1
fi
#mail root info
echo
echo
echo "Ok This is where i give you your final instructions.."
echo
echo "Please once your done review the /var/log/buildlog on what all i did here"
echo "I'm going to copy your /etc dir to /etc.old just in case if you mess up th
e next phase.."
echo
cp /etc /etc.old
echo -n "Directory Backup" ; pass
echo
echo "PAY ATTENTION HERE, especially to the /etc/group and /etc/master.passwd fi
les! Otherwise you will be"
echo "locked out and hating life. For most of the other files you will generally
just hit "i" to install"
echo " the new files and overwrite the old. Double check everything! You're on y
our own."
echo
/usr/sbin/mergemaster -v
echo
echo "Now wasnt that fun?"
echo
echo
echo "Completed"
echo
echo "Well your all done now.. please reboot and enjoy your new OS"
echo "Please Note.. For Users on the 4x branch of FreeBSD once you"
echo "Reboot please goto /dev and run ./MAKEDEV all users on the 5x"
echo "Branch do not have to do this"
echo
echo -n "Build of the BSD OS" ; pass
echo -n "Setting Various Permissions"
chmod 700 /root && pass && exit 0
fail
exit 1
}
################################################## ##
# Update Snort Rules
################################################## ##
function snort {
cd /tmp
rm -rf rules
fetch http://www.snort.org/downloads/snortrules.tar.gz
tar -xzf snortrules.tar.gz
mv /tmp/rules/*.rules $SNORTRULES
echo
echo -n "Snort Rules Have been updated" && pass && mainmenu
fail
mainmenu
exit 0
}
################################################## ##
# Update Tripwire Policy's
################################################## ##
function tripwire {
echo -n "Checking for tripwire"
ls /usr/local/sbin/tripwire 1>/dev/null 2>&1 && pass && trip2
fail
echo
echo "Please install tripwire, Then try again"
echo
mainmenu
exit 1
}
function trip2 {
echo
echo "Updating Tripwire Policies"
echo
/usr/local/sbin/tripwire --update-policy -Z low /usr/local/etc/tripwire/twpol.tx
t
echo
echo "initialized with signature update"
echo
/usr/local/sbin/tripwire --init
echo
echo -n "Updating Complete" && pass & mainmenu
fail
mainmenu
exit 0
}
################################################## ##
# View IPF State Table
################################################## ##
function mon_3 {
/sbin/ipfstat -t
mainmenu
exit 0
}
################################################## ##
# Refresh/Sync IPF/IPNAT
################################################## ##
function mon_4 {
echo
echo -n "Flushing IPF Rules" && pass
/sbin/ipf -Fa -f /etc/ipf.rules
echo
echo -n "Syncing IPF Rules" && pass
/sbin/ipf -y
echo
echo -n "Flushing IPNAT Rules" && pass
/sbin/ipnat -CF -f /etc/ipnat.rules
echo
echo -n "IPF And IPNAT Have Been Flushed And Synced" && pass
echo
ipmon -Dsvn
mainmenu
exit 0
}
################################################## ##
# View Raw Data to a Port
################################################## ##
function mon_5 {
echo
echo -n "What interface to watch over? >"
read IFACE
echo -n "What port would you like to monitor? >"
read PORT
/usr/sbin/tcpdump -e -i $IFACE port $PORT
exit 0
}
################################################## ##
# View Raw Data to the server
################################################## ##
function mon_6 {
echo
echo -n "What interface to watch over? >"
read IFACE
/usr/sbin/tcpdump -e -i $IFACE
exit 0
}
############################################
# View Postfix Queues
############################################
function postqueue {
echo
/usr/local/sbin/postqueue -p && echo && echo -n "Postqueue complete" && pass &&
postmaster
fail
postmaster
exit 0
}
############################################
# Delete queue
############################################
function delqueue {
echo
echo -n "What is the Queue ID to erase? >"
read queue
/usr/local/sbin/postsuper -d $queue && echo && echo -n "Delete Of Queue $queue"
&& pass && postmaster
echo && echo -n "Delete of Queue $queue" && fail && postmaster
exit 0
}
############################################
# Flush Postfix Queue
############################################
function flushqueue {
/usr/local/sbin/postqueue -f && echo && echo -n "Signal Sent to re-send queue" &
& pass && postmaster
echo && echo -n "Signal Sento to-resend queue" && fail && postmaster
exit 0
}
############################################
# Put a queue on hold
############################################
function queuehold {
echo
echo -n "What is the Queue ID to place on hold? >"
read queue
/usr/local/sbin/postsuper -h $queue && echo && echo -n "Queue $queue Placed on h
old" && pass && postmaster
echo && echo -n "Queue $queue Placed on hold" && fail && postmaster
exit 0
}
###########################################
# Requeue postfix queue
###########################################
function requeue {
echo
/usr/local/sbin/postqueue -f && echo && echo -n "Signial Sent to flush queues" &
& pass && postmaster
echo && echo -n "Signial Sent to flush queues" && fail && postmaster
exit 0
}
###########################################
# Postcheck
###########################################
function postcheck {
echo
/usr/local/sbin/postsuper -s && echo && echo -n "check and structure repair" &&
pass && postmaster
echo && echo -n "check and structure repair" && fail && postmaster
exit 0
}
###########################################
# Spam Trap
###########################################
function spam {
mutt -f /var/mail/spam
postmaster
exit 0
}
##########################################
# Backup WWW Tree
##########################################
function bkupwww {
echo -n "Checking for Datestamp dir"
ls $BACKUP/$DATESTAMP 1>/dev/null 2>&1 && pass && www2
fail
echo
echo -n "Creating Datestamp Backup Dir"
mkdir $BACKUP/$DATESTAMP && pass && www2
fail
bckupmnu
exit 1
}
function www2 {
echo "Determining How much disk usage this operation will take"
du -sh /usr/local/www/
du -sh /usr/local/squirrelmail/
echo
echo "Your current Freespace is:"
df -h
echo
echo
while [ x$pu = x ]; do
echo -n "Do you still want to backup? [Y/N]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO ANSWER TO BACKUP
echo -n "Thanks for at least atempting to be a good admin and backing your stuf
f up" && fail
mainmenu
exit 0
;;
esac
done
# YES ANSWER HERE
cd $BACKUP
cd $DATESTAMP
mkdir www ; cd www
echo "Making website backup"
tar cvvpzf usr_local_www.tar.gz /usr/local/www/*
echo "Backing Up webmail"
tar cvvpzf usr_local_squirrelmail.tar.gz /usr/local/squirrelmail/*
echo
echo -n "Backup Of Website Tree Complete" && pass
bckupmnu
exit 0
}
##########################################
# Backup Home Directories
##########################################
function bkuphome {
echo -n "Checking for Datestamp dir"
ls $BACKUP/$DATESTAMP 1>/dev/null 2>&1 && pass && home2
fail
echo
echo -n "Creating Datestamp Backup Dir"
mkdir $BACKUP/$DATESTAMP && pass && home2
fail
bckupmnu
exit 1
}
function home2 {
echo "Determining How much disk usage this operation will take"
du -sh /home
du -sh /root
echo
echo "Your current Freespace is:"
df -h
echo
echo
while [ x$pu = x ]; do
echo -n "Do you still want to backup? [Y/N]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO ANSWER TO BACKUP
echo -n "Thanks for at least atempting to be a good admin and backing your stuf
f up" && fail
mainmenu
exit 0
;;
esac
done
# YES ANSWER HERE
cd $BACKUP
cd $DATESTAMP
mkdir home ; cd home
echo "Making Home directory backup"
tar cvvpzf home.tar.gz /home/*
echo "Backing Up root dir"
tar cvvpzf root.tar.gz /root/*
echo
echo -n "Backup Of Home directories Complete" && pass
bckupmnu
exit 0
}
##########################################
# Backup Common System Dirs.
##########################################
function bkupsys {
echo -n "Checking for Datestamp dir"
ls $BACKUP/$DATESTAMP 1>/dev/null 2>&1 && pass && sys2
fail
echo
echo -n "Creating Datestamp Backup Dir"
mkdir $BACKUP/$DATESTAMP && pass && sys2
fail
bckupmnu
exit 1
}
function sys2 {
echo "Determining How much disk usage this operation will take"
du -sh /boot
du -sh /etc
du -sh /var
du -sh /usr/local/etc
du -sh /wip
du -sh /usr/src/sys/i386/conf
echo
echo "Your current Freespace is:"
df -h
echo
echo
while [ x$pu = x ]; do
echo -n "Do you still want to backup? [Y/N]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO ANSWER TO BACKUP
echo -n "Thanks for at least atempting to be a good admin and backing your stuf
f up" && fail
mainmenu
exit 0
;;
esac
done
# YES ANSWER HERE
cd $BACKUP
cd $DATESTAMP
mkdir system ; cd system
echo "Making boot directory backup"
tar cvvpzf boot.tar.gz /boot
echo "Backing Up etc dir"
tar cvvpzf etc.tar.gz /etc
echo "Backing up var dir"
tar cvvpzf var.tar.gz /var
echo "Backing up usr/local/etc"
tar cvvpzf usr_local_etc.tar.gz /usr/local/etc
echo "Backing up wip"
tar cvvpzf wip.tar.gz /wip
echo "Backing up Kernel Dir"
tar cvvpzf kernel.tar.gz /usr/src/sys/i386/conf
echo -n "Backup Of System directories Complete" && pass
bckupmnu
exit 0
}
######################################
# Global Script Functions
######################################
# Lets make the Pass Fail Function
function pass {
echo " [PASS]"
}
function fail {
echo " [FAIL]"
}
# Find the fastest cvsup server
# This Function came from a script on BSDVAULT.NET from SolarfluX
# Thanks Solar
function findcvs {
echo
echo "Please wait while i find the fastest cvsup server for you"
if test "$#" -lt "1"
then
count="4"
else
count="$1"
fi
range="1 3 5 6 7 8 9 10 11 12 13 14 16 18"
avgmin="500"
avgminname="nonefound"
if [ `id -u` -eq 0 ]
then
pingcmd="ping -c $count -l $count"
else
pingcmd="ping -c $count"
fi
for i in $range
do
avg=`$pingcmd cvsup$i.freebsd.org 2>&1 | grep avg | cut -d'/' -f6 | cut -d'.' -f
1`
if test -n "$avg"
then
if test "$avg" -lt "$avgmin"
then
avgmin=$avg
avgminname="cvsup$i.freebsd.org"
fi
echo "$avg - cvsup$i.freebsd.org"
else
echo "500 - bad host: cvsup$i.freebsd.org"
fi
done
}
# Function For Idle Timer
function idle {
sleep 5
while [ -f $LOCKFILE ]; do
echo -n "."
echo -n "["
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n "/]"
if [ ! -f $LOCKFILE ]; then
break
fi
sleep 2
echo -n
echo -n "-]"
if [ ! -f $LOCKFILE ]; then
break
fi
sleep 2
echo -n
echo -n "\]"
sleep 2
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n
echo -n "|]"
sleep 2
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n
echo -n "/]"
sleep 2
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n
echo -n "-]"
sleep 2
echo -n
done
idle
}
##################################################
# Starting Root Sanity Checks And Start Script
##################################################
clear
echo
echo "Starting Pure Lazyness, Please stand by."
echo -n "Detecting Root Sanity Check"
if [ "`id -u`" != "0" ]; then
fail
echo
echo "You must be root to use this script"
echo
exit 1
fi
pass
echo
echo "Important note"
echo "If you should break out of an operation, to get rid of the twirling"
echo "Cursor please delete $LOCKFILE"
mainmenu
[/code:1:3dbe4f2d76]
the full script can be downloaded at:
http://bsdhound.com/~soup4you2/menu.sh
i would recommend downloading the actual script so you can get the ansi codes...
[code:1:3dbe4f2d76]
################################################## #
# Menu Magic Script Version 3.0
# Written By: Soup4you2
# Website: http://bsdhound.com
# Last Update: 03 July 2003
################################################## #
#TODO
#Fix idle function
#Fix Backup is a datestamp dir exists it automatically performs operation
################################################
# Set Global Vars
#
DATESTAMP=`date +%Y-%m-%d%n`
BACKUP='/public/archives/backups' #NO Trailing Slash Please
SNORTRULES='/usr/local/etc/snort/rules' #Where are your snort rules located a
t?
################################################
## NO EDITING REQUIRED BELOW HERE ##
################################################
VERSION='3.0.5'
LOCKFILE='/tmp/lazy.lock'
LAZYLOG='/tmp/lazy.log' #LOGFILE
set tty erase
# Starting Main Menu
function mainmenu {
echo
echo "Welcome $USER to Pure Lazyness $VERSION"
echo
echo "Allowed Commands Are:"
echo
echo "update - Update to the latest version of Pure Lazy"
echo "update ports - Update the ports tree"
echo "update sources - Update the FreeBSD source tree"
echo "portupgrade - Perform portupgrade"
echo "buildworld - Complete update of the BSD OS"
echo "snort - Update snort rules"
echo "tripwire - Update tripwire policy"
echo "state - View IPF State table"
echo "refresh - Refresh IPF/IPNAT/IPMON"
echo "portmon - Monitor Raw data to a specified port"
echo "rawdata - Monitor all raw data to a interface"
echo
echo "backup - Enter backup menu"
echo "postmaster - Enter Postfix postmaster menu"
echo
echo "exit - Quit this script"
echo
# Define Menu Functions
echo -n "COMMAND > "
read mmi
if [ "$mmi" = "update" ];then update
fi
if [ "$mmi" = "update ports" ];then ports
fi
if [ "$mmi" = "update sources" ];then sources
fi
if [ "$mmi" = "portupgrade" ];then portupgrade
fi
if [ "$mmi" = "buildworld" ];then build1
fi
if [ "$mmi" = "snort" ];then snort
fi
if [ "$mmi" = "tripwire" ];then tripwire
fi
if [ "$mmi" = "state" ];then mon_3
fi
if [ "$mmi" = "refresh" ];then mon_4
fi
if [ "$mmi" = "portmon" ];then mon_5
fi
if [ "$mmi" = "rawdata" ];then mon_6
fi
if [ "$mmi" = "backup" ];then bckupmnu
fi
if [ "$mmi" = "postmaster" ];then postmaster
fi
if [ "$mmi" = "idle" ]; then touch $LOCKFILE && idle
fi
if [ "$mmi" = "exit" ];then quitter
else
echo "Invalid Command"
sleep 2
mainmenu
fi
}
# Backup Menu
function bckupmnu {
echo
echo "www - Backup Website directory structure"
echo "home - Backup Home directory structure"
echo "system - Backup Common System Directories"
echo
echo "return - Return to main menu"
echo
# Define Menu Functions
echo -n "BACKUP > "
read bkup
if [ "$bkup" = "www" ];then bkupwww
fi
if [ "$bkup" = "home" ];then bkuphome
fi
if [ "$bkup" = "system" ];then bkupsys
fi
if [ "$bkup" = "return" ];then mainmenu
else
echo "Invalid Command"
sleep 2
bckupmnu
fi
}
# Postmaster menu
function postmaster {
echo
echo "queue - View Active queues"
echo "delqueue - Delete a queue"
echo "flush - Atempt to re-deliver queue"
echo "hold - Put a queue on hold"
echo "requeue - Requeue message"
echo "check - Structure check and structure repair."
echo "spam - View trapped messages in spam trap"
echo
echo "return - Return to main menu"
echo
# Define Menu Functions
echo -n "POSTMASTER > "
read pmopt
if [ "$pmopt" = "queue" ];then postqueue
fi
if [ "$pmopt" = "delqueue" ];then delqueue
fi
if [ "$pmopt" = "flush" ];then flushqueue
fi
if [ "$pmopt" = "hold" ];then queuehold
fi
if [ "$pmopt" = "requeue" ];then requeue
fi
if [ "$pmopt" = "check" ];then postcheck
fi
if [ "$pmopt" = "spam" ];then spam
fi
if [ "$pmopt" = "return" ];then mainmenu
else
echo "Invalid Command"
sleep 2
postmaster
fi
}
# Exit Procedures
function quitter {
echo
echo "Thanks for using my script.."
echo "Please be sure to check out http://bsdhound.com"
echo "For updates. or new projects"
echo
exit 0
}
####################################
# Update to latest version
####################################
function update {
echo "Please wait while i update this script"
if fetch http://bsdhound.com/~soup4you2/menu.sh ; echo -n "Update of script"
then pass
else fail
fi
echo
echo "Please dont forget to set the Variables in the top of the file"
echo -n "Setting Permissions"
chown root:wheel menu.sh && chmod 750 menu.sh && pass && echo "Please restart th
e script now" && exit 0
fail && exit 0
exit 0
}
####################################
# Update the ports tree
####################################
function ports {
# VERIFY PRE-REQS
echo -n "Checking for CVSUP"
ls /usr/local/bin/cvsup 1>/dev/null 2>&1 && pass && ports2
fail
echo
echo "Please install cvsup, Then try again"
echo
mainmenu
exit 1
}
function ports2 {
echo -n "Checking for prior supfile"
ls /usr/local/etc/ports-supfile 1>/dev/null 2>&1 && pass && upports
fail
# No Supfile Exists
echo
echo "I have failed to detect a ports-supfile"
echo "This script looks for it in /usr/local/etc/"
echo
echo -n "Would you like me to build you a ports-supfile? [Y/N] "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO TO SUPFILE CREATION SCRIPT
echo "Perhaps later on then.."
echo "Please wait while I return you to the main menu"
echo
echo -n "Update of ports tree" && fail
sleep 2
mainmenu
exit 0
;;
esac
# YES TO SUPFILE CREATION SCRIPT
findcvs
echo
echo "Your Ideal CVSUP server will be $avgminname"
echo
echo
echo -n "Creating /usr/local/etc/ports-supfile"
echo "*default host=$avgminname" >> /usr/local/etc/ports-supfile
echo "*default base=/usr" >> /usr/local/etc/ports-supfile
echo "*default prefix=/usr" >> /usr/local/etc/ports-supfile
echo "*default release=cvs tag=." >> /usr/local/etc/ports-supfile
echo "*default delete use-rel-suffix" >> /usr/local/etc/ports-supfile
echo "*default compress" >> /usr/local/etc/ports-supfile
echo "*default umask=002" >> /usr/local/etc/ports-supfile
echo "ports-all" >> /usr/local/etc/ports-supfile
pass
echo -n "Setting Permissions"
if chmod 600 /usr/local/etc/ports-supfile
then pass
else fail
fi
echo "Please wait while updating ports"
touch $LOCKFILE
echo
echo -n "Please Wait."
idle &
sleep 3
/usr/local/bin/cvsup -g /usr/local/etc/ports-supfile 1>/dev/null 2>&1 && rm -f $
LOCKFILE && echo && echo -n "Update of ports" && pass && sleep 3 && mainmenu
fail && exit 1
exit 0
}
# Supfile Exists Function
function upports {
echo
echo "Updating Ports with existing supfile"
echo
echo "Please wait while updating ports"
touch $LOCKFILE
echo
echo -n "Please Wait."
idle &
sleep 3
/usr/local/bin/cvsup -g /usr/local/etc/ports-supfile 1>/dev/null 2>&1 && rm -f $
LOCKFILE && echo && echo -n "Update of ports" && pass && sleep 3 && mainmenu
fail && exit 1
exit 0
}
#####################################
# Update The FreeBSD Sources
#####################################
function sources {
# VERIFY PRE-REQS
echo
echo -n "Checking for CVSUP"
ls /usr/local/bin/cvsup 1>/dev/null 2>&1 && pass && source2
fail
echo
echo "Please install cvsup, Then try again"
echo
mainmenu
exit 1
}
function source2 {
echo -n "Checking for prior supfile"
ls /usr/local/etc/cvs-supfile 1>/dev/null 2>&1 && pass && upcvs2
fail
# No Supfile Exists
echo
echo "I have failed to detect a cvs-supfile"
echo "This script looks for it in /usr/local/etc/"
echo
echo -n "Would you like me to build you a cvs-supfile? [Y/N] "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO TO SUPFILE CREATION SCRIPT
echo "Perhaps later on then.."
echo "Please wait while I return you to the main menu"
echo
echo -n "Update of source tree" && fail
sleep 2
mainmenu
exit 0
;;
esac
# YES TO SUPFILE CREATION SCRIPT
upcvs
exit 0
}
function upcvs {
findcvs
echo
echo "Your Ideal CVSUP server will be $avgminname"
echo
echo -n "What is your cvs tag to use? (ie. RELENG_5_1) >"
read release
echo -n "Creating /usr/local/etc/ports-supfile for $release"
echo "*default host=$avgminname" >> /usr/local/etc/cvs-supfile
echo "*default base=/usr" >> /usr/local/etc/cvs-supfile
echo "*default prefix=/usr" >> /usr/local/etc/cvs-supfile
echo "*default release=cvs tag=$release" >> /usr/local/etc/cvs-supfile
echo "*default delete use-rel-suffix" >> /usr/local/etc/cvs-supfile
echo "*default compress" >> /usr/local/etc/cvs-supfile
echo "*default umask=002" >> /usr/local/etc/cvs-supfile
echo "src-all" >> /usr/local/etc/cvs-supfile
pass
echo -n "Setting Permissions"
chmod 600 /usr/local/etc/cvs-supfile && pass
upcvs2
}
function upcvs2 {
echo "Please wait while updating ports"
echo
echo -n "Please Wait."
touch $LOCKFILE
idle &
sleep 3
/usr/local/bin/cvsup -g -L 2 /usr/local/etc/cvs-supfile 1>/dev/null 2>&1 && rm -
f $LOCKFILE && echo && echo -n "Update of sources" && pass && sleep 3 && mainmen
u
fail && exit 1
exit 0
}
##################################
# Portupgrade
##################################
function portupgrade {
# VERIFY PRE-REQS
echo -n "Checking for portupgrade"
ls /usr/local/sbin/portupgrade 1>/dev/null 2>&1 && pass && pu2
fail
echo
echo "Please install portupgrade, Then try again"
echo
exit 1
}
function pu2 {
echo
echo "Rebuilding package database"
/usr/local/sbin/pkgdb -F && echo -n "Database rebuilt" && pass
echo
echo "Listing packages to be updated"
echo
/usr/sbin/pkg_version -L =
echo
echo "some packages require certin variables"
echo "I would recommend if any of the packages listed above"
echo "require any to add the args to your pkg_tools.conf file"
echo
echo -n "Are you sure you wish to update all the packages above? [Y/N] >"
read yesnoanswer
case $yesnoanswer in
y | Y)
pu2=1
;;
n | N)
echo "OK Perhaps later on";
echo -n "Portupgrade" && fail
mainmenu
exit 1
;;
esac
echo
echo -n "Please Wait."
/usr/local/sbin/portupgrade -ra && echo -n "Finished portupgrade" && pass && ma
inmenu
echo -n "Finished portupgrade" && fail && mainmenu
exit 1
}
######################################
# Update the BSD OS
######################################
function build1 {
echo
echo "This script will do a series of tasks for you..."
echo "Here's the rundown on what it does.. Please make sure you read"
echo "this and understand before continuing.. it is verry important you"
echo "understand whats about to happen.. First of all Ensure you have Obtained"
echo "The latest sources.. with the correct tags. It's also important to know"
echo "That if you are updating to a new version that requires some extra steps"
echo "This will not perform them for you"
echo
echo "First were going to clean out that /usr/obj dir for you.."
echo "Then were going to create a fresh buildlog"
echo "Once we download the souces were going to do a buildworld (this takes"
echo "a long time to do so get some beer)"
echo "After that i'm going to compile your current kernel for the new OS"
echo "Then were going to atempt to install your new kernel (Check your "
echo "Security levels for this.. then we will install the new os and check"
echo "Various configuration files for changes."
echo
echo
echo -n "Would you like to continue? [y] or [n]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
update=1
;;
n* | n*)
echo "Ok perhaps later on then";
echo -n "Build the OS" && fail
mainmenu
exit 1
;;
esac
# Lets Get to know your system for a second
echo
echo -n "Gathering Information and setting Variables" && pass
echo
DATE=`date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"`
LOG=/var/log/buildlog
Obj=/usr/obj
echo -n "Creating /var/log/buildlog"
THERE=`ls -u /var/log | grep buildlog | wc -l`
KERN=`ls /sys/i386/conf | grep -e '[0123456789]'|tail -1`
pass
echo -n "Determining kernel name"
if [ "${KERN}" = "" ] ; then
KERN=GENERIC
fi
pass
echo "Kernel will be $KERN"
echo
echo -n "Cleansing /usr/src Dir" && pass
echo
# Now lets get rid of those outdated obj's
echo
echo "About to Clean up old distro"
echo
touch $LOCKFILE
echo -n "Please Wait."
idle &
sleep 3
cd $Obj
( chflags -R noschg * ; rm -rf * ) 1>/dev/null 2>&1
cd /usr/src ; make cleandir 1>/dev/null 2>&1 ; make cleandir 1>/dev/null 2>&1 &&
echo -n "Distro Clean" && pass
rm -f $LOCKFILE
# Delete old buildlogs
echo
echo -n "Deleting Old Buildlogs"
echo
if [ $THERE != 1 ] ; then
ing System: $DATE > $LOG
else
rm $LOG && echo Rebuilding System: $DATE > $LOG
pass
fi
# Do Buildworld now
echo
echo "Performing buildworld, This may take a long time.. Go buy some beer and w
ait.."
echo "This operation will take hours"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 7
if make buildworld 1>> $LOG 2>&1
rm -f $LOCKFILE
sleep 1
then echo -n "Buildworld done.." && pass
else echo -n "Buildworld stopped - log mailed to root" ; fail ; tail -30 $LOG |
mail -s "Buildworld failed" root
exit 1
fi
# Build that kernel (or smack 'dat hoe up )
echo
echo "Building new kernel"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 7
if make buildkernel "KERNCONF=${KERN}" 1>> $LOG 2>&1
rm -f $LOCKFILE
sleep 2
then echo -n "Buildkernel Completed" ; pass
else echo -n "Kernel Build stopped = your shit is all fucked up - Log mailed to
root" ; fail ; tail -30 &LOG | mail -s "Kernel Build Failed" root
exit 1
fi
# Remove any FS Restrictions that might get in our way
echo "Removing Filesystem Restrictions that might Cause Errors."
echo "Since your going to reboot after this you should not really care"
mount -u -o exec /tmp
mount -u -o exec /usr
mount -u -o exec /var
mount -u -o exec /
echo -n "Finished All Filesystems are marked as exec" ; pass
# Install that puppie
echo
echo "Installing new kernel"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 2
if make installkernel "KERNCONF=${KERN}" 1>> $LOG 2>&1 && rm -rf $LOCKFILE
then echo -n "Install Kernel Done.." ; pass
else echo -n "Kernel Install Failed.. Boot kernel.olf to recover - Log mailed to
root" ; fail ; tail -30 &LOG | mail -s "New kernel crapped out" root
exit 1
fi
# Doing installworld now
echo
echo "Installing the new BSD OS"
echo
touch $LOCKFILE
echo -n "Please Wait."
sleep 1
idle &
sleep 2
if make installworld 1>> $LOG 2>&1 && rm -f $LOCKFILE
then echo -n "Installworld Completed" ; pass
else echo -n "Installworld Failed - Log mailed to root" ; fail ; tail -30 $LOG |
mail -s "Installworld crapped out" root
exit 1
fi
#mail root info
echo
echo
echo "Ok This is where i give you your final instructions.."
echo
echo "Please once your done review the /var/log/buildlog on what all i did here"
echo "I'm going to copy your /etc dir to /etc.old just in case if you mess up th
e next phase.."
echo
cp /etc /etc.old
echo -n "Directory Backup" ; pass
echo
echo "PAY ATTENTION HERE, especially to the /etc/group and /etc/master.passwd fi
les! Otherwise you will be"
echo "locked out and hating life. For most of the other files you will generally
just hit "i" to install"
echo " the new files and overwrite the old. Double check everything! You're on y
our own."
echo
/usr/sbin/mergemaster -v
echo
echo "Now wasnt that fun?"
echo
echo
echo "Completed"
echo
echo "Well your all done now.. please reboot and enjoy your new OS"
echo "Please Note.. For Users on the 4x branch of FreeBSD once you"
echo "Reboot please goto /dev and run ./MAKEDEV all users on the 5x"
echo "Branch do not have to do this"
echo
echo -n "Build of the BSD OS" ; pass
echo -n "Setting Various Permissions"
chmod 700 /root && pass && exit 0
fail
exit 1
}
################################################## ##
# Update Snort Rules
################################################## ##
function snort {
cd /tmp
rm -rf rules
fetch http://www.snort.org/downloads/snortrules.tar.gz
tar -xzf snortrules.tar.gz
mv /tmp/rules/*.rules $SNORTRULES
echo
echo -n "Snort Rules Have been updated" && pass && mainmenu
fail
mainmenu
exit 0
}
################################################## ##
# Update Tripwire Policy's
################################################## ##
function tripwire {
echo -n "Checking for tripwire"
ls /usr/local/sbin/tripwire 1>/dev/null 2>&1 && pass && trip2
fail
echo
echo "Please install tripwire, Then try again"
echo
mainmenu
exit 1
}
function trip2 {
echo
echo "Updating Tripwire Policies"
echo
/usr/local/sbin/tripwire --update-policy -Z low /usr/local/etc/tripwire/twpol.tx
t
echo
echo "initialized with signature update"
echo
/usr/local/sbin/tripwire --init
echo
echo -n "Updating Complete" && pass & mainmenu
fail
mainmenu
exit 0
}
################################################## ##
# View IPF State Table
################################################## ##
function mon_3 {
/sbin/ipfstat -t
mainmenu
exit 0
}
################################################## ##
# Refresh/Sync IPF/IPNAT
################################################## ##
function mon_4 {
echo
echo -n "Flushing IPF Rules" && pass
/sbin/ipf -Fa -f /etc/ipf.rules
echo
echo -n "Syncing IPF Rules" && pass
/sbin/ipf -y
echo
echo -n "Flushing IPNAT Rules" && pass
/sbin/ipnat -CF -f /etc/ipnat.rules
echo
echo -n "IPF And IPNAT Have Been Flushed And Synced" && pass
echo
ipmon -Dsvn
mainmenu
exit 0
}
################################################## ##
# View Raw Data to a Port
################################################## ##
function mon_5 {
echo
echo -n "What interface to watch over? >"
read IFACE
echo -n "What port would you like to monitor? >"
read PORT
/usr/sbin/tcpdump -e -i $IFACE port $PORT
exit 0
}
################################################## ##
# View Raw Data to the server
################################################## ##
function mon_6 {
echo
echo -n "What interface to watch over? >"
read IFACE
/usr/sbin/tcpdump -e -i $IFACE
exit 0
}
############################################
# View Postfix Queues
############################################
function postqueue {
echo
/usr/local/sbin/postqueue -p && echo && echo -n "Postqueue complete" && pass &&
postmaster
fail
postmaster
exit 0
}
############################################
# Delete queue
############################################
function delqueue {
echo
echo -n "What is the Queue ID to erase? >"
read queue
/usr/local/sbin/postsuper -d $queue && echo && echo -n "Delete Of Queue $queue"
&& pass && postmaster
echo && echo -n "Delete of Queue $queue" && fail && postmaster
exit 0
}
############################################
# Flush Postfix Queue
############################################
function flushqueue {
/usr/local/sbin/postqueue -f && echo && echo -n "Signal Sent to re-send queue" &
& pass && postmaster
echo && echo -n "Signal Sento to-resend queue" && fail && postmaster
exit 0
}
############################################
# Put a queue on hold
############################################
function queuehold {
echo
echo -n "What is the Queue ID to place on hold? >"
read queue
/usr/local/sbin/postsuper -h $queue && echo && echo -n "Queue $queue Placed on h
old" && pass && postmaster
echo && echo -n "Queue $queue Placed on hold" && fail && postmaster
exit 0
}
###########################################
# Requeue postfix queue
###########################################
function requeue {
echo
/usr/local/sbin/postqueue -f && echo && echo -n "Signial Sent to flush queues" &
& pass && postmaster
echo && echo -n "Signial Sent to flush queues" && fail && postmaster
exit 0
}
###########################################
# Postcheck
###########################################
function postcheck {
echo
/usr/local/sbin/postsuper -s && echo && echo -n "check and structure repair" &&
pass && postmaster
echo && echo -n "check and structure repair" && fail && postmaster
exit 0
}
###########################################
# Spam Trap
###########################################
function spam {
mutt -f /var/mail/spam
postmaster
exit 0
}
##########################################
# Backup WWW Tree
##########################################
function bkupwww {
echo -n "Checking for Datestamp dir"
ls $BACKUP/$DATESTAMP 1>/dev/null 2>&1 && pass && www2
fail
echo
echo -n "Creating Datestamp Backup Dir"
mkdir $BACKUP/$DATESTAMP && pass && www2
fail
bckupmnu
exit 1
}
function www2 {
echo "Determining How much disk usage this operation will take"
du -sh /usr/local/www/
du -sh /usr/local/squirrelmail/
echo
echo "Your current Freespace is:"
df -h
echo
echo
while [ x$pu = x ]; do
echo -n "Do you still want to backup? [Y/N]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO ANSWER TO BACKUP
echo -n "Thanks for at least atempting to be a good admin and backing your stuf
f up" && fail
mainmenu
exit 0
;;
esac
done
# YES ANSWER HERE
cd $BACKUP
cd $DATESTAMP
mkdir www ; cd www
echo "Making website backup"
tar cvvpzf usr_local_www.tar.gz /usr/local/www/*
echo "Backing Up webmail"
tar cvvpzf usr_local_squirrelmail.tar.gz /usr/local/squirrelmail/*
echo
echo -n "Backup Of Website Tree Complete" && pass
bckupmnu
exit 0
}
##########################################
# Backup Home Directories
##########################################
function bkuphome {
echo -n "Checking for Datestamp dir"
ls $BACKUP/$DATESTAMP 1>/dev/null 2>&1 && pass && home2
fail
echo
echo -n "Creating Datestamp Backup Dir"
mkdir $BACKUP/$DATESTAMP && pass && home2
fail
bckupmnu
exit 1
}
function home2 {
echo "Determining How much disk usage this operation will take"
du -sh /home
du -sh /root
echo
echo "Your current Freespace is:"
df -h
echo
echo
while [ x$pu = x ]; do
echo -n "Do you still want to backup? [Y/N]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO ANSWER TO BACKUP
echo -n "Thanks for at least atempting to be a good admin and backing your stuf
f up" && fail
mainmenu
exit 0
;;
esac
done
# YES ANSWER HERE
cd $BACKUP
cd $DATESTAMP
mkdir home ; cd home
echo "Making Home directory backup"
tar cvvpzf home.tar.gz /home/*
echo "Backing Up root dir"
tar cvvpzf root.tar.gz /root/*
echo
echo -n "Backup Of Home directories Complete" && pass
bckupmnu
exit 0
}
##########################################
# Backup Common System Dirs.
##########################################
function bkupsys {
echo -n "Checking for Datestamp dir"
ls $BACKUP/$DATESTAMP 1>/dev/null 2>&1 && pass && sys2
fail
echo
echo -n "Creating Datestamp Backup Dir"
mkdir $BACKUP/$DATESTAMP && pass && sys2
fail
bckupmnu
exit 1
}
function sys2 {
echo "Determining How much disk usage this operation will take"
du -sh /boot
du -sh /etc
du -sh /var
du -sh /usr/local/etc
du -sh /wip
du -sh /usr/src/sys/i386/conf
echo
echo "Your current Freespace is:"
df -h
echo
echo
while [ x$pu = x ]; do
echo -n "Do you still want to backup? [Y/N]: "
read yesnoanswer
case $yesnoanswer in
y* | Y*)
pu=1
;;
n* | n*)
# NO ANSWER TO BACKUP
echo -n "Thanks for at least atempting to be a good admin and backing your stuf
f up" && fail
mainmenu
exit 0
;;
esac
done
# YES ANSWER HERE
cd $BACKUP
cd $DATESTAMP
mkdir system ; cd system
echo "Making boot directory backup"
tar cvvpzf boot.tar.gz /boot
echo "Backing Up etc dir"
tar cvvpzf etc.tar.gz /etc
echo "Backing up var dir"
tar cvvpzf var.tar.gz /var
echo "Backing up usr/local/etc"
tar cvvpzf usr_local_etc.tar.gz /usr/local/etc
echo "Backing up wip"
tar cvvpzf wip.tar.gz /wip
echo "Backing up Kernel Dir"
tar cvvpzf kernel.tar.gz /usr/src/sys/i386/conf
echo -n "Backup Of System directories Complete" && pass
bckupmnu
exit 0
}
######################################
# Global Script Functions
######################################
# Lets make the Pass Fail Function
function pass {
echo " [PASS]"
}
function fail {
echo " [FAIL]"
}
# Find the fastest cvsup server
# This Function came from a script on BSDVAULT.NET from SolarfluX
# Thanks Solar
function findcvs {
echo
echo "Please wait while i find the fastest cvsup server for you"
if test "$#" -lt "1"
then
count="4"
else
count="$1"
fi
range="1 3 5 6 7 8 9 10 11 12 13 14 16 18"
avgmin="500"
avgminname="nonefound"
if [ `id -u` -eq 0 ]
then
pingcmd="ping -c $count -l $count"
else
pingcmd="ping -c $count"
fi
for i in $range
do
avg=`$pingcmd cvsup$i.freebsd.org 2>&1 | grep avg | cut -d'/' -f6 | cut -d'.' -f
1`
if test -n "$avg"
then
if test "$avg" -lt "$avgmin"
then
avgmin=$avg
avgminname="cvsup$i.freebsd.org"
fi
echo "$avg - cvsup$i.freebsd.org"
else
echo "500 - bad host: cvsup$i.freebsd.org"
fi
done
}
# Function For Idle Timer
function idle {
sleep 5
while [ -f $LOCKFILE ]; do
echo -n "."
echo -n "["
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n "/]"
if [ ! -f $LOCKFILE ]; then
break
fi
sleep 2
echo -n
echo -n "-]"
if [ ! -f $LOCKFILE ]; then
break
fi
sleep 2
echo -n
echo -n "\]"
sleep 2
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n
echo -n "|]"
sleep 2
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n
echo -n "/]"
sleep 2
if [ ! -f $LOCKFILE ]; then
break
fi
echo -n
echo -n "-]"
sleep 2
echo -n
done
idle
}
##################################################
# Starting Root Sanity Checks And Start Script
##################################################
clear
echo
echo "Starting Pure Lazyness, Please stand by."
echo -n "Detecting Root Sanity Check"
if [ "`id -u`" != "0" ]; then
fail
echo
echo "You must be root to use this script"
echo
exit 1
fi
pass
echo
echo "Important note"
echo "If you should break out of an operation, to get rid of the twirling"
echo "Cursor please delete $LOCKFILE"
mainmenu
[/code:1:3dbe4f2d76]