forked from openSUSE/cpanspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpanget
executable file
·80 lines (64 loc) · 1.65 KB
/
cpanget
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
#!/bin/sh
set -e
CPAN=${CPAN:-"http://www.cpan.org"}
packages=$HOME/.cpan/sources/modules/02packages.details.txt.gz
npackages=$HOME/.local/share/.cpan/sources/modules/02packages.details.txt.gz
if test -e $npackages; then
packages=$npackages
fi
quiet=''
only_url=0
help() {
cat <<END
Usage: $( basename $0 ) [options] [module [module [...]]]
Options:
-h Print this message
-n Don't download, only print URLs
-q Work quietly
END
}
for n in "$@" ; do
if [ "$( echo '' "$n" | sed 's/^ //;s/^\(.\).*$/\1/' )" = "-" ] ; then
shift
for arg in $( echo '' "$n" | sed 's/^ //;s/^-//;s/./ &/g' ) ; do
case $arg in
[h?])
help
exit 0
;;
n)
only_url=1
;;
q)
quiet='-s'
;;
*)
echo "Unknown option '$arg'."
help
exit 1
;;
esac
done
else
break
fi
done
if [ $# -eq 0 ] ; then
help
exit 1
fi
mkdir -p $( dirname $packages )
(cd $(dirname $packages) && wget -q -N -nd $CPAN/modules/$( basename $packages ) )
for module in "$@" ; do
tar=$( zgrep '^'$module' ' $packages | awk '{print $3}' )
if [ -z "$tar" ] ; then
echo "Can't find $module, skipping..." >&2
continue
fi
if [ $only_url -eq 0 ] ; then
curl $quiet -R -o "$( basename $tar )" $CPAN/authors/id/$tar
else
echo "$module: $CPAN/authors/id/$tar"
fi
done
# vi: set ai et: