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
|
@ -349,6 +349,189 @@ removedeps() {
|
|||
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() {
|
||||
# use distcc if it is requested (check buildenv and PKGBUILD opts)
|
||||
if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
|
||||
|
@ -730,13 +913,13 @@ SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
|
|||
|
||||
# Only use ABSROOT if we haven't been passed a SRCROOT on the command line.
|
||||
if [ -z "$SRCROOT" ]; then
|
||||
if [ -r "$confdir/abs/abs.conf" ]; then
|
||||
source "$confdir/abs/abs.conf"
|
||||
fi
|
||||
if [ -r ~/.abs.conf ]; then
|
||||
source ~/.abs.conf
|
||||
fi
|
||||
SRCROOT=$ABSROOT
|
||||
if [ -r "$confdir/abs/abs.conf" ]; then
|
||||
source "$confdir/abs/abs.conf"
|
||||
fi
|
||||
if [ -r ~/.abs.conf ]; then
|
||||
source ~/.abs.conf
|
||||
fi
|
||||
SRCROOT=$ABSROOT
|
||||
fi
|
||||
|
||||
while [ "$#" -ne "0" ]; do
|
||||
|
@ -886,7 +1069,7 @@ fi
|
|||
|
||||
# check for sudo if we will need it during makepkg execution
|
||||
if [ "$ASROOT" = "0" -a \( "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" \
|
||||
-o "$RMDEPS" = "1" -o "$INSTALL" = "1" \) ]; then
|
||||
-o "$RMDEPS" = "1" -o "$INSTALL" = "1" \) ]; then
|
||||
if [ ! "$(type -p sudo)" ]; then
|
||||
error "$(gettext "Cannot find the sudo binary! Is sudo installed?")"
|
||||
plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")"
|
||||
|
@ -1035,177 +1218,24 @@ cd "$srcdir"
|
|||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||
warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
|
||||
else
|
||||
msg "$(gettext "Retrieving 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
|
||||
download_sources
|
||||
fi
|
||||
|
||||
if [ "$GENINTEG" = "1" ]; then
|
||||
msg "$(gettext "Generating checksums for source files...")"
|
||||
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
|
||||
generate_checksums
|
||||
fi
|
||||
|
||||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||
warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
|
||||
else
|
||||
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
|
||||
|
||||
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
|
||||
check_checksums
|
||||
fi
|
||||
|
||||
#Extract sources
|
||||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||
warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
|
||||
else
|
||||
msg "$(gettext "Extracting 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
|
||||
extract_sources
|
||||
fi
|
||||
|
||||
if [ "$NOBUILD" = "1" ]; then
|
||||
|
|
Loading…
Reference in New Issue