]> gitweb.fluxo.info Git - httruta.git/commitdiff
Merge common options
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 26 Aug 2013 00:58:38 +0000 (21:58 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 26 Aug 2013 00:58:38 +0000 (21:58 -0300)
lib/httracker/functions

index 33152b1cca1d178b6c0a360bdc352178419535fa..1a4fa7ffdf91119ee97b09d2898ffbbcd387d0ae 100644 (file)
@@ -3,11 +3,25 @@
 # Misc httracker functions.
 #
 
+function httracker_opts {
+  OPTS=" --mirror                 \
+         --continue               \
+         --depth=${DEPTH}         \
+         --ext-depth ${EXT_DEPTH} \
+         --near                   \
+         --purge-old=0            \
+         --index                  \
+         --cookies=1              \
+         --path ${target}"
+}
+
 function httracker_get {
+  # Options
   local url="$1"
   local hash="`echo $1 | sha1sum | cut -d ' ' -f 1`"
   local target="$MIRRORS/$hash"
 
+  # Make sure that target exists
   mkdir -p $target
 
   # We already got this one
@@ -15,28 +29,21 @@ function httracker_get {
     return
   fi
 
+  # Basic options
+  httracker_opts
+
+  # Additional options
   if [ "`whoami`" == "root" ]; then
-    OPTS="--user $USER"
-  else
-    OPTS=""
+    OPTS="$OPTS --user $USER"
   fi
 
+  # Fix permissions
   if [ "`whoami`" != "$USER" ] && [ "`whoami`" == "root" ]; then
     chown -R $USER.$GROUP $target/
   fi
 
   # Get each URL
-  httrack                    \
-    --mirror                 \
-    --continue               \
-    --depth=${DEPTH}         \
-    --ext-depth ${EXT_DEPTH} \
-    --near                   \
-    --purge-old=0            \
-    --index                  \
-    --cookies=1              \
-    --path ${target}         \
-    ${OPTS} ${url}
+  httrack ${OPTS} ${url}
 
   if [ "$?" == "0" ]; then
     # Mark as downloaded
@@ -55,26 +62,19 @@ function httracker_get_incremental {
   target=${MIRRORDIR}/${year}/${month}
   sudo -u links mkdir -p ${target}
 
+  # Basic options
+  httracker_opts
+
+  # Additional options
   if [ "`whoami`" == "root" ]; then
     OPTS="--user $USER"
-  else
-    OPTS=""
   fi
 
   # Grabs URLs from the network
-  httrack                          \
-          --mirror                 \
-          --continue               \
-          --depth=${DEPTH}         \
-          --ext-depth ${EXT_DEPTH} \
-          --near                   \
-          --purge-old=0            \
-          --index                  \
-          --cookies=1              \
+  httrack ${OPTS}                  \
           --user links             \
           --list ${URLS}           \
-          --path ${target} ${OPTS}
-
+          --path ${target}
 }
 
 function httracker_scuttle_config() {