scripts/makepkg.in: Move the remaining stages into functions.
* Move download code to download_sources() * Move checksum generation code to generate_checksums() * Move checksum check code to check_checksums() * Move extract source code to extract_sources() Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
afd2adf1f3
commit
e19d7da4f9
1 changed files with 195 additions and 165 deletions
|
@ -349,6 +349,189 @@ removedeps() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
download_sources() {
|
||||||
|
msg "$(gettext "Retrieving Sources...")"
|
||||||
|
local netfile
|
||||||
|
for netfile in ${source[@]}; do
|
||||||
|
local file=$(strip_url "$netfile")
|
||||||
|
if [ -f "../$file" ]; then
|
||||||
|
msg2 "$(gettext "Found %s in build dir")" "$file"
|
||||||
|
cp "../$file" .
|
||||||
|
continue
|
||||||
|
elif [ -f "$SRCDEST/$file" ]; then
|
||||||
|
msg2 "$(gettext "Using cached copy of %s")" "$file"
|
||||||
|
cp "$SRCDEST/$file" .
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# find the client we should use for this URL
|
||||||
|
local dlclient=$(getdownloadclient $netfile) || exit $?
|
||||||
|
|
||||||
|
msg2 "$(gettext "Downloading %s")" "$file"
|
||||||
|
# fix flyspray bug #3289
|
||||||
|
local ret=0
|
||||||
|
$dlclient "$netfile" || ret=$?
|
||||||
|
if [ $ret -gt 0 ]; then
|
||||||
|
error "$(gettext "Failure while downloading %s")" "$file"
|
||||||
|
msg "$(gettext "Aborting...")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$SRCDEST" ]; then
|
||||||
|
mkdir -p "$SRCDEST" && cp "$file" "$SRCDEST" || ret=$?
|
||||||
|
if [ $ret -gt 0 ]; then
|
||||||
|
warning "$(gettext "You do not have correct permissions to cache source in %s")" "$SRCDEST"
|
||||||
|
cp "$file" ..
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
cp "$file" ..
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_checksums() {
|
||||||
|
msg "$(gettext "Generating checksums for source files...")"
|
||||||
|
plain ""
|
||||||
|
|
||||||
|
local integ
|
||||||
|
for integ in ${INTEGRITY_CHECK[@]}; do
|
||||||
|
integ="$(echo $integ | tr [:upper:] [:lower:])"
|
||||||
|
case "$integ" in
|
||||||
|
md5|sha1|sha256|sha384|sha512) : ;;
|
||||||
|
*)
|
||||||
|
error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
|
||||||
|
exit 1;; # $E_CONFIG_ERROR
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! $(type -p "${integ}sum") ]; then
|
||||||
|
error "$(gettext "Cannot fin the '%s' program.")" "${integ}sum"
|
||||||
|
exit 1 # $E_MISSING_PROGRAM
|
||||||
|
fi
|
||||||
|
|
||||||
|
local ct=0
|
||||||
|
local numsrc=${#source[@]}
|
||||||
|
echo -n "${integ}sums=("
|
||||||
|
|
||||||
|
local i=0;
|
||||||
|
local indent=''
|
||||||
|
while [ $i -lt $((${#integ}+6)) ]; do
|
||||||
|
indent="$indent "
|
||||||
|
i=$(($i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
local netfile
|
||||||
|
for netfile in ${source[@]}; do
|
||||||
|
local file="$(strip_url "$netfile")"
|
||||||
|
local sum="$(${integ}sum "$file" | cut -d ' ' -f 1)"
|
||||||
|
[ $ct -gt 0 ] && echo -n "$indent"
|
||||||
|
echo -n "'$sum'"
|
||||||
|
ct=$(($ct+1))
|
||||||
|
[ $ct -lt $numsrc ] && echo
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ")"
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 0 # $E_OK
|
||||||
|
}
|
||||||
|
|
||||||
|
check_checksums() {
|
||||||
|
local integ
|
||||||
|
for integ in ${INTEGRITY_CHECK[@]}; do
|
||||||
|
integ="$(echo $integ | tr [:upper:] [:lower:])"
|
||||||
|
case "$integ" in
|
||||||
|
md5|sha1|sha256|sha384|sha512) : ;;
|
||||||
|
*)
|
||||||
|
error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ"
|
||||||
|
exit 1;; # $E_CONFIG_ERROR
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! $(type -p "${integ}sum") ]; then
|
||||||
|
error "$(gettext "Cannot find the %s program.")" "${integ}sum"
|
||||||
|
exit 1 # $E_MISSING_PROGRAM
|
||||||
|
fi
|
||||||
|
|
||||||
|
local integrity_sums=($(eval echo \${${integ}sums[@]}))
|
||||||
|
if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
|
||||||
|
msg "$(gettext "Validating source files with %s")" "${integ}sums"
|
||||||
|
local errors=0
|
||||||
|
local idx=0
|
||||||
|
local file
|
||||||
|
for file in "${source[@]}"; do
|
||||||
|
file="$(strip_url "$file")"
|
||||||
|
echo -n " $file ... " >&2
|
||||||
|
|
||||||
|
if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c - &>/dev/null; then
|
||||||
|
echo "$(gettext "Passed")" >&2
|
||||||
|
else
|
||||||
|
echo "$(gettext "FAILED")" >&2
|
||||||
|
errors=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
idx=$(($idx+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $errors -gt 0 ]; then
|
||||||
|
error "$(gettext "One or more files did not pass the validity check!")"
|
||||||
|
exit 1 # TODO: error code
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
extract_sources() {
|
||||||
|
msg "$(gettext "Extracting Sources...")"
|
||||||
|
local netfile
|
||||||
|
for netfile in "${source[@]}"; do
|
||||||
|
unziphack=0
|
||||||
|
file=$(strip_url "$netfile")
|
||||||
|
if in_array "$file" ${noextract[@]}; then
|
||||||
|
#skip source files in the noextract=() array
|
||||||
|
# these are marked explicitly to NOT be extracted
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# fix flyspray #6246
|
||||||
|
local file_type=$(file -biz "$file")
|
||||||
|
local cmd=''
|
||||||
|
case "$file_type" in
|
||||||
|
*application/x-tar*application/x-compress*)
|
||||||
|
cmd="tar -xzf $file" ;;
|
||||||
|
*application/x-tar*)
|
||||||
|
cmd="tar -xf $file" ;;
|
||||||
|
*application/x-zip*)
|
||||||
|
unziphack=1
|
||||||
|
cmd="unzip -qqo $file" ;;
|
||||||
|
*application/x-cpio*)
|
||||||
|
cmd="bsdtar -x -f $file" ;;
|
||||||
|
*application/x-gzip*)
|
||||||
|
cmd="gunzip -d -f $file" ;;
|
||||||
|
*application/x-bzip*)
|
||||||
|
cmd="bunzip2 -f $file" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$cmd" != "" ]; then
|
||||||
|
msg2 "$cmd"
|
||||||
|
$cmd
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
# unzip will return a 1 as a warning, it is not an error
|
||||||
|
if [ "$unziphack" != "1" -o $? -ne 1 ]; then
|
||||||
|
error "$(gettext "Failed to extract %s")" "$file"
|
||||||
|
msg "$(gettext "Aborting...")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $EUID -eq 0 ]; then
|
||||||
|
# chown all source files to root.root
|
||||||
|
chown -R root.root "$srcdir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
run_build() {
|
run_build() {
|
||||||
# use distcc if it is requested (check buildenv and PKGBUILD opts)
|
# use distcc if it is requested (check buildenv and PKGBUILD opts)
|
||||||
if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
|
if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
|
||||||
|
@ -1035,177 +1218,24 @@ cd "$srcdir"
|
||||||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||||
warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
|
warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
|
||||||
else
|
else
|
||||||
msg "$(gettext "Retrieving Sources...")"
|
download_sources
|
||||||
for netfile in ${source[@]}; do
|
|
||||||
file=$(strip_url "$netfile")
|
|
||||||
if [ -f "../$file" ]; then
|
|
||||||
msg2 "$(gettext "Found %s in build dir")" "$file"
|
|
||||||
cp "../$file" .
|
|
||||||
continue
|
|
||||||
elif [ -f "$SRCDEST/$file" ]; then
|
|
||||||
msg2 "$(gettext "Using cached copy of %s")" "$file"
|
|
||||||
cp "$SRCDEST/$file" .
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# find the client we should use for this URL
|
|
||||||
dlclient=$(getdownloadclient $netfile) || exit $?
|
|
||||||
|
|
||||||
msg2 "$(gettext "Downloading %s")" "$file"
|
|
||||||
# fix flyspray bug #3289
|
|
||||||
ret=0
|
|
||||||
$dlclient "$netfile" || ret=$?
|
|
||||||
if [ $ret -gt 0 ]; then
|
|
||||||
error "$(gettext "Failure while downloading %s")" "$file"
|
|
||||||
msg "$(gettext "Aborting...")"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$SRCDEST" ]; then
|
|
||||||
mkdir -p "$SRCDEST" && cp "$file" "$SRCDEST" || ret=$?
|
|
||||||
if [ $ret -gt 0 ]; then
|
|
||||||
warning "$(gettext "You do not have correct permissions to cache source in %s")" "$SRCDEST"
|
|
||||||
cp "$file" ..
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
cp "$file" ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
unset netfile file dlclient ret
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$GENINTEG" = "1" ]; then
|
if [ "$GENINTEG" = "1" ]; then
|
||||||
msg "$(gettext "Generating checksums for source files...")"
|
generate_checksums
|
||||||
plain ""
|
|
||||||
|
|
||||||
for integ in ${INTEGRITY_CHECK[@]}; do
|
|
||||||
integ="$(echo $integ | tr [:upper:] [:lower:])"
|
|
||||||
case "$integ" in
|
|
||||||
md5|sha1|sha256|sha384|sha512) : ;;
|
|
||||||
*) error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"; exit 1;; # $E_CONFIG_ERROR
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ ! $(type -p "${integ}sum") ]; then
|
|
||||||
error "$(gettext "Cannot fin the '%s' program.")" "${integ}sum"
|
|
||||||
exit 1 # $E_MISSING_PROGRAM
|
|
||||||
fi
|
|
||||||
|
|
||||||
ct=0
|
|
||||||
numsrc=${#source[@]}
|
|
||||||
echo -n "${integ}sums=("
|
|
||||||
i=0; indent=''
|
|
||||||
while [ $i -lt $((${#integ}+6)) ]; do
|
|
||||||
indent="$indent "
|
|
||||||
i=$(($i+1))
|
|
||||||
done
|
|
||||||
|
|
||||||
for netfile in ${source[@]}; do
|
|
||||||
file="$(strip_url "$netfile")"
|
|
||||||
sum="$(${integ}sum "$file" | cut -d ' ' -f 1)"
|
|
||||||
[ $ct -gt 0 ] && echo -n "$indent"
|
|
||||||
echo -n "'$sum'"
|
|
||||||
ct=$(($ct+1))
|
|
||||||
[ $ct -lt $numsrc ] && echo
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ")"
|
|
||||||
done
|
|
||||||
|
|
||||||
exit 0 # $E_OK
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||||
warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
|
warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
|
||||||
else
|
else
|
||||||
for integ in ${INTEGRITY_CHECK[@]}; do
|
check_checksums
|
||||||
integ="$(echo $integ | tr [:upper:] [:lower:])"
|
|
||||||
case "$integ" in
|
|
||||||
md5|sha1|sha256|sha384|sha512) : ;;
|
|
||||||
*) error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ"; exit 1;; # $E_CONFIG_ERROR
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ ! $(type -p "${integ}sum") ]; then
|
|
||||||
error "$(gettext "Cannot find the %s program.")" "${integ}sum"
|
|
||||||
exit 1 # $E_MISSING_PROGRAM
|
|
||||||
fi
|
|
||||||
|
|
||||||
integrity_sums=($(eval echo \${${integ}sums[@]}))
|
|
||||||
if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
|
|
||||||
msg "$(gettext "Validating source files with %s")" "${integ}sums"
|
|
||||||
errors=0
|
|
||||||
idx=0
|
|
||||||
for file in "${source[@]}"; do
|
|
||||||
file="$(strip_url "$file")"
|
|
||||||
echo -n " $file ... " >&2
|
|
||||||
if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c - &>/dev/null; then
|
|
||||||
echo "$(gettext "Passed")" >&2
|
|
||||||
else
|
|
||||||
echo "$(gettext "FAILED")" >&2
|
|
||||||
errors=1
|
|
||||||
fi
|
|
||||||
idx=$(($idx+1))
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $errors -gt 0 ]; then
|
|
||||||
error "$(gettext "One or more files did not pass the validity check!")"
|
|
||||||
exit 1 # TODO: error code
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
unset integ integrity_sums errors idx file
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Extract sources
|
#Extract sources
|
||||||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||||
warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
|
warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
|
||||||
else
|
else
|
||||||
msg "$(gettext "Extracting Sources...")"
|
extract_sources
|
||||||
for netfile in "${source[@]}"; do
|
|
||||||
unziphack=0
|
|
||||||
file=$(strip_url "$netfile")
|
|
||||||
if in_array "$file" ${noextract[@]}; then
|
|
||||||
#skip source files in the noextract=() array
|
|
||||||
# these are marked explicitly to NOT be extracted
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# fix flyspray #6246
|
|
||||||
file_type=$(file -biz "$file")
|
|
||||||
unset cmd
|
|
||||||
case "$file_type" in
|
|
||||||
*application/x-tar*application/x-compress*)
|
|
||||||
cmd="tar -xzf $file" ;;
|
|
||||||
*application/x-tar*)
|
|
||||||
cmd="tar -xf $file" ;;
|
|
||||||
*application/x-zip*)
|
|
||||||
unziphack=1
|
|
||||||
cmd="unzip -qqo $file" ;;
|
|
||||||
*application/x-cpio*)
|
|
||||||
cmd="bsdtar -x -f $file" ;;
|
|
||||||
*application/x-gzip*)
|
|
||||||
cmd="gunzip -d -f $file" ;;
|
|
||||||
*application/x-bzip*)
|
|
||||||
cmd="bunzip2 -f $file" ;;
|
|
||||||
esac
|
|
||||||
if [ "$cmd" != "" ]; then
|
|
||||||
msg2 "$cmd"
|
|
||||||
$cmd
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
# unzip will return a 1 as a warning, it is not an error
|
|
||||||
if [ "$unziphack" != "1" -o $? -ne 1 ]; then
|
|
||||||
error "$(gettext "Failed to extract %s")" "$file"
|
|
||||||
msg "$(gettext "Aborting...")"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $EUID -eq 0 ]; then
|
|
||||||
# chown all source files to root.root
|
|
||||||
chown -R root.root "$srcdir"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$NOBUILD" = "1" ]; then
|
if [ "$NOBUILD" = "1" ]; then
|
||||||
|
|
Loading…
Add table
Reference in a new issue