diff --git a/makedeb b/makedeb index 2a5fc6d..ad35667 100755 --- a/makedeb +++ b/makedeb @@ -8,7 +8,8 @@ pkgdir="${workspace}/pkg" FAKE_PACKAGE=0 OVERRIDE_SOURCE=0 - +SHOW_TARGET_FILE=0 +QUIET=0 set -o functrace set -o nounset @@ -40,14 +41,17 @@ fi readonly ALL_OFF BOLD BLUE GREEN RED YELLOW function msg { + (( QUIET )) && return 0 local mesg=$1; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" } function msg2 { + (( QUIET )) && return 0 local mesg=$1; shift printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" } function err { + (( QUIET )) && return 0 local mesg=$1; shift printf "${RED} ->${ALL_OFF}${BOLD}${RED} ${mesg}${ALL_OFF}\n" "$@" >&2 } @@ -82,6 +86,8 @@ EOF } function generate_deb { + msg "generating deb package..." + local tmpdir="$(mktemp --directory)" local data_tgz="${tmpdir}/data.tar.gz" local control_tgz="${tmpdir}/control.tar.gz" @@ -304,79 +310,48 @@ function is_function { declare -F "$1" > /dev/null } +function check_source_validation { + # check if all source is valid + for s in "${source[@]}"; do + if ! grep "::" <<< "$s" > /dev/null; then + err "source must contain \"::\" to specify file name" + exit 1 + fi + done +} -## -## Here start the build logic -## +function clean_dir { + msg "cleaning \$srcdir and \$pkgdir..." + rm -rf "${srcdir}" "${pkgdir}" + mkdir -p "${srcdir}" "${pkgdir}" +} -while (( "$#" >= 1 )); do - case "$1" in - -F) FAKE_PACKAGE=1 ;; - -OS) OVERRIDE_SOURCE=1 ;; - *) err "Unkown option $1"; break ;; - esac - shift -done +function retrieve_source { + msg "retrieving source..." + for s in "${source[@]}"; do + file_name="${s%%::*}" + url="${s##*::}" -source "${buildfile}" + retrive_source_single "${file_name}" "${url}" + done +} -# Run package and generate deb and exit -if (( FAKE_PACKAGE )); then +function extract_source { + msg "extracting source..." + for s in "${source[@]}"; do + file_name="${s%%::*}" + url="${s##*::}" - if is_function package; then - msg "run function: custom package..." - run_function_safe package + extract_source_single "${file_name}" "${url}" + done +} + +function update_pkgver { + if ! is_function pkgver; then + return fi - - msg "generating control info..." - mkdir -p "${pkgdir}/DEBIAN" - echo 2 > "${pkgdir}/DEBIAN/compat" - debian_control > "${pkgdir}/DEBIAN/control" - - function debian_hooks_warpper { is_function "$1" && "$1" > "$2" && chmod +x "$2" || true; } - debian_hooks_warpper debian_preinst ${pkgdir}/DEBIAN/preinst - debian_hooks_warpper debian_postinst ${pkgdir}/DEBIAN/postinst - debian_hooks_warpper debian_prerm ${pkgdir}/DEBIAN/prerm - debian_hooks_warpper debian_postrm ${pkgdir}/DEBIAN/postrm - - - msg "generating deb package..." - generate_deb - exit $? -fi - -# check if all source is valid -for s in "${source[@]}"; do - if ! grep "::" <<< "$s" > /dev/null; then - err "source must contain \"::\" to specify file name" - exit 1 - fi -done - -msg "cleaning \$srcdir and \$pkgdir..." -rm -rf "${srcdir}" "${pkgdir}" - -mkdir -p "${srcdir}" "${pkgdir}" - -msg "retrieving source..." -for s in "${source[@]}"; do - file_name="${s%%::*}" - url="${s##*::}" - - retrive_source_single "${file_name}" "${url}" -done - -msg "extracting source..." -for s in "${source[@]}"; do - file_name="${s%%::*}" - url="${s##*::}" - - extract_source_single "${file_name}" "${url}" -done - -if is_function pkgver; then - msg "run function: pkgver..." + msg "updating pkgver..." newpkgver="$(run_function_safe pkgver)" if [[ "${newpkgver}" != "${pkgver:-}" ]] ; then mapfile -t bfcontent < "${buildfile}" @@ -395,17 +370,83 @@ if is_function pkgver; then msg2 "updated version: ${newpkgver}" fi + pkgver="${newpkgver}" +} + +function generate_control { + + msg "generating control info..." + mkdir -p "${pkgdir}/DEBIAN" + echo 2 > "${pkgdir}/DEBIAN/compat" + debian_control > "${pkgdir}/DEBIAN/control" + + function debian_hooks_warpper { is_function "$1" && "$1" > "$2" && chmod +x "$2" || true; } + debian_hooks_warpper debian_preinst ${pkgdir}/DEBIAN/preinst + debian_hooks_warpper debian_postinst ${pkgdir}/DEBIAN/postinst + debian_hooks_warpper debian_prerm ${pkgdir}/DEBIAN/prerm + debian_hooks_warpper debian_postrm ${pkgdir}/DEBIAN/postrm +} + +function run_function { + if is_function "$1" ; then + msg "run function: $1" + run_function_safe "$1" + fi +} + + +## +## Here start the build logic +## + +while (( "$#" >= 1 )); do + case "$1" in + -F) FAKE_PACKAGE=1 ;; + -OS) OVERRIDE_SOURCE=1 ;; + -STF) SHOW_TARGET_FILE=1 ; QUIET=1 ;; + -Q) QUIET=1 ;; + *) err "Unkown option $1"; break ;; + esac + shift +done + +source "${buildfile}" + + +if (( ! FAKE_PACKAGE )) ; then + if (( SHOW_TARGET_FILE )) && ! is_function pkgver ; then + echo "$(get_deb_name)" + exit 0 + fi + + check_source_validation + + clean_dir + + retrieve_source + + extract_source + + update_pkgver + + if (( SHOW_TARGET_FILE )) && is_function pkgver ; then + echo "$(get_deb_name)" + exit 0 + fi + + run_function build + + # recursive call self to run rest task in fakeroot + msg "entering fakeroot environment..." + fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${ARGLIST[@]}" || exit $? + msg "leaving fakeroot environment..." + + msg "builds has done" +else + run_function package + + generate_control + + generate_deb fi - -if is_function build; then - msg "run function: custom build..." - run_function_safe build -fi - -# recursive call self to run rest task in fakeroot -msg "entering fakeroot environment..." -fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${ARGLIST[@]}" || exit $? -msg "leaving fakeroot environment..." - -msg "builds has done"