diff --git a/bldpkg b/bldpkg index 2a5c1d0..7c82104 100755 --- a/bldpkg +++ b/bldpkg @@ -20,12 +20,6 @@ ############ # TODO -# -> Find a better way to communicate to the build monitor, by, for example, -# "catting" important build info into a unique build file and then -# the build monitor sources from that file -# -> Fix comments explaining how tmpfs is being validated -# -> Add extra comments about how the build logic switches from tmpfs directory to non-tmpfs -# directory if tmpfs directory validation fails # -> Uncomment entirety of the code where compilers are to be hard-validated and improve C code # in the test files and also add suitable bldpkg.conf switches for it @@ -47,17 +41,32 @@ srcdir="$PWD" # Get relative directory name from SRCDIR srcdirpath="$(basename $srcdir)" +sourcebuildfile() { + file=$1 + if [ -f "$file" ] ; then + source "$file" + elif [ -f "$srcdirpath.SMBuild" ] ; then + source "$srcdirpath.SMBuild" + else + echo "[ERROR] Could not find $srcdirpath build file to source from!" + fi +} + +debugmode() { + set -ex + sourcebuildfile $1 +} + # Generate sha512sums in the build file genchecksum() { - echo "Discarding old sha512sums from $srcdirpath.SMBuild" + echo "[INFO] Discarding old sha512sums from $srcdirpath.SMBuild" sed -E -i \ -e '/^sha512sums=".*"$/d' \ -e '/^sha512sums="/,/"$/d' \ -e "/^sha512sums='.*'\$/d" \ - -e "/^SHA512sums='/,/'\$/d" \ "$srcdirpath".SMBuild - echo "Adding new sha512sums in $srcdirpath.SMBuild..." + echo "[INFO] Adding new sha512sums in $srcdirpath.SMBuild" printf 'sha512sums="\n' >> "$srcdirpath.SMBuild" # File types @@ -73,7 +82,7 @@ genchecksum() { done printf '"' >> "$srcdirpath.SMBuild" - echo "You may now run bldpkg again without any arguments" + echo "[INFO] You may now run bldpkg again" exit 0 } @@ -81,16 +90,24 @@ help() { cat << EOF Bash script for building SMLinux-compatible packages from source. +This script takes only one parameter. Unmatched parameters are ignored. + Usage: -g | g | gen : Generate sha512 checksums of all tarballs and patches and put them into the package build file -h | h | help : Show this message + -d | d | debug : Invoke bash shell debug mode + If no arguments are provided, this script attempts to build a package provided the package build file and the parent directory name matches. EOF exit 0 } +if [ "$#" -gt 1 ] ; then + help +fi + case "$1" in -g|g|gen) genchecksum @@ -98,13 +115,12 @@ case "$1" in -h|h|help) help ;; + -d|d|debug) + debugmode + ;; *) - if [ -f "$srcdirpath.SMBuild" ]; then - source "$srcdirpath.SMBuild" - else - echo "[ERROR] No suitable file found to source and build from." - exit 1 - fi + sourcebuildfile $1 + ;; esac # Validate the build file. If any of the following variables are not set in the build file, abort. @@ -167,7 +183,8 @@ if [ -z "$skipchecksum" ] ; then eval sums=\"\$sha512sums\" - echo "Verifying Checksums..." + echo "[INFO] Verifying SHA512 checksums against source files..." + IFS=$'\n' for src in $sums; do @@ -175,14 +192,17 @@ if [ -z "$skipchecksum" ] ; then done unset IFS - echo "Looks good..." fi # Function to output to the user which patch is about to be applied. Useful when # there are many patches and you want to determine which patch failed. applypatch() { + if [ -z "$1" ]; then + echo "[ERROR] Please provide valid patch file name" + exit 1 + fi relativepath="$(basename $1)" - echo "Applying patch $relativepath.." + echo "[INFO] Applying patch $relativepath.." patch -p1 < "$1" } @@ -197,7 +217,7 @@ fi # Do a preliminary package dependency check if checkdependencies is set to 1 in bldpkg.conf if [ "$checkdependencies" == "1" ] ; then - echo "Parsing $app 's dependency list..." + echo "[INFO] Parsing $app 's dependency list..." for packagedep in "$requires"; do depcount="$(find /share/doc -name $packagedep.SMBuild | wc -l)" # If count is 1, we are ok @@ -758,7 +778,7 @@ preprunitservice() { if [ -f "$srcdir/$1.run" ] ; then cp "$srcdir/$1.run" "etc/service/$1/run" else - echo "$1.run does not exist! Exiting" + echo "[ERROR] $1.run does not exist!" exit 1 fi @@ -938,10 +958,6 @@ mkfinalpkg() { buildfilecleanup() { # Discard all temporary files rm -f "$parenttmp/BUILDING" "$tempfile" - - if [ -z "$autobuild" ] ; then - rm -f "$parenttmp/$app.{app,build,version}" - fi } @@ -1241,7 +1257,8 @@ promptuser() { # This function will set the interrupt variable so prepbuildoutput can output the right build status on receiving # ctrl-c from the user during a manual build. interruptoutput() { - echo "Caught Keyboard Interrupt..." + echo "" + echo "[INFO] Caught Keyboard Interrupt" wasinterrupted="1" # If installprompt and extractprompt are set and the prompt is invoked after a successful build, hitting # ctrl-C will only set the above sm variable repeatedly and won't return user to the shell because