Allow URLs in source entries.
Provide helpers to abstract extraction of source paths and filenames. Cleanup all direct uses of source[] to use the helpers. Add new fetch_source function to handle URLs. Depends on new __curl define. Small unrelated change in buildpkg.packaging.irix, we must use gsed to get \n expanded in the strings.
This commit is contained in:
parent
b27fef0e1b
commit
6dfdcc73c4
@ -165,6 +165,7 @@ E_BAD_VERSION=46
|
||||
E_BAD_LIBS=47
|
||||
E_SVR4_PKG_OVERFLOW=48
|
||||
E_SVR4_NAME_OVERFLOW=49
|
||||
E_MISSING_EXE=50
|
||||
|
||||
error_txt[$E_BAD_FILE]="File not found"
|
||||
error_txt[$E_PATCH_FAILED]="Patch failed"
|
||||
@ -183,6 +184,7 @@ error_txt[$E_BAD_VERSION]="Version field overflow"
|
||||
error_txt[$E_BAD_LIBS]="config.log defines obsolete libraries!"
|
||||
error_txt[$E_SVR4_PKG_OVERFLOW]="PKG field exceeds 9 char limit"
|
||||
error_txt[$E_SVR4_NAME_OVERFLOW]="NAME field exceeds 256 char limit"
|
||||
error_txt[$E_MISSING_EXE]="Executable is missing"
|
||||
|
||||
#####################################################
|
||||
# Helper functions
|
||||
@ -263,6 +265,91 @@ patch()
|
||||
fi
|
||||
}
|
||||
|
||||
# get_source_filename(): Find filename for given sourceid
|
||||
# params: $1 = source number (arrayindex)
|
||||
get_source_filename()
|
||||
{
|
||||
local snum=$1
|
||||
local file="${source[$snum]##*/}" # Extract filename part
|
||||
|
||||
if [ -z "$file" ]; then
|
||||
error $E_BAD_FILE get_source_filename
|
||||
else
|
||||
echo $file
|
||||
fi
|
||||
}
|
||||
|
||||
# get_source_path(): Find local path for given sourceid
|
||||
# params: $1 = source number (arrayindex)
|
||||
get_source_path()
|
||||
{
|
||||
local snum=$1
|
||||
local path_return=""
|
||||
local path="${source[$snum]%/*}" # Extract path part
|
||||
local file=$(get_source_filename $snum) # Extract filename part
|
||||
|
||||
if [ -n "$path" ]; then
|
||||
# We have a path component, could be relative, url or abs path
|
||||
if [ "${path:0:1}" != "/" ]; then
|
||||
# path is relative or contains an url
|
||||
# If path contains an url
|
||||
if [ -n "$(echo $path | grep '://')" ]; then
|
||||
# let empty $path code handle it
|
||||
path=""
|
||||
else
|
||||
# Not an url
|
||||
[ -r "$srcdir/$file" ] && path_return="$srcdir"
|
||||
[ -r "$srcfiles/$file" ] && path_return="$srcfiles"
|
||||
fi
|
||||
else # abs path
|
||||
path_return=$path
|
||||
fi
|
||||
fi
|
||||
# No path given
|
||||
if [ -z "$path" ]; then
|
||||
[ -r "$srcdir/$file" ] && path_return="$srcdir"
|
||||
[ -r "$srcfiles/$file" ] && path_return="$srcfiles"
|
||||
fi
|
||||
|
||||
[ -z "$path_return" ] && path_return="$srcfiles" # Best guess
|
||||
|
||||
echo $path_return
|
||||
}
|
||||
|
||||
# get_source_absfilename(): Wrapper for get_source_filename and get_source_path
|
||||
# params: $1 = source number (arrayindex)
|
||||
# Note this wrapper will exit with $E_BAD_FILE if the absolute filename is not
|
||||
# readable
|
||||
get_source_absfilename()
|
||||
{
|
||||
local snum=$1
|
||||
local absfilename="$(get_source_path $snum)/$(get_source_filename $1)"
|
||||
if [ -r "$absfilename" ]; then
|
||||
echo "$absfilename"
|
||||
else
|
||||
# File is not readable
|
||||
error $E_BAD_FILE get_source_absfilename
|
||||
fi
|
||||
}
|
||||
|
||||
# fetch_source(): Fetch a sourcefile from an url
|
||||
# params: $1 = source number (arrayindex)
|
||||
fetch_source()
|
||||
{
|
||||
local snum=$1
|
||||
local file=$(get_source_filename $snum)
|
||||
local path=$(get_source_path $snum)
|
||||
|
||||
if [ ! -r "$path/$file" ]; then
|
||||
echo "fetch_source: Downloading ${source[$snum]}"
|
||||
if [ -x ${__curl} ]; then
|
||||
${__curl} -# -L --retry 2 -C - -o $srcfiles/$file "${source[$snum]}"
|
||||
else
|
||||
error $E_MISSING_EXE fetch_source
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# unpack(): Unpack source
|
||||
# params: $1 = source number (arrayindex)
|
||||
# It will detect filetype and unpack
|
||||
@ -270,34 +357,38 @@ patch()
|
||||
unpack()
|
||||
{
|
||||
local snum=$1
|
||||
local filename
|
||||
local suffix
|
||||
local absfile
|
||||
|
||||
setdir $srcdir
|
||||
if [ "${source[$snum]:0:1}" != "/" ]; then # We have a relative pathname
|
||||
# expand to absolute
|
||||
source[$snum]=$srcfiles/${source[$snum]}
|
||||
fi # We are now sure that ${source[$snum]} contains file with absolute path
|
||||
echo "Unpacking ${source[$snum]}"
|
||||
if [ -r ${source[$snum]} ]; then # file is readable
|
||||
local absfilename=${source[$snum]}
|
||||
local filename=${absfilename##/*/} # Strip down to the filename
|
||||
local suffix=${filename##*.} # Strip down to filename suffix (strip down to the last .)
|
||||
|
||||
# If source contains an URL then first
|
||||
# download the file to $srcfiles
|
||||
if [ -n "$(echo ${source[$snum]} | grep '://')" ]; then
|
||||
# Yep it's an url
|
||||
fetch_source $snum
|
||||
fi
|
||||
|
||||
filename="$(get_source_filename $snum)"
|
||||
suffix=${filename##*.} # Strip down to filename suffix (strip down to the last .)
|
||||
echo "Unpacking $filename"
|
||||
# Note observe order here, since get_source_absfilename can exit with $E_BAD_FILE this
|
||||
# provides context for resolving!
|
||||
absfile="$(get_source_absfilename $snum)"
|
||||
# Determine filetype and unpack
|
||||
case $suffix in
|
||||
'tar') ${__tar} -xf ${source[$snum]};;
|
||||
'gz') ${__gzip} -dc ${source[$snum]} | ${__tar} -xf -;;
|
||||
'bz2') ${__bzip2} -dc ${source[$snum]} | ${__tar} -xf -;;
|
||||
'Z') ${__gzip} -dc ${source[$snum]} | ${__tar} -xf -;;
|
||||
'tgz') ${__gzip} -dc ${source[$snum]} | ${__tar} -xf -;;
|
||||
'zip') ${__unzip} -q ${source[$snum]};;
|
||||
'tar') ${__tar} -xf $absfile;;
|
||||
'gz') ${__gzip} -dc $absfile | ${__tar} -xf -;;
|
||||
'bz2') ${__bzip2} -dc $abfile | ${__tar} -xf -;;
|
||||
'Z') ${__gzip} -dc $absfile | ${__tar} -xf -;;
|
||||
'tgz') ${__gzip} -dc $absfile | ${__tar} -xf -;;
|
||||
'zip') ${__unzip} -q $absfile;;
|
||||
*) error $E_BAD_COMPRESS unpack
|
||||
esac
|
||||
if [ $? -ne 0 ]; then
|
||||
error $E_BAD_UNPACK unpack
|
||||
fi
|
||||
else
|
||||
error $E_BAD_FILE unpack
|
||||
fi
|
||||
}
|
||||
|
||||
# clean(): Scrub build environment
|
||||
|
@ -979,14 +979,8 @@ auto_src()
|
||||
local snum=0
|
||||
for ((snum=0; $snum < $numsource; snum++))
|
||||
do
|
||||
if [ "${source[$snum]:0:1}" != "/" ]; then # We have a relative pathname
|
||||
# expand to absolute
|
||||
source[$snum]=$srcfiles/${source[$snum]}
|
||||
fi # We are now sure that ${source[$snum]} contains file with absolute path
|
||||
if [ -r ${source[$snum]} ]; then
|
||||
echo "Copying source[$snum] - ${source[$snum]}"
|
||||
${__cp} ${source[$snum]} $distsrcdir
|
||||
fi
|
||||
local absfile=$(get_source_absfilename $snum)
|
||||
${__cp} $absfilename $distsrcdir
|
||||
done
|
||||
fi
|
||||
}
|
||||
@ -1075,23 +1069,15 @@ auto_rel()
|
||||
local vendor=$(_upls ${vendor_temp#pkgvendor=*})
|
||||
local packager="${pkgedby} <${email}>"
|
||||
# Compute SHA1 sums for all source entries
|
||||
local s
|
||||
local snum
|
||||
local path
|
||||
local file
|
||||
local source_sha1sum
|
||||
local temp_source_sha1sum=""
|
||||
for ((s=0; $s < ${#source[@]}; s++))
|
||||
for ((snum=0; $snum < ${#source[@]}; snum++))
|
||||
do
|
||||
# A little snip from buildpkg.functions:unpack
|
||||
if [ "${source[$s]:0:1}" != "/" ]; then # We have a relative pathname
|
||||
# expand to absolute
|
||||
[ -r "$srcdir/${source[$s]}" ] && source[$s]="$srcdir/${source[$s]}"
|
||||
[ -r "$srcfiles/${source[$s]}" ] && source[$s]="$srcfiles/${source[$s]}"
|
||||
fi # We are now sure that ${source[$s]} contains file with absolute path
|
||||
# To avoid recording an absolute path in the sha1sum output that gets inserted
|
||||
# into relnotes we cd first then run sha1sum
|
||||
path="${source[$s]%/*}" # Extract path part
|
||||
file="${source[$s]##*/}" # Extract filename part
|
||||
path="$(get_source_path $snum)"
|
||||
file="$(get_source_filename $snum)"
|
||||
(cd "$path"; ${__sha1sum} "$file") >> $metadir/sums
|
||||
done
|
||||
[ -r "$metadir/sums" ] && temp_source_sha1sum="$(cat $metadir/sums | ${__awk} '{ printf "%s\\n",$0 }')"
|
||||
@ -1107,7 +1093,7 @@ auto_rel()
|
||||
fi
|
||||
local deps="${temp_deps%\\*}"
|
||||
${__mkdir} -p $relmetadir
|
||||
${__sed} -e "s;%%PKGNAME%%;${pkgnam};g" \
|
||||
${__gsed} -e "s;%%PKGNAME%%;${pkgnam};g" \
|
||||
-e "s;%%SOURCE_AND_VER%%;${topdir}-${version};g" \
|
||||
-e "s;%%CONFIGURE%%;${fullcf};g" \
|
||||
-e "s;%%COMPILER%%;${compiler};g" \
|
||||
|
@ -393,22 +393,14 @@ auto_rel()
|
||||
local source_sha1sum
|
||||
local temp_source_sha1sum=""
|
||||
# older bash 2.x doesn't like C-style for loops (observed on Solaris 2.x)
|
||||
#for ((s=0; $s < ${#source[@]}; s++))
|
||||
local s=0
|
||||
while [ $s -lt ${#source[@]} ]
|
||||
#for ((snum=0; $snum < ${#source[@]}; s++))
|
||||
local snum=0
|
||||
while [ $snum -lt ${#source[@]} ]
|
||||
do
|
||||
# A little snip from buildpkg.functions:unpack
|
||||
if [ "${source[$s]:0:1}" != "/" ]; then # We have a relative pathname
|
||||
# expand to absolute
|
||||
[ -r "$srcdir/${source[$s]}" ] && source[$s]="$srcdir/${source[$s]}"
|
||||
[ -r "$srcfiles/${source[$s]}" ] && source[$s]="$srcfiles/${source[$s]}"
|
||||
fi # We are now sure that ${source[$s]} contains file with absolute path
|
||||
# To avoid recording an absolute path in the sha1sum output that gets inserted
|
||||
# into relnotes we cd first then run sha1sum
|
||||
path="${source[$s]%/*}" # Extract path part
|
||||
file="${source[$s]##*/}" # Extract filename part
|
||||
(cd "$path"; ${__sha1sum} "$file") >> $metadir/sums.${secname}
|
||||
let s=s+1
|
||||
path="$(get_source_path $snum)"
|
||||
file="$(get_source_filename $snum)"
|
||||
(cd "$path"; ${__sha1sum} "$file") >> $metadir/sums
|
||||
let snum=snum+1
|
||||
done
|
||||
[ -r "$metadir/sums.${secname}" ] && temp_source_sha1sum="$(cat $metadir/sums.${secname} | ${__awk} '{ printf "%s\\n",$0 }')"
|
||||
source_sha1sum="${temp_source_sha1sum%\\*}"
|
||||
|
@ -45,6 +45,7 @@ __head=/usr/bin/head # Must support -n
|
||||
__perl=/usr/tgcware/bin/perl
|
||||
__readlink=/usr/tgcware/bin/readlink
|
||||
__ldd=/usr/bin/ldd
|
||||
__curl=/usr/tgcware/bin/curl
|
||||
|
||||
# Groff stuff for manpages
|
||||
__nroff=/usr/tgcware/bin/nroff
|
||||
|
Loading…
x
Reference in New Issue
Block a user