Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=038505f71f4ae8b3aa0acadfca0420e445b166ec

commit 038505f71f4ae8b3aa0acadfca0420e445b166ec
Author: Michel Hermier <[email protected]>
Date:   Wed Nov 21 23:20:38 2012 +0100

scripts/makepkg

* Move sha1sum gpg checker and generator to functions.

diff --git a/scripts/makepkg b/scripts/makepkg
index dac6911..cddee01 100755
--- a/scripts/makepkg
+++ b/scripts/makepkg
@@ -750,6 +750,142 @@ buildscript_create_changelog() {
fi
}

+sources_sha1sum_validate() {
+       if [ ${#sha1sums[@]} -eq ${#source[@]} ]; then
+               if [ `type -p sha1sum` ]; then
+                       msg "Validating source files with SHA1sums"
+                       errors=0
+                       idx=0
+                       for netfile in "${source[@]}"; do
+                               file=`strip_url "$netfile"`
+                               $ECHO -n "    $file ... " >&2
+                               $ECHO "${sha1sums[$idx]}  $file" | sha1sum -c - 
>/dev/null 2>&1
+                               if [ $? -ne 0 ]; then
+                                       $ECHO "FAILED" >&2
+                                       errors=1
+                               else
+                                       $ECHO "Passed" >&2
+                               fi
+                               idx=$(($idx+1))
+                       done
+                       if [ $errors -gt 0 ]; then
+                               error "One or more files did not pass the 
validity check!"
+                               exit 1
+                       fi
+               else
+                       warning "The sha1sum program is missing.  Cannot verify 
source files!"
+                       sleep 1
+               fi
+       fi
+}
+
+sources_sha1sum_generate() {
+       if [ ! `type -p sha1sum` ]; then
+               error "Cannot find the sha1sum program."
+               exit 1
+       fi
+       msg "Generating SHA1sums for source files"
+       plain ""
+       ct=0
+       newline=0
+       numsrc=${#source[@]}
+       for netfile in ${source[@]}; do
+               file=$(strip_url $netfile)
+               sum=$(sha1sum $file | cut -d' ' -f 1)
+               if [ $ct -eq 0 ]; then
+                       SHA1SUMS="sha1sums=("
+               else
+                       SHA1SUMS="${SHA1SUMS}"
+               fi
+               SHA1SUMS="${SHA1SUMS}'${sum}'"
+               ct=$(($ct+1))
+               if [ $ct -eq $numsrc ]; then
+                       SHA1SUMS="${SHA1SUMS})"
+               else
+                       # Don't be afraid but \\\n instead of \n coz of the \\ 
a little below
+                       # \\\n would give \n (printed) but \\\\\n will give \
+                       # and a new line carriage '\n' (i.e '\''\n')
+                       SHA1SUMS="${SHA1SUMS} \\\\\n          "
+               fi
+       done
+       $ECHO -e "${SHA1SUMS}"
+       plain ""
+       if [ "${WRITESHA1}" = 1 ]; then
+               cd ${startdir}
+               if [ "`grep -c sha1sums= ${BUILDSCRIPT}`" -gt 1 ]; then
+                       error "${BUILDSCRIPT} contain more than one sha1sums, 
please update manually"
+                       exit 1
+               fi
+               if grep -q sha1sums= ${BUILDSCRIPT}; then
+                       msg "Updating \$sha1sums() in the $BUILDSCRIPT."
+                       # remove the sha1sum lines except the first and
+                       # the last one. hopefully the regexp is complex
+                       # enough that we won't remove something
+                       # unrelated
+                       sed "/\t\? \+'[a-z0-9]\{40\}' \?\\\\/d" -i $BUILDSCRIPT
+                       # doing this in one step causes sed hang. maybe this is 
a sed bug?
+                       sed -e :a -e "\$!N;s/sha1sums=(.*)/MAKEPKG_$$/;ta;P;D" 
-i $BUILDSCRIPT
+                       sed "s/MAKEPKG_$$/$SHA1SUMS/" -i $BUILDSCRIPT
+               else
+                       warning "Initial \$sha1sums() array does not exist, 
Aborting..."
+               fi
+       fi
+       exit 0
+}
+
+sources_gpg_validate() {
+       if [ ${#signatures[@]} -eq ${#source[@]} ]; then
+               if [ `type -p gpg` ]; then
+                       if [ ! -d ~/.gnupg ]; then
+                               msg "Configuring gpg..."
+                               gpg --list-keys
+                               $ECHO "keyserver-options auto-key-retrieve" 
>>~/.gnupg/gpg.conf
+                       fi
+                       if [ -e $startdir/$pkgname.key ]; then
+                               msg "Importing $pkgname.key"
+                               gpg --import $startdir/$pkgname.key
+                       fi
+                       msg "Validating source files with gpg"
+                       errors=0
+                       idx=0
+                       for netfile in "${source[@]}"; do
+                               file=`strip_url "$netfile"`
+                               sig=`strip_url "${signatures[$idx]}"`
+                               $ECHO -n "    $file ... " >&2
+                               if [ ! -z "$sig" ]; then
+                                       echo "$sig" | grep -q "^$file" 
>/dev/null 2>&1
+                                       if [ $? -ne 0 ]; then
+                                               case $file in
+                                                       *.gz)  cmd='zcat'  ;;
+                                                       *.bz2) cmd='bzcat' ;;
+                                                       *.xz)  cmd='xzcat' ;;
+                                               esac
+                                       else
+                                               cmd='cat'
+                                       fi
+                                       $cmd $file | gpg --batch --verify $sig 
- >/dev/null 2>&1
+                                       if [ $? -ne 0 ]; then
+                                               $ECHO "FAILED" >&2
+                                               errors=1
+                                       else
+                                               $ECHO "Passed" >&2
+                                       fi
+                               else
+                                       $ECHO "Skipping" >&2
+                               fi
+                               idx=$(($idx+1))
+                       done
+                       if [ $errors -gt 0 ]; then
+                               error "One or more files did not pass the 
validity check!"
+                               exit 1
+                       fi
+               else
+                       warning "The gpg program is missing.  Cannot verify 
source files!"
+                       sleep 1
+               fi
+       fi
+}
+
buildenv_distcc() {
if [ -d /usr/lib/distcc/bin ]; then
export PATH=/usr/lib/distcc/bin:$PATH
@@ -1515,84 +1651,8 @@ if [ "$GENSHA1" = "0" ]; then
warning "Skipping source extraction       -- using existing src/ tree"
warning "Skipping source integrity checks -- using existing src/ tree"
else
-               # SHA1 validation
-               if [ ${#sha1sums[@]} -eq ${#source[@]} ]; then
-                       if [ `type -p sha1sum` ]; then
-                               msg "Validating source files with SHA1sums"
-                               errors=0
-                               idx=0
-                               for netfile in "${source[@]}"; do
-                                       file=`strip_url "$netfile"`
-                                       $ECHO -n "    $file ... " >&2
-                                       $ECHO "${sha1sums[$idx]}  $file" | 
sha1sum -c - >/dev/null 2>&1
-                                       if [ $? -ne 0 ]; then
-                                               $ECHO "FAILED" >&2
-                                               errors=1
-                                       else
-                                               $ECHO "Passed" >&2
-                                       fi
-                                       idx=$(($idx+1))
-                               done
-                               if [ $errors -gt 0 ]; then
-                                       error "One or more files did not pass 
the validity check!"
-                                       exit 1
-                               fi
-                       else
-                               warning "The sha1sum program is missing.  
Cannot verify source files!"
-                               sleep 1
-                       fi
-               fi
-               # gpg validation
-               if [ ${#signatures[@]} -eq ${#source[@]} ]; then
-                       if [ `type -p gpg` ]; then
-                               if [ ! -d ~/.gnupg ]; then
-                                       msg "Configuring gpg..."
-                                       gpg --list-keys
-                                       $ECHO "keyserver-options 
auto-key-retrieve" >>~/.gnupg/gpg.conf
-                               fi
-                               if [ -e $startdir/$pkgname.key ]; then
-                                       msg "Importing $pkgname.key"
-                                       gpg --import $startdir/$pkgname.key
-                               fi
-                               msg "Validating source files with gpg"
-                               errors=0
-                               idx=0
-                               for netfile in "${source[@]}"; do
-                                       file=`strip_url "$netfile"`
-                                       sig=`strip_url "${signatures[$idx]}"`
-                                       $ECHO -n "    $file ... " >&2
-                                       if [ ! -z "$sig" ]; then
-                                               echo "$sig" | grep -q "^$file" 
>/dev/null 2>&1
-                                               if [ $? -ne 0 ]; then
-                                                       case $file in
-                                                               *.gz)  
cmd='zcat'  ;;
-                                                               *.bz2) 
cmd='bzcat' ;;
-                                                               *.xz)  
cmd='xzcat' ;;
-                                                       esac
-                                               else
-                                                       cmd='cat'
-                                               fi
-                                               $cmd $file | gpg --batch 
--verify $sig - >/dev/null 2>&1
-                                               if [ $? -ne 0 ]; then
-                                                       $ECHO "FAILED" >&2
-                                                       errors=1
-                                               else
-                                                       $ECHO "Passed" >&2
-                                               fi
-                                       else
-                                               $ECHO "Skipping" >&2
-                                       fi
-                                       idx=$(($idx+1))
-                               done
-                               if [ $errors -gt 0 ]; then
-                                       error "One or more files did not pass 
the validity check!"
-                                       exit 1
-                               fi
-                       else
-                               warning "The gpg program is missing.  Cannot 
verify source files!"
-                               sleep 1
-                       fi
-               fi
+               sources_sha1sum_validate
+               sources_gpg_validate

# extract sources
msg "Extracting Sources..."
@@ -1606,57 +1666,7 @@ else
# this condition is always true, but leave it here in case in the
# future we want to add support for other hash algorithms
if [ "$GENSHA1" = "1" ]; then
-               if [ ! `type -p sha1sum` ]; then
-                       error "Cannot find the sha1sum program."
-                       exit 1
-               fi
-               msg "Generating SHA1sums for source files"
-               plain ""
-               ct=0
-               newline=0
-               numsrc=${#source[@]}
-               for netfile in ${source[@]}; do
-                       file=$(strip_url $netfile)
-                       sum=$(sha1sum $file | cut -d' ' -f 1)
-                       if [ $ct -eq 0 ]; then
-                               SHA1SUMS="sha1sums=("
-                       else
-                               SHA1SUMS="${SHA1SUMS}"
-                       fi
-                       SHA1SUMS="${SHA1SUMS}'${sum}'"
-                       ct=$(($ct+1))
-                       if [ $ct -eq $numsrc ]; then
-                               SHA1SUMS="${SHA1SUMS})"
-                       else
-                               # Don't be afraid but \\\n instead of \n coz of 
the \\ a little below
-                               # \\\n would give \n (printed) but \\\\\n will 
give \
-                               # and a new line carriage '\n' (i.e '\''\n')
-                               SHA1SUMS="${SHA1SUMS} \\\\\n          "
-                       fi
-               done
-               $ECHO -e "${SHA1SUMS}"
-               plain ""
-               if [ "${WRITESHA1}" = 1 ]; then
-                       cd ${startdir}
-                       if [ "`grep -c sha1sums= ${BUILDSCRIPT}`" -gt 1 ]; then
-                               error "${BUILDSCRIPT} contain more than one 
sha1sums, please update manually"
-                               exit 1
-                       fi
-                       if grep -q sha1sums= ${BUILDSCRIPT}; then
-                               msg "Updating \$sha1sums() in the $BUILDSCRIPT."
-                               # remove the sha1sum lines except the first and
-                               # the last one. hopefully the regexp is complex
-                               # enough that we won't remove something
-                               # unrelated
-                               sed "/\t\? \+'[a-z0-9]\{40\}' \?\\\\/d" -i 
$BUILDSCRIPT
-                               # doing this in one step causes sed hang. maybe 
this is a sed bug?
-                               sed -e :a -e 
"\$!N;s/sha1sums=(.*)/MAKEPKG_$$/;ta;P;D" -i $BUILDSCRIPT
-                               sed "s/MAKEPKG_$$/$SHA1SUMS/" -i $BUILDSCRIPT
-                       else
-                               warning "Initial \$sha1sums() array does not 
exist, Aborting..."
-                       fi
-               fi
-               exit 0
+               sources_sha1sum_generate
fi
fi
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to