use rel as part as version, pkgver now run just following extract source

This commit is contained in:
leafee98 2023-03-28 16:03:03 +08:00
parent 29574d90b4
commit 5da0362dca
2 changed files with 88 additions and 33 deletions

View file

@ -1,7 +1,9 @@
#/usr/bin/env bash #/usr/bin/env bash
pkgname="forgejo" pkgname="forgejo"
pkgver=23333 # this will be override by pkgver function
pkgrel=1 pkgrel=1
pkgcommit=""
pkgdesc="A painless selfhost git service." pkgdesc="A painless selfhost git service."
url="https://codeberg.org/forgejo/forgejo" url="https://codeberg.org/forgejo/forgejo"
maintainer="Leafee98 <me@leafee98.com>" maintainer="Leafee98 <me@leafee98.com>"
@ -14,8 +16,9 @@ source=(
"t.sh::material/t.sh" "t.sh::material/t.sh"
) )
# This will be run just follow extracting source
function pkgver { function pkgver {
echo "0.0.2" echo "1.19.0-2"
} }
function build { function build {

116
makedeb
View file

@ -1,14 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
workspace=$(pwd -P) workspace="$(pwd -P)"
buildfile="${workspace}/DEBBUILD"
export srcdir="${workspace}/src" srcdir="${workspace}/src"
export pkgdir="${workspace}/pkg" pkgdir="${workspace}/pkg"
FAKE_PACKAGE=0 FAKE_PACKAGE=0
OVERRIDE_SOURCE=0 OVERRIDE_SOURCE=0
OVERRIDE_VERSION=""
ACTION=""
set -o functrace set -o functrace
@ -17,7 +16,6 @@ set -o errtrace
set -o errexit set -o errexit
function err_occur { function err_occur {
err "Build aborted in: %s" "${ACTION}"
err "Failed at $1: ${BASH_COMMAND}" err "Failed at $1: ${BASH_COMMAND}"
err "Trace line number: %s" "$*" err "Trace line number: %s" "$*"
} }
@ -54,13 +52,28 @@ function err {
printf "${RED} ->${ALL_OFF}${BOLD}${RED} ${mesg}${ALL_OFF}\n" "$@" >&2 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 { function debian_control {
local install_size="$(du --block-size=1K --summarize ${pkgdir} | cut -d $'\t' -f 1)" local install_size="$(du --block-size=1K --summarize ${pkgdir} | cut -d $'\t' -f 1)"
local fv="$(get_full_version)"
cat << EOF | envsubst cat << EOF | envsubst
Package: ${pkgname} Package: ${pkgname}
Version: ${pkgver} Version: ${fv}
Architecture: all Architecture: all
Maintainer: ${maintainer} Maintainer: ${maintainer}
Installed-Size: ${install_size} Installed-Size: ${install_size}
@ -82,9 +95,11 @@ function generate_deb {
echo 2.0 > "${debian_binary}" 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}" rm -rf "${tmpdir}"
msg2 "generated deb: %s" "$(get_deb_name)"
} }
function url_type { function url_type {
@ -257,6 +272,34 @@ function decompress_source_file {
esac 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 { function is_function {
declare -F "$1" > /dev/null declare -F "$1" > /dev/null
} }
@ -270,28 +313,23 @@ while (( "$#" >= 1 )); do
case "$1" in case "$1" in
-F) FAKE_PACKAGE=1 ;; -F) FAKE_PACKAGE=1 ;;
-OS) OVERRIDE_SOURCE=1 ;; -OS) OVERRIDE_SOURCE=1 ;;
-OV) OVERRIDE_VERSION="$2"; shift ;;
*) err "Unkown option $1"; break ;; *) err "Unkown option $1"; break ;;
esac esac
shift shift
done done
source "${workspace}/DEBBUILD" source "${buildfile}"
# Run package and generate deb and exit # Run package and generate deb and exit
if (( FAKE_PACKAGE )); then if (( FAKE_PACKAGE )); then
# version passed directly from parent shell
if [[ -n "${OVERRIDE_VERSION}" ]] ; then
pkgver="${OVERRIDE_VERSION}"
fi
if is_function package; then if is_function package; then
ACTION="custom package"; msg "run function: %s..." "${ACTION}" msg "run function: custom package..."
package run_function_safe package
fi fi
ACTION="generating control info"; msg "${ACTION}..." msg "generating control info..."
mkdir -p "${pkgdir}/DEBIAN" mkdir -p "${pkgdir}/DEBIAN"
echo 2 > "${pkgdir}/DEBIAN/compat" echo 2 > "${pkgdir}/DEBIAN/compat"
debian_control > "${pkgdir}/DEBIAN/control" debian_control > "${pkgdir}/DEBIAN/control"
@ -303,7 +341,7 @@ if (( FAKE_PACKAGE )); then
debian_hooks_warpper debian_postrm ${pkgdir}/DEBIAN/postrm debian_hooks_warpper debian_postrm ${pkgdir}/DEBIAN/postrm
ACTION="generating deb package"; msg "${ACTION}..." msg "generating deb package..."
generate_deb generate_deb
exit $? exit $?
fi fi
@ -316,12 +354,12 @@ for s in "${source[@]}"; do
fi fi
done done
ACTION="cleaning \$srcdir and \$pkgdir"; msg "${ACTION}..." msg "cleaning \$srcdir and \$pkgdir..."
rm -rf "${srcdir}" "${pkgdir}" rm -rf "${srcdir}" "${pkgdir}"
mkdir -p "${srcdir}" "${pkgdir}" mkdir -p "${srcdir}" "${pkgdir}"
ACTION="retrieving source"; msg "${ACTION}..." msg "retrieving source..."
for s in "${source[@]}"; do for s in "${source[@]}"; do
file_name="${s%%::*}" file_name="${s%%::*}"
url="${s##*::}" url="${s##*::}"
@ -329,7 +367,7 @@ for s in "${source[@]}"; do
retrive_source_single "${file_name}" "${url}" retrive_source_single "${file_name}" "${url}"
done done
ACTION="extracting source"; msg "${ACTION}..." msg "extracting source..."
for s in "${source[@]}"; do for s in "${source[@]}"; do
file_name="${s%%::*}" file_name="${s%%::*}"
url="${s##*::}" url="${s##*::}"
@ -337,23 +375,37 @@ for s in "${source[@]}"; do
extract_source_single "${file_name}" "${url}" extract_source_single "${file_name}" "${url}"
done done
if is_function build; then if is_function pkgver; then
ACTION="custom build"; msg "run function: %s..." "${ACTION}" msg "run function: pkgver..."
build 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 fi
ACTION="custom pkgver"; source "${buildfile}"
if [[ -n "${OVERRIDE_VERSION}" ]] ; then
msg "Using override version: %s" "${OVERRIDE_VERSION}" msg2 "updated version: ${newpkgver}"
pkgver="${OVERRIDE_VERSION}" fi
elif is_function pkgver; then pkgver="${newpkgver}"
msg "run function: %s..." "${ACTION}" fi
pkgver="$(pkgver)"
if is_function build; then
msg "run function: custom build..."
run_function_safe build
fi fi
# recursive call self to run rest task in fakeroot # recursive call self to run rest task in fakeroot
msg "entering fakeroot environment..." 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 "leaving fakeroot environment..."
msg "builds has done" msg "builds has done"