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

Code:
#!/bin/sh
# $Id: release-fetch,v 1.5 2010/01/16 20:13:08 j65nko Exp $
# fetch FreeBSD release files and boot-only-iso with ftp and .netrc 

#  Copyright (c) 2006,2007,2008,2009 J65nko <Administrator daemonforums.org>
# 
#  Permission to use, copy, modify, and distribute this software for any
#  purpose with or without fee is hereby granted, provided that the above
#  copyright notice and this permission notice appear in all copies.
# 
#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 

# -- start of user configurable settings

#SITE=ftp4.freebsd.org
#SITE=ftp2.dk.FreeBSD.org
SITE=ftp.nl.freebsd.org

RN='8.0'
#ARCH=i386
ARCH=amd64

MY_ISO_DIR="ISO"

# -- end of user configurable settings

RELEASE="${RN}-RELEASE"
DIR=/pub/FreeBSD/releases/${ARCH}/${RELEASE}
FILE=${ARCH}_${RELEASE}files.txt

# -------- bootonly.iso -----------------------
# ftp://ftp.nl.freebsd.org/pub/FreeBSD/ISO-IMAGES-i386/8.0/
# 8.0-RELEASE-i386-bootonly.iso

ISO_DIR="/pub/FreeBSD/ISO-IMAGES-${ARCH}/${RN}"
BOI="${RELEASE}-${ARCH}-bootonly.iso"
MD5="CHECKSUM.MD5"
SHA256="CHECKSUM.SHA256"

# -----------------------------------------
#
get_main_listing() {
    echo "ls ${DIR} ${FILE}" | ftp -4ai ${SITE} 1>&2 
}

get_main_listing

# select the release file directories 
SETS=$(awk '/^d/ { printf " %s", $9 }' ${FILE} )
# select the release documents
DOCS=$(awk '/^-r/ { printf " %s" , $9 }' ${FILE} )

# -- Create .netrc using 'here document'

cat <<END_OF_NETRC

machine ${SITE}

macdef init
prompt off
! mkdir ${MY_ISO_DIR}
lcd ${MY_ISO_DIR}
cd ${ISO_DIR} 
mget ${BOI} ${MD5} ${SHA256}
lcd ..
cd ${DIR}
mget ${DOCS} 
$ getdir ${SETS}
! ln -s . ${RELEASE} 
quit

macdef getdir
! mkdir \$i
mget \$i/*

END_OF_NETRC

# print Usage message on stderr
cat <<END >&2
-------------------------------------------------------------
Remember that ftp(1) uses the HOME environment variable to locate .netrc
Assuming you saved and/or edited .netrc in the current directory or '.',
use it as follows:

env HOME=. ftp -4a ftp://${SITE} 2>&1 | tee Logfile

END
__________________
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