Changes to bldpkg:

-> Added -r option in getopts to provide functionality to resume a build after the source
   has been deemed to be extracted completely inside the build directory
-> Fixed detection of stale directories in tmpfs directory
-> Fixed if/else of setbuildfile variable
-> Temporarily commented grepping of download= variable
-> Restored set -e
-> Temporarily added ignoreusr variable as a workaround for packages that forcefully create /usr
This commit is contained in:
PktSurf 2023-03-13 00:49:23 +05:30
parent 03b8e2675c
commit 89420776a8

79
bldpkg
View file

@ -5,7 +5,7 @@
#
# Bash script to build SMLinux-specific packages
#
# Copyright (c) 2022 PktSurf <smlinux@pktsurf.in>
# Copyright (c) 2022-2023 PktSurf <smlinux@pktsurf.in>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -25,6 +25,8 @@
# -> Email the user about the outcome of the build?
# -> Increment warnings as they are issued during the build and show final warning total in the build summary
set -e
err() {
printf "**ERROR**\n$@\n"
exit 1
@ -54,7 +56,7 @@ help() {
cat << EOF
Bash script for building SMLinux-compatible packages from source.
Any option used as an argument with this script overrides the
corresponding option, if present, in /etc/bldpkg.conf or "'$HOME/.bldpkg.conf'"
corresponding option, if present, in /etc/bldpkg.conf or '$HOME/.bldpkg.conf'
If no arguments are provided, this script attempts to first look for
a build file with a .SMBuild extension that matches the name of
@ -97,6 +99,11 @@ Usage:
exceptional cases a different file is required to be copied into the
package installer. Do note that this file will also undergo validation
-r Resume the build by skipping all commands in prepbuilddir and execute
build() function. Presumes that the package was completely extracted
in the build directory, and patches, if any, were applied and executes
stuff inside build().
-s Display build summary. A summary is produced whenever a build is either
interrupted, exits cleanly or aborts due to a build error
@ -133,32 +140,36 @@ validatebldfile() {
fi
# Validate $app
if ! grep -E -q 'app=[a-z0-9-]' "$buildfile" ; then
if ! grep -E -q '^app=[a-z0-9-]' "$buildfile" ; then
err "Only lower case, numeric characters and dash allowed in the 'app' variable in the build file."
# Validate $version
elif ! grep -E -q 'version=[a-z0-9.]' "$buildfile" ; then
elif ! grep -E -q '^version=[a-z0-9.]' "$buildfile" ; then
err "Only lower case, numeric characters and a period allowed in the 'version' variable in the build file."
# Validate $homepage
elif ! grep -E -q 'homepage="\(http|https|ftp)://' "$buildfile" ; then
elif ! grep -E -q '^homepage="\(https|http||ftp)://' "$buildfile" ; then
err "Invalid URL in the 'homepage' variable in the build file."
# Validate $download, first the URL type
elif grep -E -q 'download=' "$buildfile" ; then
if ! grep -E -q 'download="\(http|https|ftp)://' "$buildfile" ; then
err "Invalid URL in the 'download' variable in the build file."
fi
#elif grep -E -q '^download=' "$buildfile" ; then
# if ! grep -E -q '^download="\(http|https|ftp)://' "$buildfile" ; then
# err "Invalid URL in the 'download' variable in the build file."
# fi
# Then check for single quotes
if grep -E -q "download='*'" "$buildfile" ; then
err "Single quotes disallowed in the 'download' variable in the build file"
fi
# if grep -E -q "^download='*'" "$buildfile" ; then
# err "Single quotes disallowed in the 'download' variable in the build file"
# fi
# Validate $desc using bash shell's ability to count variable length
elif [[ ${#desc} -gt 100 ]] ; then
err "Package description should not exceed 100 characters in the build file."
# Check if prepbuilddir() function exists in the build file
elif ! grep -q '^prepbuilddir() {' "$buildfile" ; then
err "'prepbuilddir()' function does not exist in your build file."
# Check if build() function exists in the build file
elif ! grep -q '^build() {' "$buildfile" ; then
err "'build()' function does not exist in your build file."
@ -183,7 +194,7 @@ for requiredfile in "${rqfiles[@]}"; do
done
# Function for providing handy arguments to users. Some will override bldpkg.conf.
while getopts ':def:ghj:o:svx' option; do
while getopts ':def:ghj:o:rsvx' option; do
case "$option" in
d) debug=1 ;; # Produce a debug build with -g3
e) extractprompt=0;
@ -193,6 +204,7 @@ while getopts ':def:ghj:o:svx' option; do
h) help ;;
j) customcputhreads="$OPTARG" ;;
o) origbuildfile="$OPTARG" ;;
r) resumepkgbuild=1 ;;
s) showsummary=1 ;; # Show build summary at the end of the build irrespective of the build status
v) getoptscompilerverbosity=1 ;;
x) set -xv ;; # Invoke bash's -x option for command tracing
@ -246,9 +258,10 @@ elif [[ $OPTIND -gt 1 ]] ; then
elif ! validatebldfile "$origbuildfile" ; then
err "Alternative build file validation failed!"
fi
fi
# If $setbuildfile is set and is a file, set buildfile to its value, source it and initialise the build
elif [[ -n $setbuildfile ]] && [[ -f $setbuildfile ]] ; then
if [[ -n $setbuildfile ]] && [[ -f $setbuildfile ]] ; then
buildfile="$setbuildfile"
if ! validatebldfile "$buildfile" ; then
err "'$buildfile' validation failed!"
@ -505,11 +518,10 @@ if [[ $usetmpfs = 1 ]] && [[ -n $tmpfsdir ]]; then
# Discard the file used to test the tmp directory
[[ -e "$tmpfsdir/.smlinuxtmpwritetest" ]] && rm "$tmpfsdir/.smlinuxtmpwritetest"
# Check the tmpfsdir for stale directories other than the current package about to be built. If found, issue a warning.
if [[ $(find "$tmpfsdir" -type d -maxdepth 1 | wc -l) -gt 1 ]]; then
if [[ ! -d $app.src ]] || [[ ! -d package-$app ]] ; then
# Check the tmpfsdir for stale directories from previous builds. If found, issue a warning.
if [[ $(find "$tmpfsdir" -type d -maxdepth 1 -name "*.src" -o -name "package-*" | wc -l) -gt 0 ]]; then
if [[ ! -d $tmpfsdir/package-$app ]] || [[ ! -d $tmpfsdir/$app.src ]] ; then
warn "TMPFS directory '$tmpfsdir' has stale directories from previous builds!"
#sleep 5
fi
fi
fi
@ -884,6 +896,7 @@ fixbuilddirpermissions() {
chown -R root.root .
find -L . -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
\! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+ || true
touch ".$app.extraction.complete"
}
# Function to calculate elapsed build time. runtime takes the $SECONDS variable as an argument. $SECONDS is an
@ -976,10 +989,14 @@ Please fix the build options and ensure the /lib64 is not created."
fi
# Check if /usr and /sbin were created inside $pkg only if allowusrdir=1 is not set in the package build file
# For a package that stubbornly insists on having its stuff installed in /usr , add 'ignoreusr=1' at the top
# of its build file
for directory in usr sbin ; do
if [[ -d $pkg/$directory ]] ; then
err "'$app' has '$directory' directory which is a symlink to /bin on SMLinux.
if [[ -z "$ignoreusr" ]] ; then
err "'$app' has '$directory' directory which is a symlink to /bin on SMLinux.
Please fix the build options and ensure '$directory' is not created."
fi
fi
done
@ -1107,10 +1124,11 @@ Moving its contents into share/doc/$app-$version/"
# If $disablepkgsymlinks is not set in the package build file, change any symlinks into shell script code. An example is base/initfs wherein
# we only want the doinst.sh file in the source directory to be copied, not manipulated.
if [[ -z $disablepkgsymlinks ]] ; then
if find . -type l | grep -qm1 .; then
info "Found symlinks, preparing install/doinst.sh..."
find . -type l -printf '( cd %h ; rm -f %f )\n( cd %h ; ln -sf %l %f )\n' -delete > install/symlinks
find . -type l -printf '( cd %h ; rm -rf %f )\n( cd %h ; ln -sf %l %f )\n' -delete > install/symlinks
if [[ -f install/doinst.sh ]]; then
printf '\n' | cat - install/doinst.sh >> install/symlinks
fi
@ -1502,6 +1520,27 @@ interruptoutput() {
trap "prepbuildoutput" EXIT
trap "interruptoutput" INT
# If $resumepkgbuild variable is not set in getopts, only then execute prepbuilddir variable
if [[ -z $resumepkgbuild ]] ; then
prepbuilddir
fi
# If $resumepkgbuild is set, execute mkandenterbuilddir function to enter the build directory
# This is being done because mkandenterbuilddir is part of prepbuilddir function in the build
# file and ignoring prepbuilddir will not cause mkandenterbuilddir to be invoked separately unless the build
# system is told to.
if [[ -n $resumepkgbuild ]] ; then
mkandenterbuilddir
buildresumepath="$(find $tmp -type f -name .$app.extraction.complete)"
# fixbuilddirpermissions places a file ".$app.extraction.complete". Get the directory name that houses that file
# and cd into it
if [[ ! -f $buildresumepath ]] ; then
err "Can't resume build of '"$app"'! Are you certain the source was extracted completely?"
else
cd $(dirname $buildresumepath)
fi
fi
build
# End script