[Apt-zip-devel] r62 - in branches/nix-scripts: . debian methods

Eddy Petrisor eddyp-guest at costa.debian.org
Sun Jul 23 21:16:30 UTC 2006


Author: eddyp-guest
Date: 2006-07-23 21:16:29 +0000 (Sun, 23 Jul 2006)
New Revision: 62

Added:
   branches/nix-scripts/methods/commonmeth.sh
   branches/nix-scripts/methods/write-fetch-wget
Modified:
   branches/nix-scripts/Makefile
   branches/nix-scripts/debian/changelog
   branches/nix-scripts/methods/wget
Log:
attempting to make things easier to add new methods

Modified: branches/nix-scripts/Makefile
===================================================================
--- branches/nix-scripts/Makefile	2006-07-23 20:08:19 UTC (rev 61)
+++ branches/nix-scripts/Makefile	2006-07-23 21:16:29 UTC (rev 62)
@@ -9,8 +9,8 @@
 METHDIR=	${SHAREDIR}/methods
 SCRIPTS=	apt-zip-list
 SSCRIPTS=	apt-zip-inst
-SHARED=		common.sh
-METHODS=	wget # lftp
+SHARED=		common.sh commonmeth.sh
+METHODS=	wget write-fetch-wget # lftp
 CONFFILE=	apt-zip.conf
 MANPAGE=	apt-zip.8
 MANLINKS=	${SCRIPTS:=.8} ${SSCRIPTS:=.8}

Modified: branches/nix-scripts/debian/changelog
===================================================================
--- branches/nix-scripts/debian/changelog	2006-07-23 20:08:19 UTC (rev 61)
+++ branches/nix-scripts/debian/changelog	2006-07-23 21:16:29 UTC (rev 62)
@@ -1,6 +1,9 @@
 apt-zip (0.16) UNRELEASED; urgency=low
 
+  [ Eddy Petrișor ]
   * more indenting improvement in common.sh.in file
+  * spimplified the way to add new methods if *NIX systems are used;
+     now is only a matter of definig a methods/write-fetch-$METHOD script
 
  -- Eddy Petrișor <eddy.petrisor at gmail.com>  Mon,  5 Jun 2006 22:44:21 +0300
 

Added: branches/nix-scripts/methods/commonmeth.sh
===================================================================
--- branches/nix-scripts/methods/commonmeth.sh	2006-07-23 20:08:19 UTC (rev 61)
+++ branches/nix-scripts/methods/commonmeth.sh	2006-07-23 21:16:29 UTC (rev 62)
@@ -0,0 +1,182 @@
+#!/bin/bash -e
+
+error()
+{
+    echo >&2 "apt-zip/methods/$(basename $0) ERROR: $*"
+    exit 1
+}
+
+warn()
+{
+    echo >&2 "apt-zip/methods/$(basename $0) WARNING: $*"
+}
+
+
+
+###############
+# write header
+#
+
+cat <<-EOF
+	#!/bin/sh
+	# This file was auto-generated by apt-zip-list ${APTZIPVERSION}
+	# Method: $(basename $0) - Options: ${OPTIONS}
+	err(){
+	    echo >&2 "Fetching \$1 failed (\$2)"
+	}
+EOF
+
+source write-fetch-$METHOD
+
+###############
+# add check code, if is wanted
+#
+[ ! "${USEMD5SUMS}" = 'no' ] && cat <<-EOF
+	check(){
+	    [ ! -r "\$1" ] && return 1
+	    [ "\`type md5sum\`" ] &&
+	        if [ "\`md5sum \$1 | cut -d' ' -f1\`" = \$2 ]
+	        then return 0
+	        else err \$1 "wrong MD5"; return 1
+	        fi
+	    [ "\`type gzip\`" ] &&
+	        if ar p \$1 data.tar.gz | gzip -t
+	        then return 0
+	        else err \$1 "wrong contents"; return 1
+	        fi
+	    return \$3
+	}
+EOF
+
+
+###############
+# Differences between gnutar and solaris
+#
+if [ "$OPTION_SOLARISTAR" != 0 ] ; then
+	TAR="${OPTION_SOLARISTAR}"
+	TAREXTRACT=xnf
+	TARTEST=tnqif
+	TARADD=rnf
+elif [ "$OPTION_GNUTAR" != 0 ] ; then
+	TAR="${OPTION_GNUTAR}"
+	TAREXTRACT=xf
+	TARTEST=tf
+	TARADD=rf
+else
+	TAR="${OPTION_TAR}"
+	TAREXTRACT=xf
+	TARTEST=tf
+	TARADD=rf
+fi
+
+[ "$OPTION_RESTART" = 0 -a "$OPTION_GNUTAR" != 0 -a  "$OPTION_SOLARISTAR" = 0 ] && warn "RESTART without SOLARISTAR is currently awfully slow"
+###############
+# Stuff dependant on RESTART option
+#
+
+if [ "$OPTION_RESTART" = 0 ]
+then
+	cat <<-EOF
+
+	do_fetch() {
+	    #wget -t3 -nv -O \$2 \$1
+	    fetch \$2 \$1
+	    ${CHECK} \$2 \$4 \$?
+	    ${SLEEPCMD}
+	    return \$?
+	}
+
+EOF
+else
+    if [ "$OPTION_GNUTAR" != 0 ]
+    then
+	OLDTARFILE="old-$APTZIPTARFILE"
+	cat <<-EOF
+		[ -r "$APTZIPTARFILE" ] &&
+		if [ -r "$OLDTARFILE" ]
+		then
+		    "$OPTION_GNUTAR" Af "$OLDTARFILE" "$APTZIPTARFILE"
+		else
+		    mv "$APTZIPTARFILE" "$OLDTARFILE"
+		fi
+
+		do_fetch() {
+		    if [ -r "$OLDTARFILE" ] && "$TAR" "$TARTEST" "$OLDTARFILE" \$2 >/dev/null 2>&1
+		    then
+		        "$TAR" "$TAREXTRACT" "$OLDTARFILE" \$2
+		        if [ -r \$2 ] && ${CHECK} \$2 \$4 \$? ; then echo "Already got \$2"; return 0; fi
+		    fi
+		    #wget -nc -t3 -nv -O \$2 \$1
+		    fetch \$2 \$1
+		    ${CHECK} \$2 \$4 \$?
+		    ${SLEEPCMD}
+		    return \$?
+		}
+
+EOF
+	elif [ "$OPTION_TAR" = 0 ] ; then
+	cat <<-EOF
+	do_fetch() {
+	    if [ -r ../\$2 ] && ${CHECK} ../\$2 \$4 \$? ; then echo "Already got \$2"; return 1; fi
+	    #wget -t3 -nv -O \$2 \$1
+	    fetch \$2 \$1
+	    ${CHECK} \$2 \$4 \$?
+	    ${SLEEPCMD}
+	    return \$?
+	}
+
+EOF
+	else # OPTION_GNUTAR == 0 and OPTION_TAR != 0
+		error "RESTART only supported with GNUTAR or without TAR"
+	fi
+fi
+
+###############
+# Stuff dependant on TAR option
+#
+
+if [ "$OPTION_TAR" = 0 ]
+then
+	cat <<-EOF
+
+	getfile(){
+	    ( [ -r ../\$2 ] &&  ${CHECK} ../\$2 \$4 \$?  &&   echo \$2 already downloaded.) ||
+	    (do_fetch \$1 \$2 \$3 \$4   &&   mv \$2 ../)
+	}
+
+	mkdir -p partial && cd partial || echo >&2  "Cannot change to directory ./partial"
+EOF
+else
+	cat <<-EOF
+
+	getfile(){
+	    do_fetch \$1 \$2 \$3 \$4 &&
+	    $TAR $TARADD $APTZIPTARFILE \$2 &&
+	    rm \$2
+	}
+
+	touch foo-stamp && "$OPTION_TAR" cf "$APTZIPTARFILE" foo-stamp && rm foo-stamp
+EOF
+fi
+
+###############
+# Feed the data to the core function
+#
+
+cat <<-EOF
+
+	echo Download will be of size: "$DWLSIZE" in "$PACKCOUNT" files
+	while read URL FILE SIZE MD5
+	do getfile \$URL \$FILE \$SIZE \$MD5 || true
+	done <<EOP
+EOF
+
+###############
+# The data itself
+#
+cat
+
+###############
+# End-Of-Packages marker
+#
+echo "EOP"

Modified: branches/nix-scripts/methods/wget
===================================================================
--- branches/nix-scripts/methods/wget	2006-07-23 20:08:19 UTC (rev 61)
+++ branches/nix-scripts/methods/wget	2006-07-23 21:16:29 UTC (rev 62)
@@ -1,176 +1,5 @@
 #!/bin/bash -e
+METHOD=(basename $0)
 
-error()
-{
-    echo >&2 "apt-zip/methods/$(basename $0) ERROR: $*"
-    exit 1
-}
+source commonmeth.sh
 
-warn()
-{
-    echo >&2 "apt-zip/methods/$(basename $0) WARNING: $*"
-}
-
-###############
-# write header
-#
-
-cat <<-EOF
-	#!/bin/sh
-	# This file was auto-generated by apt-zip-list ${APTZIPVERSION}
-	# Method: wget - Options: ${OPTIONS}
-	err(){
-	    echo >&2 "Fetching \$1 failed (\$2)"
-	}
-EOF
-
-
-###############
-# add check code, if is wanted
-#
-[ ! "${USEMD5SUMS}" = 'no' ] && cat <<-EOF
-	check(){
-	    [ ! -r "\$1" ] && return 1
-	    [ "\`type md5sum\`" ] &&
-	        if [ "\`md5sum \$1 | cut -d' ' -f1\`" = \$2 ]
-	        then return 0
-	        else err \$1 "wrong MD5"; return 1
-	        fi
-	    [ "\`type gzip\`" ] &&
-	        if ar p \$1 data.tar.gz | gzip -t
-	        then return 0
-	        else err \$1 "wrong contents"; return 1
-	        fi
-	    return \$3
-	}
-EOF
-
-
-###############
-# Differences between gnutar and solaris
-#
-if [ "$OPTION_SOLARISTAR" != 0 ] ; then
-	TAR="${OPTION_SOLARISTAR}"
-	TAREXTRACT=xnf
-	TARTEST=tnqif
-	TARADD=rnf
-elif [ "$OPTION_GNUTAR" != 0 ] ; then
-	TAR="${OPTION_GNUTAR}"
-	TAREXTRACT=xf
-	TARTEST=tf
-	TARADD=rf
-else
-	TAR="${OPTION_TAR}"
-	TAREXTRACT=xf
-	TARTEST=tf
-	TARADD=rf
-fi
-
-[ "$OPTION_RESTART" = 0 -a "$OPTION_GNUTAR" != 0 -a  "$OPTION_SOLARISTAR" = 0 ] && warn "RESTART without SOLARISTAR is currently awfully slow"
-###############
-# Stuff dependant on RESTART option
-#
-
-if [ "$OPTION_RESTART" = 0 ]
-then
-	cat <<-EOF
-
-	do_wget() {
-	    wget -t3 -nv -O \$2 \$1
-	    ${CHECK} \$2 \$4 \$?
-	    ${SLEEPCMD}
-	    return \$?
-	}
-
-EOF
-else
-    if [ "$OPTION_GNUTAR" != 0 ]
-    then
-	OLDTARFILE="old-$APTZIPTARFILE"
-	cat <<-EOF
-		[ -r "$APTZIPTARFILE" ] &&
-		if [ -r "$OLDTARFILE" ]
-		then
-		    "$OPTION_GNUTAR" Af "$OLDTARFILE" "$APTZIPTARFILE"
-		else
-		    mv "$APTZIPTARFILE" "$OLDTARFILE"
-		fi
-
-		do_wget() {
-		    if [ -r "$OLDTARFILE" ] && "$TAR" "$TARTEST" "$OLDTARFILE" \$2 >/dev/null 2>&1
-		    then
-		        "$TAR" "$TAREXTRACT" "$OLDTARFILE" \$2
-		        if [ -r \$2 ] && ${CHECK} \$2 \$4 \$? ; then echo "Already got \$2"; return 0; fi
-		    fi
-		    wget -nc -t3 -nv -O \$2 \$1
-		    ${CHECK} \$2 \$4 \$?
-		    ${SLEEPCMD}
-		    return \$?
-		}
-
-EOF
-	elif [ "$OPTION_TAR" = 0 ] ; then
-	cat <<-EOF
-	do_wget() {
-	    if [ -r ../\$2 ] && ${CHECK} ../\$2 \$4 \$? ; then echo "Already got \$2"; return 1; fi
-	    wget -t3 -nv -O \$2 \$1
-	    ${CHECK} \$2 \$4 \$?
-	    ${SLEEPCMD}
-	    return \$?
-	}
-
-EOF
-	else # OPTION_GNUTAR == 0 and OPTION_TAR != 0
-		error "RESTART only supported with GNUTAR or without TAR"
-	fi
-fi
-
-###############
-# Stuff dependant on TAR option
-#
-
-if [ "$OPTION_TAR" = 0 ]
-then
-	cat <<-EOF
-
-	getfile(){
-	    ( [ -r ../\$2 ] &&  ${CHECK} ../\$2 \$4 \$?  &&   echo \$2 already downloaded.) ||
-	    (do_wget \$1 \$2 \$3 \$4   &&   mv \$2 ../)
-	}
-
-	mkdir -p partial && cd partial || echo >&2  "Cannot change to directory ./partial"
-EOF
-else
-	cat <<-EOF
-
-	getfile(){
-	    do_wget \$1 \$2 \$3 \$4 &&
-	    $TAR $TARADD $APTZIPTARFILE \$2 &&
-	    rm \$2
-	}
-
-	touch foo-stamp && "$OPTION_TAR" cf "$APTZIPTARFILE" foo-stamp && rm foo-stamp
-EOF
-fi
-
-###############
-# Feed the data to the core function
-#
-
-cat <<-EOF
-
-	echo Download will be of size: "$DWLSIZE" in "$PACKCOUNT" files
-	while read URL FILE SIZE MD5
-	do getfile \$URL \$FILE \$SIZE \$MD5 || true
-	done <<EOP
-EOF
-
-###############
-# The data itself
-#
-cat
-
-###############
-# End-Of-Packages marker
-#
-echo "EOP"

Added: branches/nix-scripts/methods/write-fetch-wget
===================================================================
--- branches/nix-scripts/methods/write-fetch-wget	2006-07-23 20:08:19 UTC (rev 61)
+++ branches/nix-scripts/methods/write-fetch-wget	2006-07-23 21:16:29 UTC (rev 62)
@@ -0,0 +1,9 @@
+
+cat <<-EOF
+
+#$2 contains the local file and $1 contains the URL
+fetch () {
+	    wget -t3 -nv -O \$2 \$1
+}
+
+EOF




More information about the apt-zip-devel mailing list