source: pkgtools/genmd5

Last change on this file was d70d2bd, checked in by Paweł Foremski <pjf@…>, 10 years ago

general update, new env vars, etc.

  • Property mode set to 100755
File size: 3.5 KB
Line 
1#!/bin/bash
2#
3# genmd5, part of Arch Linux's makepkg
4#
5# Copyright (C) 2002-2004 Judd Vinet <jvinet@zeroflux.org>
6# Copyright (C) 2005-2009 ASN Sp. z o.o.
7#
8# Authors: Pawel Foremski <pjf@asn.pl>
9#          Michał Wróbel <maw@asn.pl>
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24# USA.
25#
26# TODO: share some code with makepkg
27#
28
29myver='0.21'
30startdir=`pwd`
31
32
33### SUBROUTINES ###
34msg() { echo "==> $1" >&2; }
35warning() { echo "==> WARNING: $1" >&2; }
36error() { echo "==> ERROR: $1" >&2; msg "Aborting..."; exit ${2:-1}; }
37
38strip_url() { echo $1 | sed 's|^.*://.*/||g'; }
39
40usage() {
41        echo "genmd5 version $myver"
42        echo "usage: $0 [options]"
43        echo "options:"
44        echo "  -h, --help       This help"
45        echo "  -p <buildscript> Use an alternate build script (instead of PKGBUILD)"
46        echo
47        echo "  if -p is not specified, makepkg will look for a PKGBUILD"
48        echo "  file in the current directory."
49        echo
50}
51
52# options
53BUILDSCRIPT="./PKGBUILD"
54
55ARGLIST=$@
56while [ "$#" -ne "0" ]; do
57        case $1 in
58                --help) usage; exit 0 ;;
59                --*)    usage; exit 1 ;;
60                -*)
61                        while getopts "p:-" opt; do
62                                case $opt in
63                                        h) usage; exit 0 ;;
64                                        p) BUILDSCRIPT=$OPTARG ;;
65                                        -) OPTIND=0; break ;;
66                                        *) usage; exit 1 ;;
67                                esac
68                        done
69                        ;;
70                *) true ;;
71        esac
72        shift
73done
74
75unset pkgname pkgver pkgrel md5sums source install build
76umask 0022
77
78### prepare
79[ ! -f $BUILDSCRIPT ] && error "$BUILDSCRIPT does not exist."
80source $BUILDSCRIPT
81
82[ `echo $pkgver | grep '-'` ] && error "pkgver is not allowed to contain hyphens."
83[ `echo $pkgrel | grep '-'` ] && error "pkgrel is not allowed to contain hyphens."
84
85msg "Generating MD5 sums for package: $pkgname (`date`)"
86cd $startdir
87
88# retrieve sources
89msg "Retrieving sources..."
90mkdir -p $FB_PKGDW
91cd $FB_PKGDW
92
93for netfile in ${source[@]}; do
94        file=`strip_url $netfile`
95
96        if [ -f $file ]; then
97                msg "    Found $file in build dir"
98        else
99                [ -z "$FB_FTPAGENT" ] && error "FTPAGENT is not configured."
100                ftpclient=`echo $FB_FTPAGENT | awk {'print $1'}`
101                [ -z "`which $ftpclient 2> /dev/null`" ] && error "ftpclient `basename $ftpclient` is not installed."
102
103                proto=`echo $netfile | sed 's|://.*||'`
104                [ "$proto" != "ftp" -a "$proto" != "http" -a "$proto" != "https" ] && \
105                        error "$netfile was not found in the build directory and is not a proper URL."
106
107                msg "    Downloading $file"
108                $FB_FTPAGENT $netfile 2>&1
109                [ ! -f $file ] && error "Failed to download $file"
110        fi
111done
112
113# generate md5 hashes
114[ ! `type -p md5sum` ] && error "Cannot find the md5sum program."
115
116msg "Generating MD5 sums for source files"
117echo
118
119ct=0
120newline=0
121numsrc=${#source[@]}
122
123for netfile in ${source[@]}; do
124        file=`strip_url $netfile`
125        sum=`md5sum $file | cut -d' ' -f 1`
126
127        if [ $ct -eq 0 ]; then
128                echo -n "md5sums=("
129        else
130                [ $newline -eq 0 ] && echo -n "         "
131        fi
132
133        echo -n "'$sum'"
134        let ct++
135
136        if [ $ct -eq $numsrc ]; then
137                echo ')'
138        else
139                if [ $newline -eq 1 ]; then
140                        echo ' \'
141                        newline=0
142                else
143                        echo -n ' '
144                        newline=1
145                fi
146        fi
147done
148
149echo
150exit 0
Note: See TracBrowser for help on using the repository browser.