View Single Post
  #2   (View Single Post)  
Old 7th January 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,776
Default The 'snapget' sh script

Code:
#!/bin/sh
# $Id: snapget,v 1.4 2010/01/07 01:42:05 j65nko Exp $
# get snapshot files with a on the fly generated '.netrc' for ftp(1)


DESTDIR="Snapshots"
if [ -d ${DESTDIR} ] ; then
   rm -f ${DESTDIR}/*
else
   mkdir -p ${DESTDIR} || exit 1
fi

# -- destination directory 
# DESTDIR="SNAP$(date -u "+%Y-%m-%d_%H:%M_UTC")"
# mkdir ${DESTDIR} || exit 1

echo "Destination directory: ${DESTDIR}"

# variables  used in 'netrc' template
# ------------------------------------------------------------------
ARCH='i386'		# architecture name used as ftp dir
#ARCH='amd64'		# architecture name used as ftp dir

RN=46			# used in "base${RN}.tgz" etc
#VERSION='4.6'		# ftp dir for releases
VERSION='snapshots'	# ftp dir for snapshots

DIR="/pub/OpenBSD/${VERSION}/${ARCH}"  

SITE='ftp.calyx.nl'
SITE='ftp.eu.openbsd.org'
SITE='ftp.esat.net'
SITE='ftp.openbsd.org'
SITE='ftp.wu-wien.ac.at'
SITE='ftp.eu.openbsd.org'
SITE='ftp.nluug.nl'

# customizable file sets 
# if you add or remove sets, don't forget the update the ALLSETS variable 
# ------------------------------------------------------------------

#SETS_START
# ------------------------------------------------------------------
base="
INSTALL.${ARCH}
SHA256
base${RN}.tgz
bsd
bsd.mp
bsd.rd
comp${RN}.tgz
etc${RN}.tgz
man${RN}.tgz
misc${RN}.tgz
"

x="
xbase${RN}.tgz
xetc${RN}.tgz
xfont${RN}.tgz
xserv${RN}.tgz
xshare${RN}.tgz
"

mini="
SHA256
base${RN}.tgz
bsd
bsd.rd
etc${RN}.tgz
"
pxe="
pxeboot
"

floppy="
floppy${RN}.fs
floppyB${RN}.fs
floppyC${RN}.fs
"
man="
man${RN}.tgz
"

misc="
misc${RN}.tgz
"
iso="
install${RN}.iso
"
# ------------------------------------------------------------------
#SETS_END

# ------------------------------------------------------------------
ALLSETS="base x mini pxe floppy man misc iso"
# ------------------------------------------------------------------

if [ $# -eq 0 ] ; then
    echo "$0: Please specify one or more sets"
    echo "The sets are: ${ALLSETS}"
    exit 1
fi

# -- accumulate all sets in FILES
for SET in "$@" ; do
     eval CONTENTS=\"\$${SET}\"
     if [ "x${CONTENTS}" = "x" ] ; then
         echo "$0 : undefined set ${SET}"
         echo "$0 : aborting"
         exit 1
     fi 
    FILES="${FILES} ${CONTENTS} "
done

# echo ${FILES} | tr '[:blank:]' '\n'

# --- 'here document' as '.netrc' template

cat <<-TEMPLATE >${DESTDIR}/.netrc

machine ${SITE} login anonymous password thanks@puffy.org

macdef init
prompt off
epsv4 off
preserve on
$( for THIS in ${FILES} ; do 
     echo "get ${DIR}/${THIS} ${DESTDIR}/${THIS}" 
   done
)
quit

TEMPLATE

# -- An empty line is the terminator for a macdef macro
# -- So KEEP EMPTY LINE between 'quit' and here document marker 'TEMPLATE'
# -- to prevent 'Macro definition missing null line terminator' messages
# -- from 'ftp'

echo -------------- Created '.netrc'-----------------------
cat -n  $DESTDIR/.netrc
echo ------------------------------------------------------
echo "Do you want to start 'ftp' with this '.netrc' ? (Y/N)" ; read answer

case "$answer" in
[Yy] )		;;

*    )		echo "$0: I take this for a 'NO', aborting ..."
    		exit 2
		;;
esac

# -- ftp uses HOME to locate '.netrc'
env HOME=${DESTDIR} ftp -4 ${SITE} 2>&1 | tee ${DESTDIR}/Logfile

# -- EOF
At this moment the script does not prompt for the ftp site, or architecture. You will have to edit the variables in the script itself.

Because the forum software insists on a file extension, you will have to rename the downloaded script to remove the '.txt'
Code:
$ mv snapget.txt snapget

$ chmod u+x snapget
Attached Files
File Type: txt snapget.txt (3.1 KB, 92 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote