author hg@mozilla.com
Thu, 22 Mar 2007 10:30:00 -0700
changeset 1 9b2a99adc05e53cd4010de512f50118594756650
permissions -rwxr-xr-x
Free the (distributed) Lizard! Automatic merge from CVS: Module mozilla: tag HG_REPO_INITIAL_IMPORT at 22 Mar 2007 10:30 PDT,

#! /bin/bash

#original author: Alice Nodelman
#contributor: Darin Fisher
#takes two inputs, $1 = file containing list of web pages of form http://pagename
#                  $2 = output file where list of index files is dumped - useful for places list of links into scripts
# web pages are dropped in directories named for their urls

if [ $# != 2 ]; then
	echo 'missing command line arguments'
	echo 'usage: getpages.sh inputfile outputfile'
	echo '	inputfile: file containing one url per line of the form http://url'
	echo '	outputfile: file to be created during execution, contains a list of index files one per url'

# generates the list of files to be cleansed (exclude image files)
# disables any existing call-outs to the live web
# provided by Darin Fisher
cleanse_files() {
	  find "$1" -type f -a -print0 ! -iname \*.jpg -a ! -iname \*.gif -a ! -iname \*.png -a ! -name \*.bak | xargs -0 perl -pi -e 's/[a-zA-Z0-9_]*.writeln/void/g;' -e 's/[a-zA-Z0-9_]*.write/void/g;' -e 's/[a-zA-Z0-9_]*.open/void/g;' -e 's/"https/"httpsdisabled/gi;' -e 's/"http/"httpdisabled/gi;' -e 's/<object/<objectdisabled/gi;' -e 's/<embed/<embeddisabled/gi;' -e 's/load/loaddisabled/g;'

mkdir testpages
cd testpages
for URL in $(cat ../$1); do
	#strip the leading http:// from the url
	CLEANURL=$(echo $URL | sed -e 's/http:\/\/\(.*\)/\1/')
	#create a directory with the cleaned url as the name
	echo "grabbing "$CLEANURL
	mkdir $CLEANURL
	../../wget-1.10-css-parser/src/wget -p -k -H -E -erobots=off --no-check-certificate -U "Mozilla/5.0 (firefox)" --restrict-file-names=windows $URL -o outputlog.txt
	#figure out where/what the index file for this page is from the wget output log
	FILENAME=$(grep "saved" outputlog.txt | head -1 | sed -e "s/.*\`\(.*\)\'.*/\1/")
	rm outputlog.txt
	cd ..

	#do the final cleanup of any dangling urls
	#with thanks to Darin Fisher for the code
	cleanse_files $CLEANURL

	#add the index file link to the list of index files being generated
cd ..