1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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
|