├── LICENSE ├── README.md ├── DEBBUILD └── makedeb /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Leafee98 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # makedeb 2 | 3 | Script for building Debian package quickly and easily. Inspired by Archlinux's makepkg. 4 | 5 | ## Example 6 | 7 | Check the `DEBBUILD` 8 | 9 | ## Reference 10 | 11 | ### Build process 12 | 13 | First it download needed content from array `sources`, then use function `pkgver` to determine the package version, then run function `build` and function `package`, then run hooks `debian_(pre|post)(inst|rm)` and make the printed strings as debian's hook scripts. Finally generate .deb with files in `$pkgdir`. 14 | 15 | ### Download and extract source 16 | 17 | Every string in array `source` should be like `::`. When downloading, the `download_url` content will be named with ``. When `build` and `pacage` run, every `` will be copied to `$srcdir`. If the file is a compressed file, it will be decompressed, if the file is a git repo, the specific branch, commit or tag will be checkouted. 18 | 19 | ### Global variables 20 | 21 | - `pkgname`: package's name 22 | - `pkgver`: package's version, if need to extract version from source, use function `pkgver` 23 | - `pkgrel`: debian package reference, it should increase by one every build 24 | - `pkgdesc`: package's description 25 | - `section`: default `misc` if not specified 26 | - `priority`: default `optional` if not specified 27 | - `url`: packages upstream url 28 | - `maintainer`: maintainer's contect information 29 | 30 | ### Global functions 31 | 32 | - `pkgver`: should print the actual version. This override the variable `pkgver` 33 | - `build`: do something like compile source 34 | - `package`: do something like copy file from `$srcdir` to `$pkgdir` 35 | - `debian_(pre|post)(inst|rm)`: should print content of debian hooks file 36 | -------------------------------------------------------------------------------- /DEBBUILD: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | 3 | pkgname="makedeb" 4 | pkgver=0.0.2.0.g175943a 5 | pkgrel=1 6 | arch="all" 7 | pkgcommit="" 8 | section="utils" # https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections 9 | priority="optional" # https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities 10 | pkgdesc="A painless selfhost git service." 11 | url="https://git.leafee98.com/leafee98/makedeb" 12 | maintainer="Leafee98 " 13 | 14 | source=( 15 | "LICENSE::https://git.leafee98.com/leafee98/makedeb/raw/branch/main/LICENSE" # from http (existed file will skip, without checking hash) 16 | "makedeb-repo::git+https://git.leafee98.com/leafee98/makedeb.git#branch=main" # from git with https 17 | "README.md::README.md" # from local file 18 | ) 19 | 20 | # This will be run just after extracting source, and re-assign to `pkgver` 21 | # 22 | # If extracting version from source is not needed, don't define this function. 23 | function pkgver { 24 | git describe --tags --long | sed 's/^v//;s/-/./g' 25 | } 26 | 27 | function build { 28 | echo "Here should do something like compile sources." 29 | echo "But for this package we just print some messages." 30 | } 31 | 32 | function package { 33 | install -Dm644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/makedeb/LICENSE" 34 | install -Dm755 "${srcdir}/makedeb-repo/makedeb" "${pkgdir}/usr/bin/makedeb" 35 | install -Dm755 "${srcdir}/README.md" "${pkgdir}/usr/share/doc/makedeb/README.md" 36 | } 37 | 38 | # The function describing hook for (pre|post)(inst|rm) should 39 | # *print* content of those hook file. 40 | # If the any hook is not needed, don't define those function. 41 | 42 | #function debian_preinst { 43 | #} 44 | 45 | function debian_postinst { 46 | cat << EOF 47 | #!/usr/bin/env bash 48 | echo "successfully installed makedeb" 49 | EOF 50 | } 51 | 52 | #function debian_prerm { 53 | #} 54 | 55 | function debian_postrm { 56 | cat << EOF 57 | #!/usr/bin/env bash 58 | echo "successfully removed makedeb" 59 | EOF 60 | } 61 | -------------------------------------------------------------------------------- /makedeb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | workspace="$(pwd -P)" 4 | buildfile="${workspace}/DEBBUILD" 5 | 6 | srcdir="${workspace}/src" 7 | pkgdir="${workspace}/pkg" 8 | 9 | _IN_FAKEROOT=0 10 | _BACKUP_STDOUT=3 # use file descriptor 3 to backup stdout 11 | _BACKUP_STDERR=4 # use file descriptor 4 to backup stderr 12 | _ARGLIST=("$@") 13 | OVERRIDE_SOURCE=0 14 | QUIET=0 15 | PACKAGELIST=0 16 | IS_DYNAMICV_PKGVER=0 17 | 18 | _STEP_CLEAN=1 19 | _STEP_RETRIEVE_SOURCE=1 20 | _STEP_EXTRACT_SOURCE=1 21 | _STEP_UPDATE_PKGVER=1 22 | _STEP_CHCECK_PACKAGE_EXISTS=1 23 | _STEP_BUILD=1 24 | _STEP_PACKAGE=1 25 | _STEP_CREATE_ARCHIVE=1 26 | 27 | _STOP_AFTER_CLEAN=0 28 | _STOP_AFTER_RETRIEVE_SOURCE=0 29 | _STOP_AFTER_EXTRACT_SOURCE=0 30 | _STOP_AFTER_UPDATE_PKGVER=0 31 | #_STEP_CHCECK_PACKAGE_EXISTS=0 # stop after checking exists is useless 32 | _STOP_AFTER_BUILD=0 33 | _STOP_AFTER_PACKAGE=0 34 | _STOP_AFTER_CREATE_ARCHIVE=0 35 | 36 | set -o functrace 37 | set -o nounset 38 | set -o errtrace 39 | set -o errexit 40 | 41 | function err_occur { 42 | err "Failed at $1: ${BASH_COMMAND}" 43 | err "Trace line number: %s" "$*" 44 | } 45 | trap 'err_occur "${LINENO}" "${BASH_LINENO[@]}"' ERR 46 | 47 | # prefer terminal safe colored and bold text when tput is supported 48 | if tput setaf 0 &>/dev/null; then 49 | ALL_OFF="$(tput sgr0)" 50 | BOLD="$(tput bold)" 51 | BLUE="${BOLD}$(tput setaf 4)" 52 | GREEN="${BOLD}$(tput setaf 2)" 53 | RED="${BOLD}$(tput setaf 1)" 54 | YELLOW="${BOLD}$(tput setaf 3)" 55 | else 56 | ALL_OFF="\e[0m" 57 | BOLD="\e[1m" 58 | BLUE="${BOLD}\e[34m" 59 | GREEN="${BOLD}\e[32m" 60 | RED="${BOLD}\e[31m" 61 | YELLOW="${BOLD}\e[33m" 62 | fi 63 | readonly ALL_OFF BOLD BLUE GREEN RED YELLOW 64 | 65 | function msg { 66 | (( QUIET )) && return 0 67 | local mesg=$1; shift 68 | printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" 69 | } 70 | function msg2 { 71 | (( QUIET )) && return 0 72 | local mesg=$1; shift 73 | printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" 74 | } 75 | function err { 76 | (( QUIET )) && return 0 77 | local mesg=$1; shift 78 | printf "${RED}==>${ALL_OFF}${BOLD}${RED} ${mesg}${ALL_OFF}\n" "$@" >&2 79 | } 80 | 81 | function get_full_version { 82 | local result="${pkgver//-/.}" 83 | if [[ -n "${pkgrel:-}" ]] ; then 84 | result="${result}-${pkgrel}" 85 | fi 86 | if [[ -n "${pkgcommit:-}" ]] ; then 87 | result="${result}+${pkgcommit}" 88 | fi 89 | echo "${result}" 90 | } 91 | 92 | function get_deb_name { 93 | echo "${pkgname}_$(get_full_version).deb" 94 | } 95 | 96 | function debian_control { 97 | local install_size="$(du --block-size=1K --summarize ${pkgdir} | cut -d $'\t' -f 1)" 98 | local fv="$(get_full_version)" 99 | 100 | echo "Package: ${pkgname}" 101 | echo "Version: ${fv}" 102 | echo "Architecture: ${arch}" 103 | echo "Maintainer: ${maintainer}" 104 | echo "Installed-Size: ${install_size}" 105 | echo "Homepage: ${url}" 106 | 107 | [[ -n "${section:=misc}" ]] && echo "Section: ${section}" 108 | [[ -n "${priority:=optional}" ]] && echo "Priority: ${priority}" 109 | 110 | echo "Description: ${pkgdesc}" 111 | } 112 | 113 | function generate_control { 114 | msg "Generating control info..." 115 | mkdir -p "${pkgdir}/DEBIAN" 116 | echo 2 > "${pkgdir}/DEBIAN/compat" 117 | debian_control > "${pkgdir}/DEBIAN/control" 118 | 119 | function debian_hooks_warpper { is_function "$1" && "$1" > "$2" && chmod +x "$2" || true; } 120 | debian_hooks_warpper debian_preinst ${pkgdir}/DEBIAN/preinst 121 | debian_hooks_warpper debian_postinst ${pkgdir}/DEBIAN/postinst 122 | debian_hooks_warpper debian_prerm ${pkgdir}/DEBIAN/prerm 123 | debian_hooks_warpper debian_postrm ${pkgdir}/DEBIAN/postrm 124 | } 125 | 126 | 127 | function generate_deb { 128 | msg "Generating deb package..." 129 | 130 | local tmpdir="$(mktemp --directory)" 131 | local data_tgz="${tmpdir}/data.tar.gz" 132 | local control_tgz="${tmpdir}/control.tar.gz" 133 | local debian_binary="${tmpdir}/debian-binary" 134 | 135 | tar --gzip --exclude="./DEBIAN" -C "${pkgdir}" -cf "${data_tgz}" . 136 | 137 | tar --gzip -C "${pkgdir}/DEBIAN" -cf "${control_tgz}" . 138 | 139 | echo 2.0 > "${debian_binary}" 140 | 141 | ar r "$(get_deb_name)" "${debian_binary}" "${control_tgz}" "${data_tgz}" 142 | 143 | rm -rf "${tmpdir}" 144 | 145 | msg2 "Generated deb: %s" "$(get_deb_name)" 146 | } 147 | 148 | function step_create_archive { 149 | generate_control 150 | generate_deb 151 | } 152 | 153 | function url_type { 154 | if [[ "${url}" == git+* ]] ; then 155 | echo "git" 156 | elif [[ "${url}" == http://* ]] ; then 157 | echo "http" 158 | elif [[ "${url}" == https://* ]] ; then 159 | echo "https" 160 | elif [[ "${url}" == ftp://* ]] ; then 161 | echo "ftp" 162 | elif [[ "${url}" == ftps://* ]] ; then 163 | echo "ftps" 164 | elif [[ "${url}" == file//* ]]; then 165 | echo "file" 166 | elif [[ "${url}" != *://* ]] ; then 167 | echo "file" 168 | else 169 | err "Unkown url schema: %s" "${url}" 170 | err "Aborting..." 171 | exit 1 172 | fi 173 | } 174 | 175 | function create_soft_link { 176 | local src="$1" 177 | local tgt="$2" 178 | 179 | if [[ ! -e "${src}" ]] ; then 180 | err "soft_link src %s not exist" "${src}" 181 | return 1 182 | fi 183 | 184 | if [[ -e "${tgt}" ]] ; then 185 | err "soft_link tgt %s already exist" "${tgt}" 186 | return 1 187 | fi 188 | 189 | ln --symbolic "${src}" "${tgt}" 190 | } 191 | 192 | function url_fragment { 193 | local url="$1" 194 | local fragment="${url#*#}" 195 | if [[ "${url}" == "${fragment}" ]] ; then 196 | return 197 | fi 198 | echo "${fragment}" 199 | } 200 | 201 | # $1 is relative path to file 202 | # $2 is url/(relative path to materials) 203 | function retrieve_source_single { 204 | local file_name="$1" 205 | local url="$2" 206 | 207 | case "$(url_type "${url}")" in 208 | "git") 209 | if [[ -d "${file_name}" ]]; then 210 | msg2 "Updating ${file_name} from ${url} with git..." 211 | git --git-dir="${workspace}/${file_name}" fetch --all 212 | else 213 | msg2 "Cloning ${file_name} from ${url} with git..." 214 | local git_source="${url##git+}" 215 | git_source="${git_source%%#*}" 216 | git clone --mirror "${git_source}" "${workspace}/${file_name}" 217 | fi 218 | ;; 219 | "http"|"https"|"ftp"|"ftps") 220 | if (( ! OVERRIDE_SOURCE )) && [[ -f "${workspace}/${file_name}" ]] ; then 221 | msg2 "${file_name} already exists, skip download" 222 | else 223 | msg2 "Retrieving ${file_name} from ${url} with curl..." 224 | curl --location "${url}" --output "${workspace}/${file_name}" 225 | fi 226 | ;; 227 | "file") 228 | if [[ -e "${workspace}/${url}" ]] ; then 229 | msg2 "Found local file: ${url}" 230 | else 231 | err "Local file not found: ${url}" 232 | err "Aborting..." 233 | exit 1 234 | fi 235 | ;; 236 | *) 237 | err "Retrieving url as type ${url_type} not supported" 238 | err "Aborting..." 239 | exit 1 240 | esac 241 | } 242 | 243 | # $1 is relative path to file 244 | # $2 is url/(relative path to materials) 245 | function extract_source_single { 246 | local file_name="$1" 247 | local url="$2" 248 | local url_type="$(url_type "${url}")" 249 | 250 | case "${url_type}" in 251 | "git") 252 | [[ -d "${srcdir}/${file_name}" ]] || mkdir -p "${srcdir}/${file_name}" 253 | 254 | local ref=HEAD 255 | local frag=$(url_fragment "${url}") 256 | if [[ -n "${frag}" ]] ; then 257 | case "${frag%%=*}" in 258 | "branch") 259 | ref="refs/heads/${frag##*=}" 260 | ;; 261 | "tag") 262 | ref="refs/tags/${frag##*=}" 263 | ;; 264 | "commit") 265 | ref="${frag##*=}" 266 | ;; 267 | *) 268 | err "unrecognized reference in git url: ${frag}" 269 | exit 1 270 | ;; 271 | esac 272 | fi 273 | 274 | msg2 "Extracting git ${workspace}/${file_name} with reference ${ref}" 275 | git clone --shared "${workspace}/${file_name}" "${srcdir}/${file_name}" 276 | git -C "${srcdir}/${file_name}" switch --force-create makedeb --no-track "${ref}" 277 | ;; 278 | "file") # for material files, just soft-link under src 279 | create_soft_link $(realpath "${workspace}/${url}") "${srcdir}/${file_name}" 280 | decompress_source_file "${srcdir}/${file_name}" 281 | ;; 282 | *) # for downloaded files, just soft-link downloaded file under src 283 | create_soft_link $(realpath "${workspace}/${file_name}") "${srcdir}/${file_name}" 284 | decompress_source_file "${srcdir}/${file_name}" 285 | ;; 286 | esac 287 | } 288 | 289 | # $1 is real path to file 290 | function decompress_source_file { 291 | local file="$1" 292 | case "${file}" in 293 | *.tar|*.tar.gz|*.tgz|*.tar.Z|*.tar.bz2|*.tbz2|*.tar.lz|*.tlz|*.tar.xz|*.txz|*.tar.zst) 294 | cmd="tar" ;; 295 | *.gz|*.z|*.Z) 296 | cmd="gzip" ;; 297 | *.bz2|*.bz) 298 | cmd="bzip2" ;; 299 | *.xz) 300 | cmd="xz" ;; 301 | *.zst|*.zstd) 302 | cmd="zstd" ;; 303 | *.zip) 304 | cmd="unzip" ;; 305 | *) 306 | msg2 "No need to decompress, skip %s" "${file}" 307 | return 308 | esac 309 | 310 | msg2 "Decompressing %s with %s" "${file}" "${cmd}" 311 | local res=0 312 | case "$cmd" in 313 | "tar") 314 | $cmd -xf "$file" --directory="${srcdir}" || res=$? 315 | ;; 316 | "unzip") 317 | $cmd "$file" -d "${srcdir}" || res=$? 318 | ;; 319 | *) 320 | rm -f -- "${file%.*}" 321 | $cmd -dcf -- "$file" > "${file%.*}" || res=$? 322 | ;; 323 | esac 324 | } 325 | 326 | error_function() { 327 | # first exit all subshells, then print the error 328 | if (( ! BASH_SUBSHELL )); then 329 | err "A failure occurred in %s()." "$1" 330 | err "$(gettext "Aborting...")" 331 | fi 332 | exit 1 333 | } 334 | 335 | # use less strict shell for custom functions 336 | function run_function_safe { 337 | local restoretrap 338 | 339 | set +o errtrace 340 | set +o errexit 341 | 342 | restoretrap=$(trap -p ERR) 343 | trap "error_function '$1'" ERR 344 | 345 | "$1" 346 | 347 | set -o errtrace 348 | set -o errexit 349 | 350 | trap - ERR 351 | eval "$restoretrap" 352 | } 353 | 354 | function is_function { 355 | declare -F "$1" > /dev/null 356 | } 357 | 358 | function check_source_validation { 359 | # check if all source is valid 360 | for s in "${source[@]}"; do 361 | if ! grep "::" <<< "$s" > /dev/null; then 362 | err "source must contain \"::\" to specify file name" 363 | exit 1 364 | fi 365 | done 366 | } 367 | 368 | function step_clean_dir { 369 | msg "Cleaning \$srcdir and \$pkgdir..." 370 | rm -rf "${srcdir}" "${pkgdir}" 371 | mkdir -p "${srcdir}" "${pkgdir}" 372 | } 373 | 374 | function step_retrieve_source { 375 | msg "Retrieving source..." 376 | for s in "${source[@]}"; do 377 | file_name="${s%%::*}" 378 | url="${s##*::}" 379 | 380 | retrieve_source_single "${file_name}" "${url}" 381 | done 382 | } 383 | 384 | function step_extract_source { 385 | msg "Extracting source..." 386 | for s in "${source[@]}"; do 387 | file_name="${s%%::*}" 388 | url="${s##*::}" 389 | 390 | extract_source_single "${file_name}" "${url}" 391 | done 392 | } 393 | 394 | function step_update_pkgver { 395 | if ! is_function pkgver; then 396 | return 397 | fi 398 | 399 | msg "Updating pkgver..." 400 | newpkgver="$(run_function_safe pkgver)" 401 | if [[ "${newpkgver}" != "${pkgver:-}" ]] ; then 402 | mapfile -t bfcontent < "${buildfile}" 403 | 404 | shopt -s extglob 405 | bfcontent=("${bfcontent[@]/#pkgver=*?(")([^ ])?(")/pkgver=$newpkgver}") 406 | bfcontent=("${bfcontent[@]/#pkgrel=*([^ ])/pkgrel=1}") 407 | shopt -u extglob 408 | 409 | if ! printf '%s\n' "${bfcontent[@]}" > "${buildfile}"; then 410 | err "Failed to update %s from %s to %s" "pkgver" "$pkgver" "$newpkgver" 411 | exit 1 412 | fi 413 | 414 | source "${buildfile}" 415 | 416 | msg2 "Updated version: ${newpkgver}" 417 | fi 418 | 419 | pkgver="${newpkgver}" 420 | } 421 | 422 | function run_function { 423 | if is_function "$1" ; then 424 | msg "Run function: $1" 425 | run_function_safe "$1" 426 | fi 427 | } 428 | 429 | function disable_stdout { 430 | exec {_BACKUP_STDOUT}>&1 431 | exec 1>/dev/null 432 | } 433 | 434 | function enable_stdout { 435 | exec 1>&"$_BACKUP_STDOUT" 436 | } 437 | 438 | function show_help { 439 | echo "$0 [OPTIONS]" 440 | echo " -Q quiet, disable log" 441 | echo " -f|--force don't check if package already exists, will" 442 | echo " --nobuild retrieve source, update pkgver and stop" 443 | echo " override the existed package" 444 | echo " --noextract use the current srcdir to build package, skip" 445 | echo " those retrieve source steps" 446 | echo " --noarchive retrieve and build, but don't package to .deb" 447 | echo " --packagelist show file to be generated by current DEBBUILD" 448 | echo " --is-dynamic-pkgver exit with 0 if DEBBUILD will update pkgver later" 449 | echo " -h|--help show this message" 450 | } 451 | 452 | ## 453 | ## Here start the build logic 454 | ## 455 | 456 | while (( "$#" >= 1 )); do 457 | case "$1" in 458 | -F) _IN_FAKEROOT=1 ;; 459 | -Q) QUIET=1 ;; 460 | -f|--force) _STEP_CHCECK_PACKAGE_EXISTS=0 ;; 461 | --noextract) 462 | _STEP_CLEAN=0 463 | _STEP_RETRIEVE_SOURCE=0 464 | _STEP_EXTRACT_SOURCE=0 465 | _STEP_UPDATE_PKGVER=0 466 | ;; 467 | --nobuild) 468 | _STEP_CHCECK_PACKAGE_EXISTS=0 469 | _STEP_BUILD=0 470 | _STEP_PACKAGE=0 471 | _STEP_CREATE_ARCHIVE=0 472 | 473 | _STOP_AFTER_UPDATE_PKGVER=1 474 | ;; 475 | --noarchive) 476 | _STEP_CHCECK_PACKAGE_EXISTS=0 477 | _STEP_CREATE_ARCHIVE=0 478 | 479 | _STOP_AFTER_BUILD=1 480 | ;; 481 | --packagelist) PACKAGELIST=1 ;; 482 | --is-dynamic-pkgver) IS_DYNAMICV_PKGVER=1 ;; 483 | -h|--help) show_help ; exit 0;; 484 | 485 | *) err "Unkown option $1" 486 | err "Use $0 --help for help" 487 | exit 1 ;; 488 | esac 489 | shift 490 | done 491 | 492 | source "${buildfile}" 493 | 494 | 495 | if (( PACKAGELIST )) ; then 496 | echo "$(get_deb_name)" 497 | exit 0 498 | fi 499 | 500 | if (( IS_DYNAMICV_PKGVER )) ; then 501 | if is_function pkgver ; then 502 | exit 0 503 | else 504 | exit 4 505 | fi 506 | fi 507 | 508 | if (( QUIET )) ; then 509 | disable_stdout 510 | fi 511 | 512 | if (( ! _IN_FAKEROOT )) ; then 513 | check_source_validation 514 | 515 | if (( _STEP_CLEAN )) ; then 516 | step_clean_dir 517 | fi 518 | 519 | if (( _STEP_RETRIEVE_SOURCE )) ; then 520 | step_retrieve_source 521 | fi 522 | 523 | if (( _STEP_EXTRACT_SOURCE )) ; then 524 | step_extract_source 525 | fi 526 | 527 | if (( _STEP_UPDATE_PKGVER )) ; then 528 | step_update_pkgver 529 | (( _STOP_AFTER_UPDATE_PKGVER )) && msg "Sources are ready." 530 | fi 531 | 532 | # Check if the package already exists 533 | if (( _STEP_CHCECK_PACKAGE_EXISTS )) ; then 534 | if [[ -f "$(get_deb_name)" ]] ; then 535 | err "The package already exists. (use -f to force build)" 536 | exit 13 537 | fi 538 | fi 539 | 540 | if (( _STEP_BUILD )) ; then 541 | run_function build 542 | (( _STOP_AFTER_BUILD )) && msg "Package directory is ready." 543 | fi 544 | 545 | if (( _STEP_PACKAGE || _STEP_CREATE_ARCHIVE )) ; then 546 | # recursive call self to run rest task in fakeroot 547 | msg "Entering fakeroot environment..." 548 | fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${_ARGLIST[@]}" || exit $? 549 | msg "Leaving fakeroot environment..." 550 | fi 551 | else 552 | if (( _STEP_PACKAGE )) ; then 553 | run_function package 554 | fi 555 | 556 | if (( _STEP_CREATE_ARCHIVE )) ; then 557 | step_create_archive 558 | msg "Finish making: $(get_deb_name) $(date)" 559 | fi 560 | fi 561 | 562 | if (( QUIET )) ; then 563 | enable_stdout 564 | fi 565 | --------------------------------------------------------------------------------