#!/bin/sh

# fetch PDF text

set -e

# resolve options
eval set -- "$(getopt -s sh -o f -- "$@")"
while true; do case "$1" in -f) force=1; shift;; --) shift; break;; esac; done

. /lib/lsb/init-functions

# operate on both files if none provided
test "$#" -gt 0 || eval set -- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

log_action_begin_msg "Fetch PDF"
for stem in "$@"; do
	outfile=$stem.pdf
	log_action_cont_msg $stem
	[ -n "$force" ] || [ ! -f $outfile ] || [ $outfile -ot "$0" ] || { log_warning_msg "skipped"; continue; }
	case $stem in
	  1) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2009:078:0001:0042:en:PDF';;
	  2) wget -O$outfile 'http://www.europarl.europa.eu/registre/docs_autres_institutions/commission_europeenne/com/2013/0161/COM_COM%282013%290161_EN.pdf';;
	  3) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=CELEX:52012PC0011:EN:PDF';;
# disappeared 20130510
#	  4) wget -O$outfile 'http://www.statewatch.org/news/2013/may/eu-coe-data-protection-8825-13.pdf';;
	  4) wget -O$outfile 'http://erikjosefsson.eu/sites/default/files/Council-20130424-GDPR-statewatch-leak.pdf';;
# the following 5 documents are ACTA leaks and the 6th is the final ACTA text
	  5) wget -O$outfile 'http://www.laquadrature.net/files/201001_acta.pdf';;
	  6) wget -O$outfile 'http://trade.ec.europa.eu/doclib/docs/2010/april/tradoc_146029.pdf';;
	  7) wget -O$outfile 'http://www.erikjosefsson.eu/sites/default/files/ACTA_leak_20100701.pdf';;
	  8) wget -O$outfile 'http://keionline.org/sites/default/files/acta_aug25_dc.pdf';;
	  9) wget -O$outfile 'http://keionline.org/sites/default/files/actaoct2010.pdf';;
	 10) wget -O$outfile 'http://trade.ec.europa.eu/doclib/docs/2011/may/tradoc_147937.pdf';;
# the following 9 documents are EUR-LEX files, the first each year in the Offical Journal of the EU (OJ) starting 1996
	 11) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:1996:001:0001:001:en:PDF';;
	 12) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:1997:001:0001:001:en:PDF';;
	 13) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:1998:001:0001:001:en:PDF';;
	 14) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:1999:001:0001:001:en:PDF';;
	 15) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2000:001:0001:001:en:PDF';;
	 16) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2001:001:0001:001:en:PDF';;
	 17) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2002:001:0001:001:en:PDF';;
	 18) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2003:001:0001:001:en:PDF';;
	 19) wget -O$outfile 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2004:001:0001:001:en:PDF';;
	esac
done
log_action_end_msg $?