From 5da0362dcacc9a94b8e13d8f76df7a281c561a81 Mon Sep 17 00:00:00 2001 From: leafee98 Date: Tue, 28 Mar 2023 16:03:03 +0800 Subject: [PATCH] use rel as part as version, pkgver now run just following extract source --- DEBBUILD | 5 ++- makedeb | 116 ++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 88 insertions(+), 33 deletions(-) diff --git a/DEBBUILD b/DEBBUILD index 57fcf7d..5c9a643 100644 --- a/DEBBUILD +++ b/DEBBUILD @@ -1,7 +1,9 @@ #/usr/bin/env bash pkgname="forgejo" +pkgver=23333 # this will be override by pkgver function pkgrel=1 +pkgcommit="" pkgdesc="A painless selfhost git service." url="https://codeberg.org/forgejo/forgejo" maintainer="Leafee98 " @@ -14,8 +16,9 @@ source=( "t.sh::material/t.sh" ) +# This will be run just follow extracting source function pkgver { - echo "0.0.2" + echo "1.19.0-2" } function build { diff --git a/makedeb b/makedeb index 2a6f980..2a5fc6d 100755 --- a/makedeb +++ b/makedeb @@ -1,14 +1,13 @@ #!/usr/bin/env bash -workspace=$(pwd -P) +workspace="$(pwd -P)" +buildfile="${workspace}/DEBBUILD" -export srcdir="${workspace}/src" -export pkgdir="${workspace}/pkg" +srcdir="${workspace}/src" +pkgdir="${workspace}/pkg" FAKE_PACKAGE=0 OVERRIDE_SOURCE=0 -OVERRIDE_VERSION="" -ACTION="" set -o functrace @@ -17,7 +16,6 @@ set -o errtrace set -o errexit function err_occur { - err "Build aborted in: %s" "${ACTION}" err "Failed at $1: ${BASH_COMMAND}" err "Trace line number: %s" "$*" } @@ -54,13 +52,28 @@ function err { printf "${RED} ->${ALL_OFF}${BOLD}${RED} ${mesg}${ALL_OFF}\n" "$@" >&2 } +function get_full_version { + local result="${pkgver//-/.}" + if [[ -n "${pkgrel:-}" ]] ; then + result="${result}-${pkgrel}" + fi + if [[ -n "${pkgcommit:-}" ]] ; then + result="${result}+${pkgcommit}" + fi + echo "${result}" +} + +function get_deb_name { + echo "${pkgname}_$(get_full_version).deb" +} function debian_control { local install_size="$(du --block-size=1K --summarize ${pkgdir} | cut -d $'\t' -f 1)" + local fv="$(get_full_version)" cat << EOF | envsubst Package: ${pkgname} -Version: ${pkgver} +Version: ${fv} Architecture: all Maintainer: ${maintainer} Installed-Size: ${install_size} @@ -82,9 +95,11 @@ function generate_deb { echo 2.0 > "${debian_binary}" - ar r "${pkgname}${pkgver:+-}${pkgver}.deb" "${debian_binary}" "${control_tgz}" "${data_tgz}" + ar r "$(get_deb_name)" "${debian_binary}" "${control_tgz}" "${data_tgz}" rm -rf "${tmpdir}" + + msg2 "generated deb: %s" "$(get_deb_name)" } function url_type { @@ -257,6 +272,34 @@ function decompress_source_file { esac } +error_function() { + # first exit all subshells, then print the error + if (( ! BASH_SUBSHELL )); then + error "A failure occurred in %s()." "$1" + plainerr "$(gettext "Aborting...")" + fi + exit $E_USER_FUNCTION_FAILED +} + +# use less strict shell for custom functions +function run_function_safe { + local restoretrap + + set +o errtrace + set +o errexit + + restoretrap=$(trap -p ERR) + trap "error_function '$1'" ERR + + "$1" + + set -o errtrace + set -o errexit + + trap - ERR + eval "$restoretrap" +} + function is_function { declare -F "$1" > /dev/null } @@ -270,28 +313,23 @@ while (( "$#" >= 1 )); do case "$1" in -F) FAKE_PACKAGE=1 ;; -OS) OVERRIDE_SOURCE=1 ;; - -OV) OVERRIDE_VERSION="$2"; shift ;; *) err "Unkown option $1"; break ;; esac shift done -source "${workspace}/DEBBUILD" +source "${buildfile}" # Run package and generate deb and exit if (( FAKE_PACKAGE )); then - # version passed directly from parent shell - if [[ -n "${OVERRIDE_VERSION}" ]] ; then - pkgver="${OVERRIDE_VERSION}" - fi if is_function package; then - ACTION="custom package"; msg "run function: %s..." "${ACTION}" - package + msg "run function: custom package..." + run_function_safe package fi - ACTION="generating control info"; msg "${ACTION}..." + msg "generating control info..." mkdir -p "${pkgdir}/DEBIAN" echo 2 > "${pkgdir}/DEBIAN/compat" debian_control > "${pkgdir}/DEBIAN/control" @@ -303,7 +341,7 @@ if (( FAKE_PACKAGE )); then debian_hooks_warpper debian_postrm ${pkgdir}/DEBIAN/postrm - ACTION="generating deb package"; msg "${ACTION}..." + msg "generating deb package..." generate_deb exit $? fi @@ -316,12 +354,12 @@ for s in "${source[@]}"; do fi done -ACTION="cleaning \$srcdir and \$pkgdir"; msg "${ACTION}..." +msg "cleaning \$srcdir and \$pkgdir..." rm -rf "${srcdir}" "${pkgdir}" mkdir -p "${srcdir}" "${pkgdir}" -ACTION="retrieving source"; msg "${ACTION}..." +msg "retrieving source..." for s in "${source[@]}"; do file_name="${s%%::*}" url="${s##*::}" @@ -329,7 +367,7 @@ for s in "${source[@]}"; do retrive_source_single "${file_name}" "${url}" done -ACTION="extracting source"; msg "${ACTION}..." +msg "extracting source..." for s in "${source[@]}"; do file_name="${s%%::*}" url="${s##*::}" @@ -337,23 +375,37 @@ for s in "${source[@]}"; do extract_source_single "${file_name}" "${url}" done -if is_function build; then - ACTION="custom build"; msg "run function: %s..." "${ACTION}" - build +if is_function pkgver; then + msg "run function: pkgver..." + newpkgver="$(run_function_safe pkgver)" + if [[ "${newpkgver}" != "${pkgver:-}" ]] ; then + mapfile -t bfcontent < "${buildfile}" + + shopt -s extglob + bfcontent=("${bfcontent[@]/#pkgver=*?(")([^ ])?(")/pkgver=$newpkgver}") + bfcontent=("${bfcontent[@]/#pkgrel=*([^ ])/pkgrel=1}") + shopt -u extglob + + if ! printf '%s\n' "${bfcontent[@]}" > "${buildfile}"; then + err "Failed to update %s from %s to %s" "pkgver" "$pkgver" "$newpkgver" + exit 1 + fi + + source "${buildfile}" + + msg2 "updated version: ${newpkgver}" + fi + pkgver="${newpkgver}" fi -ACTION="custom pkgver"; -if [[ -n "${OVERRIDE_VERSION}" ]] ; then - msg "Using override version: %s" "${OVERRIDE_VERSION}" - pkgver="${OVERRIDE_VERSION}" -elif is_function pkgver; then - msg "run function: %s..." "${ACTION}" - pkgver="$(pkgver)" +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 -OV "${pkgver}" "${ARGLIST[@]}" || exit $? +fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${ARGLIST[@]}" || exit $? msg "leaving fakeroot environment..." msg "builds has done"