summaryrefslogtreecommitdiff
path: root/.files/.pget/pget-wch
diff options
context:
space:
mode:
Diffstat (limited to '.files/.pget/pget-wch')
-rwxr-xr-x.files/.pget/pget-wch232
1 files changed, 232 insertions, 0 deletions
diff --git a/.files/.pget/pget-wch b/.files/.pget/pget-wch
new file mode 100755
index 0000000..f7e9e25
--- /dev/null
+++ b/.files/.pget/pget-wch
@@ -0,0 +1,232 @@
+#!/bin/sh
+# pget
+ver="0.6.3.4.1"
+#
+# Copyright (C) 2009 Luke Shumaker
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# Originally written by Luke Shumaker <lukeshu@sbcglobal.net>.
+
+
+#####################################################################
+#################### Option Handling ####################
+#####################################################################
+mode="get"
+a=""
+file=""
+ua="Pget/$ver"
+base=""
+mode="help"
+while [ $# -gt 0 ]; do; case "$1" in
+ # subsitutions
+ -V | -v | --version) mode="version"; break;;
+ -h | --help ) mode="help"; break;;
+ # directory base
+ -B) base="$2"; shift;;
+ # prepends URL to relative links in -F -i file.
+ --base=*) base="$($1 | sed s/--base=//)";;
+ # user agent
+ -U) ua=$2; shift;;
+ # identify as AGENT instead of Pget/VERSION.
+ --user-agent=*) ua=$($1 | sed s/--user-agent=//);;
+ # file
+ -i) mode="file"; code=$2; shift;;
+ # download URLs found in FILE.
+ --input-file=*)
+ mode="file";
+ code=$($1 | sed "s/--input-file=//");;
+ # not implemented functions
+ -e | --execute=* ) mode="error"; code="$1";;
+ #Recursive download:
+ -r | --recursive ) mode="error"; code="$1";;
+ -l | --level=* ) mode="error"; code="$1";;
+ --delete-after ) mode="error"; code="$1";;
+ -k | --convert-links ) mode="error"; code="$1";;
+ -K | --backup-converted ) mode="error"; code="$1";;
+ -m | --mirror ) mode="error"; code="$1";;
+ --page-requisites ) mode="error"; code="$1";;
+ --strict-comments ) mode="error"; code="$1";;
+ -A | --accept=* ) mode="error"; code="$1";;
+ -R | --reject=* ) mode="error"; code="$1";;
+ -D | --domains=* ) mode="error"; code="$1";;
+ --exclude-domains=* ) mode="error"; code="$1";;
+ --follow-ftp ) mode="error"; code="$1";;
+ --follow-tags=* ) mode="error"; code="$1";;
+ --ignore-tags=* ) mode="error"; code="$1";;
+ -H | --span-hosts ) mode="error"; code="$1";;
+ -L | --relative ) mode="error"; code="$1";;
+ -I | --include-directories=*) mode="error"; code="$1";;
+ -X | --exclude-directories=*) mode="error"; code="$1";;
+ -np | --no-parent ) mode="error"; code="$1";;
+ # removed functions
+ -O | --output-document=* ) mode="wget"; code="$1";;
+ -nc | --no-clobber ) mode="wget"; code="$1";;
+ -c | --continue ) mode="wget"; code="$1";;
+ -N | --timestamping ) mode="wget"; code="$1";;
+ --spider ) mode="wget"; code="$1";;
+ -P | --directory-prefix=* ) mode="wget"; code="$1";;
+ # general handling
+ # these are all wget options that take a second argument
+ -o | -a | -t | -T | -w | -Q) a="$a $1 $2"; shift;;
+ --) shift; break;;
+ -g | -p) break;;
+ -*) a="$a $1";;
+ *) break;; # terminate while loop
+esac
+shift
+done
+
+# all command line switches are processed,
+# "$@" contains all file names
+
+#####################################################################
+#################### The Core ####################
+#####################################################################
+if [ $mode = "file" ]; then
+ set -- $(cat $code | tr '\n' ' ')
+ mode="get"
+fi
+
+if [ $mode = "get" ]; then
+ od=$PWD
+ gz="false"
+ p="false"
+ while [ $# -gt 0 ]; do
+ while [ 1 -gt 0 ]; do
+ case "$1" in
+ -g) gz="true";;
+ -p) p="$2"; shift;;
+ *) break;;
+ esac
+ shift
+ done
+
+ cache="$HOME/.pget/cache/$(dirname $2)"
+ mkdir -p $cache
+ cd $cache
+
+ got="false"
+ file="$1"
+ temp="$HOME/.pget/cache/$2"
+
+ if [ $gz = "true" ]; then
+ echo -n "A cached copy of the archive "
+ if [ -e $temp ]; then
+ echo "already exists"
+ before="$(stat -c %Y $temp)"
+ else
+ echo "does not exist"
+ before="false"
+ fi
+ else
+ if [ -e $file ]; then
+ echo "A local copy already exists"
+ before="$(stat -c %Y $file)"
+ mv $file $temp
+ else
+ echo "A local copy does not exist"
+ before="false"
+ fi
+ fi
+
+ cd "$cache"
+ echo "\033[31m"
+ wget -N -U "$ua" $a $base$2
+ echo "\033[0m"
+ after=$(stat -c %Y $temp)
+ if [ "$before" != "$after" ]; then
+ echo "A new version of the file was retrieved"
+ if [ $gz = "true" ]; then
+ echo "Decompressing..."
+ gunzip -c $temp > $file
+ gz=""
+ else
+ mv $temp $file
+ fi
+
+ if [ $p != "false" ]; then
+ chmod $p $file
+ p="false"
+ fi
+ else
+ echo "A new version of the file was not retreived"
+ if [ $gz = "false" ]; then
+ mv $temp $file
+ fi
+ fi
+ shift 2
+ done
+ cd $od
+fi
+
+#####################################################################
+#################### Messages! ####################
+#####################################################################
+if [ $mode = "wget" ]; then; cat <<__wget__
+You used the $code option."
+This is a valid option in wget, but does not make sense in pget."
+__wget__
+fi
+
+if [ $mode = "error" ]; then; cat <<__error__
+You used the $code option. This is a valid option in wget,"
+but has not been implemented in pget."
+This does not mean it cannot be, it just hasn't yet."
+ PATCHES ARE WELCOME!"
+"
+For more information on pget, try 'pget -h' or 'pget --help'."
+For more information on Wget, try 'wget -h' or 'wget --help'."
+__error__
+fi
+
+if [ $mode = "version" ]; then; cat <<__version__
+pget $ver, running on top of $(wget -V | grep -i wget)"
+"
+pget (but not Wget) is copyright (C) 2009 Luke Shumaker"
+This program is distributed in the hope that it will be useful,"
+but WITHOUT ANY WARRANTY; without even the implied warranty of"
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
+GNU General Public License for more details."
+"
+Originally written by Luke Shumaker <lukeshu@sbcglobal.net>."
+"
+Use 'wget -V' for more information about Wget"
+__version__
+fi
+
+if [ $mode = "help" ]; then; cat <<__help__
+pget $ver, a non-interactive network retriever for eventual use in a
+package manager and version control system.
+Usage: pget [OPTIONS] [OPTIONS1] [FILE1] [URL1] [OPTIONS2] [FILE2] [URL2]...
+ or: pget [OPTIONS] -i [FILELIST]
+
+Mandatory arguments to long options are mandatory for short options too.
+With arguments to short options, insert a space between them
+ do: -f file
+ don't: -ffile
+
+All of the pget options work are exactly like wget,
+ with the exeption that recursion is disabled,
+ as are
+ -O, --output-document=FILE write documents to FILE.
+ -nc, --no-clobber skip downloads that would download
+ to existing files.
+ -c, --continue resume getting a partially-
+ downloaded file.
+ -N, --timestamping pget always checks timestamps
+ --spider don't download anything.
+ -P, --directory-prefix=PREFIX save files to PREFIX/...
+ and '-e' / '--execute=*' is not implemented [yet],
+
+File options:
+ -g The file needs to be ran throught gunzip.
+ -p PERMISSIONS Run 'chown PERMISSIONS FILENAME' on the
+ file after it is downloaded
+
+Report bugs to <lukeshu@sbcglobal.net>.
+__help__
+fi
+