Feature: "-STF" to show target deb file, refactor code

This commit is contained in:
leafee98 2023-03-28 21:41:14 +08:00
parent 5da0362dca
commit f53a2e1de8

139
makedeb
View file

@ -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,48 +310,7 @@ function is_function {
declare -F "$1" > /dev/null
}
##
## Here start the build logic
##
while (( "$#" >= 1 )); do
case "$1" in
-F) FAKE_PACKAGE=1 ;;
-OS) OVERRIDE_SOURCE=1 ;;
*) err "Unkown option $1"; break ;;
esac
shift
done
source "${buildfile}"
# Run package and generate deb and exit
if (( FAKE_PACKAGE )); then
if is_function package; then
msg "run function: custom package..."
run_function_safe package
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
function check_source_validation {
# check if all source is valid
for s in "${source[@]}"; do
if ! grep "::" <<< "$s" > /dev/null; then
@ -353,12 +318,15 @@ for s in "${source[@]}"; do
exit 1
fi
done
}
function clean_dir {
msg "cleaning \$srcdir and \$pkgdir..."
rm -rf "${srcdir}" "${pkgdir}"
mkdir -p "${srcdir}" "${pkgdir}"
}
function retrieve_source {
msg "retrieving source..."
for s in "${source[@]}"; do
file_name="${s%%::*}"
@ -366,7 +334,9 @@ for s in "${source[@]}"; do
retrive_source_single "${file_name}" "${url}"
done
}
function extract_source {
msg "extracting source..."
for s in "${source[@]}"; do
file_name="${s%%::*}"
@ -374,9 +344,14 @@ for s in "${source[@]}"; do
extract_source_single "${file_name}" "${url}"
done
}
if is_function pkgver; then
msg "run function: pkgver..."
function update_pkgver {
if ! is_function pkgver; then
return
fi
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
if is_function build; then
msg "run function: custom build..."
run_function_safe build
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