Allow partial downloads.
[minipack.git] / tools / mpk-source
blobeb342792dd1de48eed785a9bb6d9b3b79762822d
1 # mpk-source - downloads source code
2 # This file is part of Minipack - an automated build tool.
4 # Copyright (C) 2008 Cesar Strauss
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 get_source()
22   do_get_source
25 do_get_source()
27   : ${source_package_type:=tar.gz}
28   : ${source:=$name-$version.$source_package_type}
30   if [ -z "$force" -a -e $sourcedir/$source ]; then
31     exit 0
32   fi
34   if [ -n "$origin" ]; then
35     case $origin in
36       gnu) pkg_download="http://ftp.gnu.org/pub/gnu/$name/$source";;
37       sf) pkg_download="http://downloads.sourceforge.net/sourceforge/$name/$source";;
38       *) echo >&2 "$name: Unknown origin."; exit 1;;
39     esac
40   fi
41   
42   if [ -n "$download" ]; then
43     pkg_download=$download/$source
44   fi
46   if [ -z "$pkg_download" ]; then
47     echo >&2 "$name: download location not found."
48     exit 1
49   fi
51   mkdir -p $sourcedir/partial
52   cd $sourcedir/partial
53   echo Downloading $name from $pkg_download ...
54   wget -c $pkg_download
56   if [ $? != 0 ]; then
57     echo >&2 "$(basename $0) source: Failed to download $name"
58     exit 1
59   fi
60   
61   mv $sourcedir/partial/$source $sourcedir
64 case $1 in
65   -f|--force) force=yes; shift;;
66   -*) echo "$(basename $0) source: unrecognized option"; exit 1;;
67 esac
69 pkg=$1
71 if [ -z "$pkg" ]; then
72   echo "Usage: $(basename $0) source package-name ..."
73   exit 1
76 recipe=$(get_recipe_name $pkg) || exit 1
78 . $recipe
80 get_source