#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## genmkfile - make-helper-bsh - version 1.7

## This is a copy.
## master location:
## https://github.com/Whonix/genmkfile/blob/master/usr/bin/genmkfile

#set -x

## Code duplication. Copied from
## helper-scripts/usr/libexec/helper-scripts/check_runtime.bsh.
##
## Because check_runtime.bsh cannot be sourced here (the build host may not
## have helper-scripts installed).
was_executed() {
  local caller_bash_source_zero="${1}"
  if [[ "${caller_bash_source_zero}" == "${0}" ]] \
    || [[ "${caller_bash_source_zero}" == "$(command -v "${0}")" ]]; then
    return 0
  fi
  return 1
}

if [ "$GENMKFILE_DEBUG" = "1" ]; then
   set -x
fi

grep_no_comments() {
   ## Not using end-of-options ("--") for the first invocation of 'grep',
   ## because it is up to the caller of this function to use it or not.
   grep "$@" | grep --invert-match -- "^#"
}

make_log_and_run() {
   printf "%s\n" "${green}$0: running:${reset} $*"
   "$@"
}

make_init() {
   ## For manual invocation.
   ## Should be set by makefile already.
   [ -n "$GENMKFILE_PATH" ] || GENMKFILE_PATH="/usr/share/genmkfile"
   export GENMKFILE_PATH

   pwd="$(pwd)"
   ## Example pwd:
   ## ~/derivative-maker/packages/kicksecure/genmkfile
   dirname_pwd="$(dirname -- "$pwd")"
   ## Example dirname_pwd:
   ## ~/derivative-maker/packages/kicksecure
   parent_folder="$(basename -- "$dirname_pwd")"
   ## Example parent_folder:
   ## kicksecure
   derivative_repository_name="$parent_folder"
   ## derivative_repository_name is read by dm-reprepro-wrapper
   export derivative_repository_name

   ## No longer in use.
   #pushd "$GENMKFILE_ROOT_DIR" >/dev/null

   genmkfile_temp_dir="$(mktemp --directory)"
}

make_deinit() {
   safe-rm -r -f -- "$genmkfile_temp_dir"
}

make_parse_cmd() {
   ## Thanks to:
   ## http://mywiki.wooledge.org/BashFAQ/035

   local matched="false"
   local deb

   while :
   do
       case $1 in
           help)
               matched="true"
               make_function_run make_help
               shift
               ;;
           all)
               matched="true"
               make_function_run make_all "$@"
               shift
               ;;
           dist)
               matched="true"
               make_function_run make_dist
               shift
               ;;
           test)
               matched="true"
               make_function_run make_test
               shift
               ;;
           undist)
               matched="true"
               make_function_run make_undist
               shift
               ;;
           debdist)
               matched="true"
               make_function_run make_debdist
               shift
               ;;
           undebdist)
               matched="true"
               make_function_run make_undebdist
               shift
               ;;
           debdsc)
               matched="true"
               make_function_run make_debdsc
               shift
               ;;
           undebdsc)
               matched="true"
               make_function_run make_undebdsc
               shift
               ;;
           debinstfile)
               matched="true"
               make_function_run make_debinstfile
               shift
               ;;
           manpages)
               matched="true"
               make_function_run make_manpages
               shift
               ;;
           uch)
               matched="true"
               make_function_run make_uch
               shift
               ;;
           install)
               matched="true"
               make_function_run make_install
               shift
               ;;
           deb-build-dep)
               matched="true"
               make_function_run make_deb-build-dep
               shift
               ;;
           deb-run-dep)
               matched="true"
               make_function_run make_deb-run-dep
               shift
               ;;
           deb-all-dep)
               matched="true"
               make_function_run make_deb-all-dep
               shift
               ;;
           deb-pkg-build)
               matched="true"
               make_function_run make_deb-pkg-build
               shift
               ;;
           deb-install)
               matched="true"
               make_function_run make_deb-install
               shift
               ;;
           deb-remove)
               matched="true"
               make_function_run make_deb-remove
               shift
               ;;
           deb-purge)
               matched="true"
               make_function_run make_deb-purge
               shift
               ;;
           deb-clean)
               matched="true"
               make_function_run make_deb-clean
               shift
               ;;
           deb-cleanup)
               matched="true"
               make_function_run make_deb-cleanup
               shift
               ;;
           lintian)
               matched="true"
               make_function_run make_lintian
               shift
               ;;
           dput-ubuntu-ppa)
               matched="true"
               make_function_run make_dput-ubuntu-ppa
               shift
               ;;
           clean)
               matched="true"
               make_function_run make_clean
               shift
               ;;
           distclean)
               matched="true"
               make_function_run make_distclean
               shift
               ;;
           checkout)
               matched="true"
               make_function_run make_checkout
               shift
               ;;
           installcheck)
               matched="true"
               make_function_run make_installcheck
               shift
               ;;
           installsim)
               matched="true"
               make_function_run make_installsim
               shift
               ;;
           uninstallcheck)
               matched="true"
               make_function_run make_uninstallcheck
               shift
               ;;
           uninstall)
               matched="true"
               make_function_run make_uninstall
               shift
               ;;
           uninstallsim)
               matched="true"
               make_function_run make_uninstallsim
               shift
               ;;
           deb-chl-bumpup-major)
               matched="true"
               make_function_run make_deb-chl-bumpup-major
               shift
               ;;
           deb-chl-bumpup-manual)
               matched="true"
               make_function_run make_deb-chl-bumpup-manual
               shift
               ;;
           deb-uachl-bumpup-major)
               matched="true"
               make_function_run make_deb-uachl-bumpup-major
               shift
               ;;
           deb-uachl-bumpup-manual)
               matched="true"
               make_function_run make_deb-uachl-bumpup-manual
               shift
               ;;
           deb-uachl-commit-changelog)
               matched="true"
               make_function_run make_deb-uachl-commit-changelog
               shift
               ;;
           git-tag-show)
               matched="true"
               make_function_run make_git_tag_show
               shift
               ;;
           git-tag-sign)
               matched="true"
               make_function_run make_git_tag_sign
               shift
               ;;
           git-tag-verify)
               matched="true"
               make_function_run make_git_tag_verify
               shift
               ;;
           git-tag-check)
               matched="true"
               make_function_run make_git_tag_check
               shift
               ;;
           git-commit-verify)
               matched="true"
               make_function_run make_git_commit_verify_current
               shift
               ;;
           git-verify)
               matched="true"
               make_function_run make_git_verify
               shift
               ;;
           git-tag-push)
               matched="true"
               make_function_run make_git_tag_push
               shift
               ;;
           git-tag-show-latest)
               matched="true"
               make_function_run make_git_tag_show_latest
               shift
               ;;
           git-tag-push-latest)
               matched="true"
               make_function_run make_git_tag_push_latest
               shift
               ;;
           reprepro-add)
               matched="true"
               make_function_run make_reprepro-add
               shift
               ;;
           reprepro-remove)
               matched="true"
               make_function_run make_reprepro-remove
               shift
               ;;
           --)
               true "$0: end-of-options"
               shift
               break
               ;;
           -*)
               printf "%s\n" "$0: ${red}${bold}ERROR:${reset} (FUNCNAME: '$FUNCNAME') unknown option: $1" >&2
               exit 1
               ;;
           *)
               true "$0: positional parameter: $@"
               break
               ;;
       esac
   done

   ## If there are input files (for example) that follow the options, they
   ## will remain in the "$@" positional parameters.

   local args
   args="$@"

   if [ "$args" = "" ]; then
      make_function_run make_all
      return 0
   fi

   if [ ! "$matched" = "true" ]; then
      make_function_run "$@"
   fi
}

make_dependencies_filter_helper() {
   local temp to_remove
   temp="$@"
   for to_remove in '${shlibs:Depends}' '${misc:Depends}' '${python:Depends}' '${python3:Depends}' '|' ; do
      temp="${temp//"$to_remove"/""}"
   done
   printf "%s\n" "$temp"
}

make_get_variables() {
   if [ "${#make_folder_list_for_un_and_install[@]}" -eq 0 ]; then
      make_folder_list_for_un_and_install=(bin boot dev etc home lib opt sbin srv sys usr var)
   fi

   my_user_id="$(id -u)"
   if [ "$my_user_id" = "0" ]; then
      running_as_root_maybe="Running as ${under}root${eunder}. ($my_user_id)"
   else
      running_as_root_maybe="Running as ${under}user${eunder}. ($my_user_id)"
   fi

   ## Deterministic.
   LC_ALL=C.UTF-8
   TZ=UTC
   export LC_ALL TZ

   ## XXX: maybe better set dynamically but would that be deterministic?
   [ -n "$XZ_OPT" ] || XZ_OPT="--threads=8"
   export XZ_OPT

   local temp dpkg_line
   if ! command -v dpkg-parsechangelog >/dev/null ; then
      true 'dpkg-parsechangelog not found. Do you have the "build-essential" package installed?
To install all dependencies, try running:
sudo genmkfile deb-all-dep
'
      exit 1
   fi

   ## sets: architecture_of_source_package
   ## sets: make_debian_control_file_relative_path
   ## sets: make_debian_control_file_absolute_path
   ## sets: dpkg_print_architecture
   source "$GENMKFILE_PATH/shared.bsh"
   make_shared_function

   make_debian_changelog_file_relative_path="debian/changelog"
   make_debian_changelog_file_absolute_path="$(realpath "$make_debian_changelog_file_relative_path")"
   test -f "$make_debian_changelog_file_absolute_path"

   ## Thanks to jakob for the perl lines.
   ## http://unix.stackexchange.com/users/20977/jakob
   ## http://unix.stackexchange.com/a/215919/49297

   make_deb_build_dependencies="$(perl -ne 'next if /^#/; $p=(s/^Build-Depends:\s*/ / or (/^ / and $p)); s/,|\n|\([^)]+\)//mg; print if $p' < "$make_debian_control_file_absolute_path")"
   make_deb_build_dependencies="$(make_dependencies_filter_helper "$make_deb_build_dependencies")"

   make_deb_build_dependencies=${make_deb_build_dependencies//"[linux-any]"}
   make_deb_build_dependencies=${make_deb_build_dependencies//"[all]"}

   make_deb_runtime_dependencies="$(perl -ne 'next if /^#/; $p=(s/^Depends:\s*/ / or (/^ / and $p)); s/,|\n|\([^)]+\)//mg; print if $p' < "$make_debian_control_file_absolute_path")"
   make_deb_runtime_dependencies="$(make_dependencies_filter_helper "$make_deb_runtime_dependencies")"

   while read -r -d $'\n' dpkg_line; do
      true "dpkg_line: $dpkg_line"
      ## Example dpkg_line:
      ## Version: 0.1-1
      ## Version: 1:20240810
      read -r first second _ <<< "$dpkg_line"
      ## Example first:
      ## Version:
      ## Example second:
      ## 3:0.1-1
      ## Example second:
      ## 1:20240810
      first="${first,,}"
      true "first: $first"
      true "second: $second"

    if [ "$first" = "version:" ]; then
         make_changelog_version="$second"
         ## Example make_changelog_version:
         ## 3:0.1-1
         ## 0.1-1
         ## 1:20240810

         if [[ "$make_changelog_version" == *-* ]]; then
            make_pkg_revision="${make_changelog_version#*-}"
            ## prepend '-'
            make_pkg_revision="-${make_pkg_revision}"
            temp="${make_changelog_version%-*}"
         else
            make_pkg_revision=""
            temp="$make_changelog_version"
         fi

         ## Parse version (strip epoch if present)
         make_pkg_version="${temp#*:}"

         ## Parse epoch (if present)
         if [[ "$make_changelog_version" == *:* ]]; then
            make_epoch="${temp%:*}"
         else
            make_epoch=""
         fi

         ## Debugging outputs
         true "make_changelog_version: $make_changelog_version"
         true "make_pkg_revision: $make_pkg_revision"
         true "make_pkg_version: $make_pkg_version"
         true "make_epoch: $make_epoch"
         break
      fi
   done < <( dpkg-parsechangelog )

   if [ "$make_pkg_version" = "" ]; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') variable make_pkg_version is empty."
      exit 1
   fi

   make_pkg_version_with_revision="${make_pkg_version}${make_pkg_revision}"

   if [ "$make_pkg_use_pkg_version_without_revision_for_git_version" = "true" ]; then
      ## used for derivative-maker
      make_git_tag_version_number="$make_pkg_version"
   else
      ## default for all packages
      make_git_tag_version_number="$make_pkg_version_with_revision"
   fi
   ## make_git_tag_sign_appendix gets set by dm-bump-derivative-maker-version
   make_git_tag_version_number="${make_git_tag_version_number}${make_git_tag_sign_appendix}"

   [ -n "$host_architecture" ] || host_architecture="$dpkg_print_architecture"
   [ -n "$target_architecture" ] || target_architecture="$dpkg_print_architecture"

   if [ "$binary_package_architecture" = "" ]; then
      if [ "$architecture_of_source_package" = "all" ]; then
         ## binary_package_architecture=all
         binary_package_architecture="$architecture_of_source_package"
      else
         binary_package_architecture="$target_architecture"
      fi
   fi

   local grep_line a package

   grep_line="$(grep_no_comments "^Source:" -- "$make_debian_control_file_absolute_path")"
   read -r a package _ <<< "$grep_line"
   make_source_package_name="$package"
   ## Source package name may or may not match binary package name.
   make_package_list="$make_source_package_name"
   make_package_debs_files_list=""

   make_debian_non_package_specific_install_file_relative_path="debian/install"
   make_debian_install_file_relative_path="debian/${make_source_package_name}.install"

   ## Example grep_output:
   ## Package: kicksecure-vm-gui-lxqt

   while read -r -d $'\n' grep_line; do
      read -r a package _ <<< "$grep_line"
      true "package: $package"
      true "make_pkg_version: $make_pkg_version"
      true "make_pkg_revision: $make_pkg_revision"
      true "binary_package_architecture: $binary_package_architecture"
      ## Example architecture independent "all" package: anon-apt-sources-list_3.4-1_all.deb
      temp="${package}_${make_pkg_version}${make_pkg_revision}_${binary_package_architecture}.deb"
      temp="${DISTDIR}/$temp"
      make_package_debs_files_list="$make_package_debs_files_list $temp"
      if [ "$package" = "$make_source_package_name" ]; then
         continue
      fi
      make_package_list="$make_package_list $package"
   done < <( grep_no_comments "^Package:" -- "$make_debian_control_file_absolute_path" )

   true "make_package_list: $make_package_list"
   true "make_package_debs_files_list: $make_package_debs_files_list"

   make_main_deb_file_name="${package}_${make_pkg_version}${make_pkg_revision}_${binary_package_architecture}.deb"
   make_main_deb_file="${DISTDIR}/$make_main_deb_file_name"

   make_main_dsc_file_name="${make_source_package_name}_${make_pkg_version}${make_pkg_revision}.dsc"

   ## Changes file contains target_architecture such as 'amd64', not 'all'.
   ## Example changes file for architecture independent package:
   ## anon-apt-sources-list_3.4-1_amd64.changes
   if [ "$make_use_cowbuilder" = "true" ]; then
      make_main_dsc_file="$DISTDIR/$make_main_dsc_file_name"
      make_main_changes_file="$DISTDIR/${make_source_package_name}_${make_pkg_version}${make_pkg_revision}_${target_architecture}.changes"
   else
      make_main_dsc_file="${DISTDIR}/$make_main_dsc_file_name"
      make_main_changes_file="${DISTDIR}/${make_source_package_name}_${make_pkg_version}${make_pkg_revision}_${target_architecture}.changes"
   fi

   make_debian_tarball_file_name="${make_source_package_name}_${make_pkg_version}${make_pkg_revision}.debian.tar.xz"
   make_debian_tarball="${DISTDIR}/$make_debian_tarball_file_name"
   if [ "$make_debdist_tolower" = "false" ]; then
      true
   else
      make_debian_tarball_file_name="${make_debian_tarball_file_name,,}"
      make_debian_tarball="${make_debian_tarball,,}"
   fi
   make_debian_tarball_absolute_path="$(realpath "$make_debian_tarball")"

   make_upstream_tarball_relative_path_file_name="${make_source_package_name}_${make_pkg_version}.orig.tar.xz"
   make_upstream_tarball_relative_path="${DISTDIR}/$make_upstream_tarball_relative_path_file_name"
   if [ "$make_upstream_tarball_relative_path_tolower" = "false" ]; then
      true
   else
      make_upstream_tarball_relative_path_file_name="${make_upstream_tarball_relative_path_file_name,,}"
      make_upstream_tarball_relative_path="${make_upstream_tarball_relative_path,,}"
   fi
   make_upstream_tarball_real_path="$(realpath "$make_upstream_tarball_relative_path")"

   make_upstream_tarball_source_folder_name="${make_source_package_name}-${make_pkg_version}"
}

make_get_destdir() {
   if [ "$DESTDIR" = "" ]; then
      DESTDIR="/"
   fi
   if type -t make_hook_at_the_end_of_get_destdir ; then
      make_hook_at_the_end_of_get_destdir
   fi
}

make_get_distdir() {
   if [ "$DISTDIR" = "" ]; then
      DISTDIR=".."
   fi

   if [ "$make_use_cowbuilder" = "true" ]; then
      if [ "$make_cowbuilder_dist_folder" = "" ]; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') make_use_cowbuilder=$make_use_cowbuilder, so environment variable make_cowbuilder_dist_folder needs to be set! For example:"
         printf "%s\n" "make_use_cowbuilder=$make_use_cowbuilder make_cowbuilder_dist_folder=~/genmkfile-packages-result"
         exit 1
      else
         DISTDIR="$make_cowbuilder_dist_folder"
      fi

      if ! test -d "$make_cowbuilder_dist_folder" ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') make_cowbuilder_dist_folder $make_cowbuilder_dist_folder does not exist! Run:
mkdir -p -- $make_cowbuilder_dist_folder"
         exit 1
      fi
   fi

   if ! test -d "$DISTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DISTDIR '$DISTDIR' does not exist!"
      exit 1
   fi
   if ! test -w "$DISTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DISTDIR '$DISTDIR' is not writeable!"
      exit 1
   fi
}

make_help() {
   set +x
   printf "%s\n" "\
genmkfile help
   Show this help.
genmkfile dist
   Create package-version.tar.xz from source files in \$DISTDIR (default \"..\").
genmkfile undist
   Delete package-version.tar.xz from source files in \$DISTDIR (default \"..\").
genmkfile debdist
   Create debian.tar.xz from source files in \$DISTDIR (default \"..\").
genmkfile undebdist
   Delete debian.tar.xz from source files in \$DISTDIR (default \"..\").
genmkfile debdsc
   Create dsc file \$DISTDIR (default \"..\").
genmkfile undebdsc
   Deletes dsc file \$DISTDIR (default \"..\").
genmkfile debinstfile
   Creates files debian/pkg-name.install.
genmkfile manpages
   Create man page from man source folder, which will be stored in auto-generated-man-pages folder.
genmkfile uch
   Store upstream changelog from git log in changelog.upstream.
genmkfile install
   Copying the files from the source tree to system-wide directories.
genmkfile installsim
   Simulate copying the files from the source tree to system-wide directories.
genmkfile deb-build-dep
   Install build dependencies listed in debian/control under Build-Depends using apt-get.
   Various environment variables supported.
genmkfile deb-run-dep
   Install runtime dependencies listed in debian/control under Depends using apt-get.
   Various environment variables supported.
genmkfile deb-all-dep
   Combination of deb-build-dep and deb-build-dep.
genmkfile deb-pkg-build
   Create a deb, which will be stored in parent folder.
genmkfile deb-install
   Install deb from parent folder.
genmkfile deb-icup
   Combination of genmkfile deb-cleanup, deb-pkg-build, genmkfile deb-pkg-install and genmkfile deb-pkg-cleanup.
   icup stands for install and cleanup.
genmkfile deb-remove
   apt-get remove make_source_package_name
genmkfile deb-purge
   apt-get purge make_source_package_name
genmkfile deb-clean
   Delete temporary debhelper files.
genmkfile deb-cleanup
   Same as genmkfile deb-clean and deletes debuild artifacts from parent folder.
genmkfile dput-ubuntu-ppa
   Upload to Ubuntu ppa. Requires functional .dput.cf.
genmkfile distclean
   Currently same as genmkfile clean.
genmkfile checkout
   Fetch from git.
genmkfile installcheck
   Check if source files match installed files.
genmkfile uninstallcheck
   Check if genmkfile uninstall removed all files.
genmkfile uninstall
   Delete all installed files.
genmkfile uninstallsim
   Simulate what genmkfile uninstall would do.
genmkfile deb-chl-bumpup-manual
   Manual upstream version number in debian/changelog.
genmkfile deb-uachl-bumpup-manual
   Combination of genmkfile uch and genmkfile deb-chl-bumpup.
genmkfile deb-chl-bumpup-major
   Major bump upstream version number in debian/changelog.
genmkfile deb-uachl-bumpup-major
   Combination of genmkfile uch and genmkfile deb-chl-bumpup.
genmkfile git-tag-show
   echo the current git tag to stdout.
genmkfile git-tag-sign
   git tag (-s) sign latest pkg_version_with_revision from debian/changelog. Only a repository sanity check. Not for security purposes!
genmkfile git-tag-verify
   git tag (-v) verify latest pkg_version_with_revision from debian/changelog. Only a repository sanity check. Not for security purposes!
genmkfile git-tag-check
   Check if current git tag is a signed git tag. Only a repository sanity check. Not for security purposes!
genmkfile git-commit-verify
   Check if current git head is a signed git commit. Only a repository sanity check. Not for security purposes!
genmkfile git-verify
   Combination of tag-check and commit-verify. Only a repository sanity check. Not for security purposes!
genmkfile git-tag-push
   git push latest pkg_version_with_revision from debian/changelog. (Environment variable make_git_tag_push_targets, that defaults to 'origin'.)
genmkfile git-tag-show-latest
   echo recent git tag to stdout.
genmkfile git-tag-push-latest
   git push most recent git tag. (Environment variable make_git_tag_push_targets, that defaults to 'origin'.)
genmkfile reprepro-add
   Add main deb package using reprepro wrapper (Environment variable make_reprepro_wrapper, that default to 'reprepro'.)
   to repository (Environment variable dist_build_apt_codename, that defaults to 'local'.).
genmkfile reprepro-remove
   Delete.

multiple architecture builds examples:

make_use_cowbuilder=true make_cross_build_platform_list='amd64 arm64' genmkfile deb-pkg

make_use_cowbuilder=true make_cross_build_platform_list='amd64' genmkfile deb-pkg"
}

make_all() {
   if [ -f "$PWD/Makefile_orig" ]; then
      make -f "$PWD/Makefile_orig" all "$@"
   fi
}

make_dist() {
   local empty_directories

   #find "." -not -iwholename '*.git*' -exec touch --no-dereference --date="Wed Sep 30 16:30:05 UTC 2015" {} +

   ## No longer using --transform because that does not work with symlinks.
   ## (Important for 'corridor' package.)

   if ! test -d "$DISTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DISTDIR '$DISTDIR' does not exist!"
      exit 1
   fi
   if ! test -w "$DISTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DISTDIR '$DISTDIR' is not writeable!"
      exit 1
   fi

   ## Debugging.
   test -w "$(pwd)"
   touch "$make_upstream_tarball_real_path"
   test -w "$make_upstream_tarball_real_path"
   safe-rm -f -- "$make_upstream_tarball_real_path"

   empty_directories="$(find "." -not -ipath '*.git*' -type d -empty)"

   if ! [ "${empty_directories}" = "" ]; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} Empty directory found! empty_directories:
'${empty_directories}'"
      exit 1
   fi

   printf "%s\n" "$0: DEBUG manual reproduction:
cd $(pwd)"

   ## Excluding '/debian' folder from upstream tarball to avoid lintian warning
   ## 'no-debian-changes'.

   msg="DEBUG manual reproduction:
find \
      '.' \
      -not -path '*/\.git/*' \
      -not -path '*/\.git' \
      -not -name '.gitignore' \
      -not -path './debian*' \
      -print0 \
         | tar \
            --null \
            --no-recursion \
            --create \
            --owner=0 --group=0 --numeric-owner \
            --mode=go=rX,u+rw,a-s \
            --sort=name \
            --mtime='2015-10-21 00:00Z' \
            --xz \
            --file='$make_upstream_tarball_real_path' \
            -T \
            -
   "

   msg="$(printf "%s\n" "$msg" | sed 's/  */ /g')"
   printf "%s\n" "$msg"

   find \
      '.' \
      -not -path '*/\.git/*' \
      -not -path '*/\.git' \
      -not -name '.gitignore' \
      -not -path './debian*' \
      -print0 \
         | tar \
            --null \
            --no-recursion \
            --create \
            --owner=0 --group=0 --numeric-owner \
            --mode=go=rX,u+rw,a-s \
            --sort=name \
            --mtime='2015-10-21 00:00Z' \
            --xz \
            --file="$make_upstream_tarball_real_path" \
            -T \
            -

   strip-nondeterminism "$make_upstream_tarball_real_path"

   test -f "$make_upstream_tarball_real_path"
}

make_debdist() {
   #find "." -not -iwholename '*.git*' -exec touch --no-dereference --date="Wed Sep 30 16:30:05 UTC 2015" {} +

   ## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657401
   ## Not using `dpkg-source` since that does not support any other output dir than '../'.

   find \
      debian \
      -print0 \
         | tar \
            --null \
            --no-recursion \
            --create \
            --owner=0 --group=0 --numeric-owner \
            --mode=go=rX,u+rw,a-s \
            --sort=name \
            --mtime='2015-10-21 00:00Z' \
            --xz \
            --file="$make_debian_tarball_absolute_path" \
            -T \
            -

   strip-nondeterminism "$make_debian_tarball_absolute_path"

   test -f "$make_debian_tarball_absolute_path"
}

make_undist() {
   safe-rm --force -- "$make_upstream_tarball_relative_path"
}

make_debdsc() {
   if ! test -d "$DISTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DISTDIR '$DISTDIR' does not exist!"
      exit 1
   fi
   if ! test -w "$DISTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DISTDIR '$DISTDIR' is not writeable!"
      exit 1
   fi

   pushd "$DISTDIR" >/dev/null

   ## Creates make_main_dsc_file.
   make_log_and_run \
      dpkg-source \
         -c"$make_debian_control_file_absolute_path" \
         -l"$make_debian_changelog_file_absolute_path" \
         --format="3.0 (custom)" \
         --target-format="3.0 (quilt)" \
         -b / \
         "$make_upstream_tarball_real_path" \
         "$make_debian_tarball_absolute_path"

   popd >/dev/null

   test -f "$make_main_dsc_file"
}

make_undebdsc() {
   safe-rm --force -- "$make_main_dsc_file"
}

make_undebdist() {
   safe-rm --force -- "$make_debian_tarball_absolute_path"
}

make_debinstfile() {
   local line d missing

   ## calamares-settings-debian comes with debian/install by upstream default.
   ## If file debian/calamares-settings-debian.install was created, that would result in debian/install
   ## being ignored and in an empty package. Therefore, if debian/install already exists, do not
   ## automatically create a debian/package-name.install file.
   if test -f "$make_debian_non_package_specific_install_file_relative_path" ; then
      return 0
   fi

   if test -f "$make_debian_install_file_relative_path" ; then
      if grep --quiet -- "nogenmkfile" "$make_debian_install_file_relative_path" ; then
         return 0
      fi
   fi

   make_debinstfile_create
}

make_debinstfile_create() {
   local new_file filename_without_hash cleaned_filename_without_hash pkg_name \
   temp_deb_install_file real_deb_instal_file destination_directory
   local -a find_cmd
   local -A delete_yet

   find_cmd+=(find)
   find_cmd+=(.)
   find_cmd+=(-not -path '*/\.git/*')
   find_cmd+=(-not -path '*/\.git')
   find_cmd+=(-not -name '.gitignore')
   find_cmd+=(-not -path './debian*')
   find_cmd+=(-iname '*#*')

   if "${find_cmd[@]}" | grep --fixed-strings -- '#' >/dev/null; then
      true "multi-package hash filename found: yes"
      find_cmd+=(-print0)

      "${find_cmd[@]}" | LC_ALL='C' sort -z | \
         while IFS= read -r -d '' file_name; do
            filename_without_dot="${file_name#./}"
            filename_without_hash="${file_name%%#*}"
            cleaned_filename_without_hash="${filename_without_hash/#.\//\/}"
            destination_directory="${cleaned_filename_without_hash%/*}"
            pkg_name="${file_name#*#}"
            temp_deb_install_file="${genmkfile_temp_dir}/${pkg_name}.install"

            if [ -z "${delete_yet[$pkg_name]}" ]; then
                safe-rm -f -- "$temp_deb_install_file"
                delete_yet["${pkg_name}"]=true
                printf "%s\n" "\
#!/usr/bin/dh-exec

## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## This file was generated using 'genmkfile debinstfile'.
" | sponge -a -- "$temp_deb_install_file"
                chmod -- +x "$temp_deb_install_file"
            fi

            printf "%s\n" "${filename_without_dot} => ${cleaned_filename_without_hash}" | sponge -a -- "$temp_deb_install_file"
         done

        for new_file in "$genmkfile_temp_dir"/*.install; do
            real_deb_instal_file="debian/$(basename "$new_file")"
            if [ -f "$real_deb_instal_file" ]; then
                if cmp -s "$new_file" "$real_deb_instal_file"; then
                    continue
                fi
            fi
            cp -- "$new_file" "$real_deb_instal_file"
        done

   else
      true "multi-package hash filename found: no"
      temp_deb_install_file="${genmkfile_temp_dir}/pkg.install"
      real_deb_instal_file="$make_debian_install_file_relative_path"
      printf "%s\n" "\
## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## This file was generated using 'genmkfile debinstfile'.
" | sponge -a -- "$temp_deb_install_file"
      local d
      for d in "${make_folder_list_for_un_and_install[@]}"; do
         if [ -d "$d" ]; then
            printf "%s\n" "${d}/*" | sponge -a -- "$temp_deb_install_file"
         fi
      done
      if cmp -s "$temp_deb_install_file" "$real_deb_instal_file"; then
         return 0
      fi
      cp -- "$temp_deb_install_file" "$real_deb_instal_file"
   fi
}

make_test() {
   ## Automatically run by debhelper. To prevent debhelper from failing,
   ## implemented a dummy function here.
   printf "%s\n" "${green}$0: INFO:${reset} $FUNCNAME not implemented"
}

make_manpages() {
   shopt -s globstar dotglob nullglob
   local i source_folder filename_without_ronn_file_extension base_name
   for i in "$PWD/man/"*".ronn"; do
      if [ -d "$i" ]; then
         continue
      fi

      base_name="${i##*/}"
      filename_without_ronn_file_extension="${base_name%.*}"

      mkdir --parents -- "$PWD/auto-generated-man-pages/$source_folder"

      true "${bold}${cyan}${green}INFO:${reset} Creating man page $PWD/auto-generated-man-pages/$filename_without_ronn_file_extension ${reset}"

      ## '--date=2020-01-01' for deterministic man pages.
      ronn \
         --date=2020-01-01 \
         --manual="$make_source_package_name Manual" \
         --organization="$make_source_package_name" \
         -- \
         < "$i" \
         > "$PWD/auto-generated-man-pages/$filename_without_ronn_file_extension"

   done
   shopt -u globstar dotglob nullglob
}

make_uch() {
   if test -f "$PWD/CHANGES" ; then
      return 0
   fi
   git log | sponge -- "$PWD/changelog.upstream"
   test -f "$PWD/changelog.upstream"
}

make_distclean() {
   printf "%s\n" "$0: ${green}INFO:${reset} (internal) genmkfile distclean"
   make_clean
}

make_clean() {
   if [ -f "$PWD/Makefile_orig" ]; then
      make -f "$PWD/Makefile_orig" clean
   else
      if make --dry-run clean &>/dev/null ; then
         printf "%s\n" "$0: ${green}INFO:${reset} (internal) make clean"
         make clean
      else
         printf "%s\n" "$0: ${green}INFO:${reset} no target 'make clean', ok."
      fi
   fi
}

make_deb-shared-dep() {
   local msg apt_get_exit_code

   ## TODO: check if sudo is available.

   msg="sudo \
      apt-get \
         "${APTGETOPT[@]}" \
         --yes \
         --no-install-recommends \
         --allow-downgrades \
         install \
         -- \
         $make_deb_shared_dependencies"

   msg="$(printf "%s\n" "$msg" | sed 's/  */ /g')"
   printf "%s\n" "$msg"

   apt_get_exit_code="0"
   sudo \
      apt-get \
         "${APTGETOPT[@]}" \
         --yes \
         --no-install-recommends \
         --allow-downgrades \
         install \
         -- \
         $make_deb_shared_dependencies \
         || { apt_get_exit_code="$?" ; true; };

   exit "$apt_get_exit_code"
}

make_deb-build-dep() {
   make_deb_shared_dependencies="$make_deb_build_dependencies"
   make_function_run make_deb-shared-dep
}

make_deb-run-dep() {
   make_deb_shared_dependencies="$make_deb_runtime_dependencies"
   make_function_run make_deb-shared-dep
}

make_deb-all-dep() {
   make_deb_shared_dependencies="$make_deb_build_dependencies $make_deb_runtime_dependencies"
   make_function_run make_deb-shared-dep
}


make_dpkg_source_verification_sanity_test_help_message() {
   printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') dpkg-source verification failed!

To add you could use for example...

If using gpg (GnuPG):
- Does your key exist in file '~/.gnupg/trustedkeys.gpg'?
- to add, run:
gpg --no-default-keyring --keyring trustedkeys.gpg --import ~/derivative-maker/packages/kicksecure/repository-dist/usr/share/keyrings/derivative.asc

If using sq (Sequoia-PGP):
- to add, run:
1.
sudo apt install debian-keyring
2.
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/debian-maintainers.gpg --import ~/derivative-maker/packages/kicksecure/repository-dist/usr/share/keyrings/derivative.asc
"
}

make_deb-pkg-build_shared() {
   if [ "$make_use_cowbuilder" = "true" ]; then
      if ! test -f "$make_upstream_tarball_real_path" ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') upstream tarball $make_upstream_tarball_real_path does not exist.
Did you run
genmkfile dist && genmkfile debdist && genmkfile debdsc
beforehand?
"
         exit 1
      fi

      if ! test -f "$make_debian_tarball_absolute_path" ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') debian tarball $make_debian_tarball_absolute_path does not exist.
Did you run
genmkfile dist && genmkfile debdist && genmkfile debdsc
beforehand?
"
         exit 1
      fi

      if ! test -f "$make_main_dsc_file" ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') dsc file $make_main_dsc_file does not exist.
Did you run
genmkfile dist && genmkfile debdist && genmkfile debdsc
beforehand?
"
         exit 1
      fi

      true "COWBUILDER_PREFIX: $COWBUILDER_PREFIX"

      if [ ! "$dist_build_apt_stable_release" = "" ]; then
         [ -n "$make_cowbuilder_distribution" ] || make_cowbuilder_distribution="$dist_build_apt_stable_release"
      else
         [ -n "$make_cowbuilder_distribution" ] || make_cowbuilder_distribution="$(lsb_release --short --codename)"
      fi

      ## Whonix build script sets variable `make_cowbuilder_mirror`.

      if [ ! "$dist_build_apt_sources_mirror" = "" ]; then
         [ -n "$make_cowbuilder_mirror" ] || make_cowbuilder_mirror="$dist_build_apt_sources_mirror"
      else
         ## approx caching proxy support
         if [ "$APPROX_PROXY_ENABLE" = "yes" ]; then
            ## TODO: Use the derivative-maker specific proxy at port 9977, or
            ## the system-wide proxy at port 9999?
            [ -n "$make_cowbuilder_mirror" ] || make_cowbuilder_mirror="http://127.0.0.1:9977/debian"
         fi
         [ -n "$make_cowbuilder_mirror" ] || make_cowbuilder_mirror="https://deb.debian.org/debian"
      fi

      ## TODO: change that folder
      cow_folder="/var/cache/pbuilder/cow.cow_${target_architecture}"
      base_folder="/var/cache/pbuilder/base.cow_${target_architecture}"

      if [ ! "$dist_build_pbuilder_config_file" = "" ]; then
         make_cowbuilder_config_file_arg="--configfile $dist_build_pbuilder_config_file"
      fi

      ## Using cowbuilder with
      ## --host-arch "$host_architecture" \
      ## --architecture "$dist_build_target_arch" \
      ## can cause the following build error:
      ## The following packages have unmet dependencies:
      ## builddeps:/build/anon-apps-config_3.0-1.dsc:amd64 : Depends: genmkfile:amd64 but it is not installable
      ##
      ## Test command:
      ## dist_build_pbuilder_config_file=/home/user/derivative-binary/pbuilder.conf make_cross_build_platform_list=arm64 make_cowbuilder_dist_folder=~/genmkfile-packages-result make_use_cowbuilder=true genmkfile deb-pkg

      ## Not using '--mirror' results in cowbuilder automatically passing to pbuilder:
      ## --mirror http://you-have-broken-debconf-configuration.example.com/
      ## Not using '--distribution' results in cowbuilder automatically passing to pbuilder:
      ## --distribution sid

      ## W: --override-config is not set; not updating apt.conf Read the manpage for details.
      ## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1075960

      ## TODO: REPO_PROXY is no longer used, update this comment.
      ## COWBUILDER_PREFIX could set variables such as http_proxy.
      ## Whonix build script sets:
      ## COWBUILDER_PREFIX+=" env http_proxy=${REPO_PROXY}"
      ## which results in:
      ## sudo env http_proxy=http://127.0.0.1:9977 cowbuilder [...]
      ##
      ## creates $make_main_changes_file
      ##
      ## creates again (overwrites) $make_debian_tarball_file_name
      ##
      ## Forces the inclusion of the original source.
      ## --debbuildopts="-sa" is passed by cowbuilder to pdebuild (which passes
      ## it to debuild?) which passes it to dpkg-genchanges. In other words,
      ## results in 'dpkg-genchanges -sa'.
      ## That is required when make_pkg_revision is higher than 1. In that case
      ## by default the original source tarball would not be included by Debian
      ## default. The practice in Debian is not to upload the original source
      ## tarball if only the Debian package revision version number was
      ## increased since it would already be in the archive. That however seems
      ## incompatible with reprepro, which would show the following error:
      ## ##
      ## Unable to find pool/main/l/lkrg/lkrg_0.9.1.orig.tar.xz needed by lkrg_0.9.1-3.dsc!
      ## Perhaps you forgot to give dpkg-buildpackage the '-sa' option,
      ## or you could try --ignore=missingfile to guess possible files to use.
      ## There have been errors!
      ## ##
      ## Maybe non-ideal. '--debbuildopts="-sa" would only be required' if
      ## package revision number is higher than 1 and maybe only if there never
      ## has been package revision number 1 including upstream source tarball
      ## uploaded beforehand. Good enough.
      ##
      ## --unset=TEMP \
      ## --unset=TEMPDIR \
      ## --unset=TMP \
      ## --unset=TMPDIR \
      ## Setting TMPDIR breaks pbuilder (which gets called by cowbuilder).
      ## Installing libpam-tmpdir (security-feature) results in these variables being set.
      ## In other words:
      ## "`sudo apt install libpam-tmpdir` breaks cowbuilder"
      ## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=823651
      ## https://github.com/Kicksecure/security-misc/pull/147
      ## https://forums.whonix.org/t/make-symlink-attacks-and-other-tmp-based-attacks-harder-or-impossible-using-libpam-tmpdir/8488
      ## Installing libpam-tmpdir inside the grml-debootstrap chroot did fix a similar issue for grml-debootstrap / grub.
      ## https://github.com/grml/grml-debootstrap/issues/232
      ## Installing libpam-tmpdir inside the cowbuilder chroot did however not fix this issue.
      make_log_and_run \
         sudo \
            $COWBUILDER_PREFIX \
               cowbuilder \
                  --debbuildopts="-sa" \
                  --architecture "$target_architecture" \
                  $make_cowbuilder_config_file_arg \
                  --build "$make_main_dsc_file" \
                  --basepath "$base_folder" \
                  --buildplace "$cow_folder" \
                  --distribution "$make_cowbuilder_distribution" \
                  --mirror "$make_cowbuilder_mirror" \
                  --extrapackages "$make_deb_build_dependencies" \
                  --buildresult "$DISTDIR"

   else
      if ! command -v debuild >/dev/null ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') debuild not found. Do you have the 'devscripts' package installed?
To install all dependencies, try running:
sudo genmkfile deb-all-dep
"
         exit 1
      fi

      if ! dpkg-checkbuilddeps ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') dpkg-checkbuilddeps reported missing build dependencies.
To install all dependencies, try running:
sudo genmkfile deb-all-dep
"
         exit 1
      fi

      ## Using --no-lintian, because debuild does not exist with a non-zero exit
      ## code, should lintian find an error. Therefore running lintian afterwards.
      make_log_and_run \
         debuild \
            --no-lintian \
            -sa \
            $make_debuild_maybe_unsigned_opts \
            "$@"
   fi

   printf "%s\n" "$0: INFO: make_use_debsign: $make_use_debsign | whoami: $(whoami)"
   if [ "$make_use_debsign" = "true" ]; then
      ## For manual use for non-maintainer builds use example:
      #DEBSIGN_KEYID="FFF25C6BEA585C88D96D9AFC2E39FB8D91FDDF6A"
      #export make_debsign_opts="-k$DEBSIGN_KEYID"

      ## clearsign's $make_main_changes_file
      make_log_and_run debsign $make_debsign_opts "$make_main_changes_file"

      ## sanity test
      make_log_and_run gpg --verify "$make_main_changes_file"

      #local genmkfile_temp_dir
      #genmkfile_temp_dir="$(mktemp --directory)"
      ## Required, otherwise:
      ## dpkg-source: error: unpack target exists: /tmp/tmp.n1V3KXmMtI
      #safe-rm --recursive --force -- "$genmkfile_temp_dir"
      ## Sanity test.
      ## Broken under Trixie, disabled. See:
      ## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1110172
      ## TODO: consider re-enabling in Debian forky
      #make_log_and_run \
      #   dpkg-source \
      #      --require-strong-checksums \
      #      --require-valid-signature \
      #      -x \
      #      "$make_main_dsc_file" \
      #      "$genmkfile_temp_dir/" || \
      #         { make_dpkg_source_verification_sanity_test_help_message ; return 1; };
      #safe-rm --recursive --force -- "$genmkfile_temp_dir"
   fi

   for package in $make_package_debs_files_list; do
      if ! test -f "$package" ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') File '$package' does not exist."
         exit 1
      fi
      printf "%s\n" "$0: ${green}INFO:${reset} You can find your deb file here: ${bold}$package${reset}"
   done

   if [ "$make_use_lintian" = "false" ]; then
      printf "%s\n" "$0: ${green}INFO:${reset} make_use_lintian=false - skipping lintian."
   elif [ "$make_use_lintian" = "true" ]; then
      printf "%s\n" "$0: ${green}INFO:${reset} make_use_lintian=true - running lintian..."
      make_function_run make_lintian
   else
      printf "%s\n" "$0: ${green}INFO:${reset} make_use_lintian='' - Autodetecting if lintian is installed..."
      if command -v lintian &>/dev/null ; then
         printf "%s\n" "$0: ${green}INFO:${reset} lintian auto detected, using it..."
         make_function_run make_lintian
      else
         printf "%s\n" "$0: ${green}INFO:${reset} lintian not installed, skipping."
      fi
   fi
}

make_lintian_on_warning() {
   if [ "$make_lintian_fail_open_versus_closed" = "open" ]; then
      printf "%s\n" "$0: ${red}WARNING:${reset} lintian warning. make_lintian_fail_open_versus_closed=open - Therefore, failing open."
   else
      printf "%s\n" "$0: ${red}${bold}ERROR:${reset} (FUNCNAME: '$FUNCNAME') lintian warning. make_lintian_fail_open_versus_closed is not set to 'open' - Therefore, failing closed."
      if [ "$make_lintian_exit_code" = "0" ]; then
         exit 1
      else
         exit "$make_lintian_exit_code"
      fi
   fi
}

make_lintian() {
   if ! test -f "$make_main_changes_file" ; then
      printf "%s\n" "$0: ${red}${bold}ERROR:${reset} (FUNCNAME: '$FUNCNAME') make_main_changes_file '$make_main_changes_file' does not exist."
      exit 1
   fi
   if [ "$DEBUILD_LINTIAN_OPTS" = "" ]; then
      ## https://github.com/openwall/lkrg/pull/105
      ## --suppress-tags systemd-service-file-missing-documentation-key
      ##
      ## Building from git. Not from tarball.
      ## https://forums.whonix.org/t/end-to-end-signed-debs-debsign-debsig-and-dpkg-sig/3446
      ## --suppress-tags orig-tarball-missing-upstream-signature
      ##
      ## Removed '--suppress-tags package-supports-alternative-init-but-no-init.d-script' for Trixie, tag no longer exists.
      export DEBUILD_LINTIAN_OPTS="\
         --suppress-tags missing-tests-control \
         --suppress-tags systemd-service-file-missing-documentation-key \
         --suppress-tags orig-tarball-missing-upstream-signature \
         --suppress-tags no-manual-page \
         --quiet \
         --pedantic \
         --info \
         --display-info \
         "
   fi
   local make_lintian_exit_code="0"
   printf "%s\n" "lintian $genmkfile_lintian_pre_opts $DEBUILD_LINTIAN_OPTS $genmkfile_lintian_post_opts \"$make_main_changes_file\""
   lintian_output="$(lintian $genmkfile_lintian_pre_opts $DEBUILD_LINTIAN_OPTS $genmkfile_lintian_post_opts "$make_main_changes_file" 2>&1 || { make_lintian_exit_code="$?" ; true; };)"
   if [ ! "" = "$lintian_output" ]; then
      if ! test -o xtrace ; then
         printf "%s\n" "$0: ${green}INFO:${reset} lintian exit code: $make_lintian_exit_code"
         printf "%s\n" "$0: ${green}INFO:${reset} lintian output:"
         printf "%s\n" "################################################################################"
         printf "%s\n" "$lintian_output"
         printf "%s\n" "################################################################################"
      fi
      make_lintian_on_warning
   fi
   if [ ! "$make_lintian_exit_code" = "0" ] ; then
      make_lintian_on_warning
   else
      printf "%s\n" "$0: ${green}INFO:${reset} lintian ok."
   fi
}

make_deb-pkg-build() {
   make_debuild_maybe_unsigned_opts="-us -uc"
   make_function_run make_deb-pkg-build_shared "$@"
}

make_deb-install() {
   local package
   for package in $make_package_debs_files_list; do
      if [ ! -f "$package" ]; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') File $package does not exist. Have you run \"genmkfile deb-pkg-build\" already?"
         exit 1
      fi
      ## --reinstall is required otherwise apt-get would refuse to install the package with the following error message:
      ## Note, selecting 'systemcheck' instead of '/home/user/derivative-binary/genmkfile-packages-result/systemcheck_25.1-1_all.deb'
      ## systemcheck is already the newest version (3:25.1-1).
      make_log_and_run sudo \
         apt-get \
            "${APTGETOPT[@]}" \
            --yes \
            --no-install-recommends \
            --allow-downgrades \
            --reinstall \
            install \
            -- \
            "$package"
   done
}

make_deb-remove() {
   sudo apt-get --yes remove -- "$make_source_package_name"
}

make_deb-purge() {
   sudo apt-get --yes purge -- "$make_source_package_name"
}

make_dh_clean() {
  ## TODO: Executes arbitrary code from the working directory, is this safe?
  if [ -x debian/rules ]; then
    debian/rules clean
  fi
}

make_deb-clean() {
   if [ -d "debian/tmp" ]; then
      safe-rm --recursive -- "debian/tmp"
   fi
   if [ -d "deb_dist" ]; then
      safe-rm --recursive -- "deb_dist"
   fi
   if [ -d "debian/.debhelper" ]; then
      safe-rm --recursive -- "debian/.debhelper"
   fi
   if [ -f "debian/autoreconf.after" ]; then
      safe-rm -- "debian/autoreconf.after"
   fi
   if [ -f "debian/autoreconf.before" ]; then
      safe-rm -- "debian/autoreconf.before"
   fi
   local to_delete package
   for package in $make_package_list; do
      if [ -d "debian/$package" ]; then
         safe-rm --recursive -- "debian/$package"
      fi
      for to_delete in \
         "debian/$package.debhelper.log" \
         "debian/$package.substvars" \
         "debian/files" \
         "debian/$package.prerm.debhelper" \
         "debian/$package.preinst.debhelper" \
         "debian/$package.postinst.debhelper" \
         "debian/$package.postrm.debhelper" \
         "debian/$package.dkms.debhelper" \
         "debian/debhelper-build-stamp"
      do
         if [ -e "$to_delete" ]; then
            safe-rm -- "$to_delete"
         fi
      done
   done
}

make_deb-cleanup() {
   local to_delete package
   make_function_run make_undist
   make_function_run make_undebdist
   make_function_run make_undebdsc
   make_function_run make_clean
   make_function_run make_dh_clean
   make_function_run make_deb-clean
   for package in $make_package_list; do
      for to_delete in \
         "${DISTDIR}/${package}_"*-*_*".deb" \
         "${DISTDIR}/${package}-dbgsym_"*-*_*".deb" \
         "${DISTDIR}/${package}_"*-*_*".buildinfo" \
         "${DISTDIR}/${package}_"*-*".debian.tar.xz" \
         "${DISTDIR}/${package}_"*-*".orig.tar.xz" \
         "${DISTDIR}/${package}_"*-*".dsc" \
         "${DISTDIR}/${package}_"*-*_*".build" \
         "${DISTDIR}/${package}_"*-*_*".changes" \
         "${DISTDIR}/${package}_"*-*"_source.build" \
         "${DISTDIR}/${package}_"*-*"_source.changes" \
         "${DISTDIR}/${package}_"*-*"_source.${package}.upload"
      do
         if [ -e "$to_delete" ]; then
            safe-rm -- "$to_delete"
         fi
      done
   done
   if [ -f "$make_upstream_tarball_relative_path" ]; then
      safe-rm -- "$make_upstream_tarball_relative_path"
   fi
}

make_dput-ubuntu-ppa() {
   dput "$make_source_package_name" "${DISTDIR}/${make_source_package_name}_${make_pkg_version}${make_pkg_revision}_source.changes"
}

make_checkout() {
   git fetch
}

in_array() {
   local needle item
   needle="$1"
   shift
   true "INFO: in_array: @: |$@|"
   for item in "$@"; do
      true "INFO: in_array: item: $item"
      if [ "$item" = "$needle" ]; then
         true "INFO: in_array: found"
         return 0
      fi
   done
   true "INFO: in_array: not found"
   return 1
}

array_match() {
   local needle item
   needle="$1"
   shift
   true "INFO: array_match: @: |$@|"
   for item in "$@"; do
      true "item: $item"
      if printf "%s\n" "$needle" | grep --quiet --fixed-strings -- "$item" ; then
         true "INFO: array_match: found"
         return 0
      fi
   done
   true "INFO: array_match: not found"
   return 1
}

make_helper() {
   shopt -s globstar dotglob nullglob
   local source_directory source_fso file_without_pwd file_with_destdir

   if ! test -d "$DESTDIR" ; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DESTDIR '$DESTDIR' does not exist!"
      exit 1
   fi

   if [ ! "$make_installcheck_" = "true" ]; then
      if ! test -w "$DESTDIR" ; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') DESTDIR '$DESTDIR' is not writeable!"
         exit 1
      fi
   fi

   genmkfile_rsync_opts=()

   ## Does not work.
   #genmkfile_rsync_opts+=("--chmod=o+r")
   #genmkfile_rsync_opts+=("--executability")

   genmkfile_rsync_opts+=("--recursive") ## recurse into directories
   genmkfile_rsync_opts+=("--keep-dirlinks") ## treat symlinked dir on receiver as dir
   genmkfile_rsync_opts+=("--links") ## copy symlinks as symlinks
   genmkfile_rsync_opts+=("--hard-links") ## preserve hard links
   genmkfile_rsync_opts+=("--safe-links") ## ignore symlinks that point outside the tree
   #genmkfile_rsync_opts+=("--progress")
   #genmkfile_rsync_opts+=("--verbose")

   ## Cannot be `local` so hooks can increase it.
   #local genmkfile_file_has_been_copied
   [ -n "$genmkfile_file_has_been_copied" ] || genmkfile_file_has_been_copied=false

   folder_permission_skip_list=()
   folder_permission_skip_list+=("/etc/sudoers.d")
   folder_permission_skip_list+=("/usr/src")

   if [ "$make_installsim_" = "true" ]; then
      if [ ! -d "$DESTDIR" ]; then
         printf "%s\n" "${green}$0: INFO:${reset} would create DESTDIR '$DESTDIR': mkdir --parents -- '$DESTDIR'"
      else
         printf "%s\n" "${green}$0: INFO:${reset} No need to run, because folder DESTDIR '$DESTDIR' already exists: mkdir --parents -- '$DESTDIR'"
      fi
   fi

   for source_directory in "${make_folder_list_for_un_and_install[@]}"; do
      if [ ! -d "$source_directory" ]; then
         continue
      fi
      local rsync_done
      rsync_done=""
      for source_fso in "$PWD/$source_directory"/**; do
         genmkfile_file_has_been_copied=true
         file_without_pwd="${source_fso#$PWD}"
         ## Issue: starts with double '//'
         #file_with_destdir="${DESTDIR}${file_without_pwd}"
         ## New: single '/'
         file_with_destdir="${DESTDIR%/}/${file_without_pwd#/}"
         if [ "$make_install_" = "true" ]; then
            if [ ! -d "$DESTDIR" ]; then
               mkdir --parents -- "$DESTDIR"
            fi
            if [ ! "$rsync_done" = "true" ]; then
               ## Not using 'cp' because:
               #cp --recursive lib /
               # > cp: cannot overwrite non-directory '/lib' with directory 'lib'
               rsync "${genmkfile_rsync_opts[@]}" -- "$source_directory" "$DESTDIR"
               rsync_done=true
            fi
            ## Need to check first if it is a file...
            ## ...before checking if it is an executable.
            ## Because folders can also have executable bit.
            fso_with_destdir_stat="$(stat -c "%a" "$file_with_destdir")"
            #echo "source_fso: $source_fso"
            if test -d "$source_fso" ; then
                  if ! [ "$fso_with_destdir_stat" = "755" ]; then
                     if [ "$DESTDIR" = "/" ]; then
                        true "calling...: in_array |$file_without_pwd| |${folder_permission_skip_list[@]}|"
                        if ! in_array "$file_without_pwd" "${folder_permission_skip_list[@]}"; then
                           true "in_array did not match, therefore continuing..."
                           printf "%s\n" "$0: INFO: chmod change on folder might(!) be required, consider running the following command: chmod -- 755 '$file_with_destdir'"
                           ## Not safe due to folders such as '/etc/sudoers.d' which have chmod '700' as per Debian default.
                           #chmod -- 755 "$file_with_destdir"
                        fi
                     fi
                  fi
            elif test -f "$source_fso" ; then
               true "calling...: array_match |$file_without_pwd| |${folder_permission_skip_list[@]}|"
               if ! array_match "$file_without_pwd" "${folder_permission_skip_list[@]}"; then
                  true "array_match did not match, therefore continuing..."
                  if test -x "$source_fso" ; then
                     if ! [ "$fso_with_destdir_stat" = "755" ]; then
                        printf "%s\n" "$0: INFO: executable file found, running command...: chmod -- 755 '$file_with_destdir'"
                        chmod -- 755 "$file_with_destdir"
                     fi
                  else
                     if ! [ "$fso_with_destdir_stat" = "644" ]; then
                        printf "%s\n" "$0: INFO: non-executable file found, running command...: chmod -- 644 '$file_with_destdir'"
                        chmod -- 644 "$file_with_destdir"
                     fi
                  fi
               fi
            fi
         elif [ "$make_installsim_" = "true" ]; then
            if [ ! "$rsync_done" = "true" ]; then
               ## use '[*]' to trat as single line and avoid newlines in output
               printf "%s\n" "${green}$0: INFO:${reset} would do: rsync --dry-run ${genmkfile_rsync_opts[*]} -- \"$source_directory\" \"$DESTDIR\""
               rsync --dry-run "${genmkfile_rsync_opts[@]}" -- "$source_directory" "$DESTDIR"
               rsync_done=true
            fi
            ## chmod cannot be simulated because actually no file gets copied.
         elif [ "$make_uninstallcheck_" = "true" ]; then
            if [ -f "$file_with_destdir" ]; then
               printf "%s\n" "$0: ${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') file $file_with_destdir still installed."
               local still_installed="true"
            fi
         elif [ "$make_installcheck_" = "true" ]; then
            if test -f "$source_fso" ; then
               diff -- "$source_fso" "$file_with_destdir"
            fi
         elif [ "$make_uninstallsim_" = "true" ]; then
            if [ -f "$file_with_destdir" ]; then
               printf "%s\n" "${green}$0: INFO:${reset} would do: safe-rm --verbose -- \"$file_with_destdir\""
            fi
         elif [ "$make_uninstall_" = "true" ]; then
            if [ -f "$file_with_destdir" ]; then
               safe-rm --verbose -- "$file_with_destdir"
            fi
         else
            printf "%s\n" "$0: ${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') error 2 in $FUNCNAME!"
            exit 1
         fi
      done
   done
   shopt -u globstar dotglob nullglob
   if [ "$still_installed" = "true" ]; then
      exit 1
   fi
   if [ "$genmkfile_file_has_been_copied" = "false" ]; then
      printf "%s\n" "$0: ${red}${bold}$0: ERROR:${reset} Nothing has been copied."
      exit 1
   fi
}

make_install() {
   make_install_="true"
   make_function_run make_helper
}

make_installcheck() {
   make_installcheck_="true"
   make_function_run make_helper
}

make_installsim() {
   make_installsim_="true"
   make_function_run make_helper
}

make_uninstallcheck() {
   make_uninstallcheck_="true"
   make_function_run make_helper
}

make_uninstall() {
   make_uninstall_="true"
   make_function_run make_helper
}

make_uninstallsim() {
   make_uninstallsim_="true"
   make_function_run make_helper
}

make_deb-chl-bumpup-major() {
   make_bump_type="major"
   make_function_run make_deb-chl-bumpup
}

make_deb-chl-bumpup-manual() {
   make_bump_type="manual"
   make_function_run make_deb-chl-bumpup
}

make_deb-uachl-commit-changelog() {
   if test -f changelog.upstream ; then
      git add -- changelog.upstream
   fi
   git add -- debian/changelog
   git commit -m "bumped changelog version"
}

make_deb-chl-bumpup() {
   command -v debchange >/dev/null

   if [ "$DEBEMAIL" = "" ]; then
      ## Otherwise e-mail address in debian/changelog would default to
      ## user@host.localdomain and then lintian would complain and exit with
      ## failure code.
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') environment variable DEBEMAIL may not be empty! Both, DEBEMAIL and DEBFULLNAME need to be set!"
      exit 1
   fi
   if [ "$DEBFULLNAME" = "" ]; then
      printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') environment variable DEBFULLNAME may not be empty! Both, DEBEMAIL and DEBFULLNAME need to be set!"
      exit 1
   fi

   local new_upstream_version_without_epoch new_upstream_version new_changelog_version new_revision

   if [ "$make_bump_type" = "major" ]; then
      true "make_pkg_version: $make_pkg_version"

      if [ "$version_numbers_by_upstream" = "true" ] ; then
         ## Thanks to:
         ## https://stackoverflow.com/a/4485581
         #new_upstream_version="$(printf "%s\n" "$make_pkg_version" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')"
         new_upstream_version="$make_pkg_version"
         new_revision="$(bc -l <<< "scale=9 ; $make_pkg_revision + 1" 2>&1)"
      else
         #new_upstream_version_without_epoch="$(bc -l <<< "scale=9 ; $make_pkg_version + 0.1" 2>&1)"
         #new_upstream_version="$(printf '%3.1f\n' "$new_upstream_version_without_epoch")"
         new_upstream_version="$(/usr/share/genmkfile/version-bump-calculate "$make_pkg_version")"
         ## Packages by Kicksecure / Whonix always bump package version. Not Debian package revision.
         new_revision="1"
      fi

      if [ "$make_epoch" = "" ]; then
         new_changelog_version="$new_upstream_version-$new_revision"
      else
         new_changelog_version="$make_epoch:$new_upstream_version-$new_revision"
      fi
   elif [ "$make_bump_type" = "manual" ]; then
      printf "%s\n" "$0: INFO: Current version number: $make_changelog_version"
      printf "%s\n" "Please enter new version number!"
      read new_changelog_version
   else
      true "make_bump_type $make_bump_type is neither major nor manual!"
   fi

   true "\
Bumping version from / to...
$make_changelog_version
$new_changelog_version"

   if printf "%s\n" "$new_changelog_version" | grep_no_comments --quiet -- "error" ; then
      printf "%s\n" "$0: ${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') Failed!" >&2
      exit 1
   fi

   [ -n "$DEBCHANGE_MSG" ] || DEBCHANGE_MSG="New upstream version (local package)."

   make_log_and_run \
      debchange \
         --newversion "$new_changelog_version" \
         "$DEBCHANGE_MSG"

   make_log_and_run \
      debchange \
         --release \
         ""
}

make_deb-uachl-bumpup-manual() {
   make_function_run make_uch
   make_function_run make_deb-chl-bumpup-manual
}

make_deb-uachl-bumpup-major() {
   make_function_run make_uch
   make_function_run make_deb-chl-bumpup-major
}

make_git_tag_shared() {
   if [ "$make_git_tag_shared_done" = "true" ]; then
      return 0
   fi
   if [ "$package" = "derivative-maker" ]; then
      ## make_git_tag_sign_appendix gets set by dm-bump-derivative-maker-version
      if [ "$make_git_tag_sign_appendix" = "" ]; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') package is '$package' but variable make_git_tag_sign_appendix is empty."
         exit 1
      fi
   fi
   [ -n "$make_git_tag_push_targets" ] || make_git_tag_push_targets="origin"
   command -v git >/dev/null
   make_git_tag_shared_done="true"
}

make_git_tag_show() {
   make_function_run make_git_tag_shared
   printf "%s\n" "$make_git_tag_version_number"
}

make_git_tag_sign() {
   make_function_run make_git_tag_shared
   make_log_and_run git tag -s "$make_git_tag_version_number" -m "."
   make_function_run make_git_tag_verify
}

make_git_tag_verify() {
   make_function_run make_git_tag_shared
   make_log_and_run git tag -v -- "$make_git_tag_version_number"
}

make_git_tag_check() {
   make_function_run make_git_tag_shared

   ## Sanity test.
   #local make_git_describe_output
   ## dm-bump-derivative-maker-version script overrules this to disable this check.
   [ -n "$make_git_describe_output" ] || make_git_describe_output="$(git describe --always --abbrev=1000000000)"
   if [ ! "$make_git_tag_version_number" = "$make_git_describe_output" ]; then
      if [ ! "$make_skip_git_describe_output_check" = "true" ]; then
         printf "%s\n" "${red}${bold}$0: ERROR:${reset} (FUNCNAME: '$FUNCNAME') Failed! Current git head is a untagged git tag! $running_as_root_maybe \
make_git_tag_version_number $make_git_tag_version_number differs from make_git_describe_output $make_git_describe_output" >&2
         exit 1
      fi
   fi

   make_function_run make_git_tag_verify
   printf "%s\n" "$0: ${green}INFO:${reset} Ok, current git head is a signed git tag."
}

make_git_commit_verify() {
   make_log_and_run git verify-commit -- "$1"
}

make_git_commit_verify_current() {
   make_function_run make_git_tag_shared
   local make_git_commit_verify_return_code="0"
   make_function_run make_git_commit_verify "HEAD" || { make_git_commit_verify_return_code="$?" ; true; };
   if [ ! "$make_git_commit_verify_return_code" = "0" ]; then
      printf "%s\n" "$0: ${red}${bold}ERROR:${reset} (FUNCNAME: '$FUNCNAME') Failed! Current git head commit is unsigned! $running_as_root_maybe" >&2
      exit 1
   fi
   printf "%s\n" "$0: ${green}INFO:${reset} Ok, current git head commit is signed."
}

make_git_verify() {
   make_function_run make_git_commit_verify_current
   make_function_run make_git_tag_check
   printf "%s\n" "$0: ${green}INFO:${reset} Ok, current git head is a signed git commit and a signed git tag."
}

make_git_tag_push() {
   make_function_run make_git_tag_shared
   local repository
   for repository in $make_git_tag_push_targets; do
      printf "%s\n" "git push -- $repository $make_git_tag_version_number"
      git push "$repository" -- "$make_git_tag_version_number"
   done
}

make_git_tag_show_latest() {
   make_function_run make_git_tag_shared
   ## Thanks to kilianc - http://stackoverflow.com/a/7979255/2605155
   make_git_tag_latest="$(git describe --tags $(git rev-list --tags --max-count=1))"
   printf "%s\n" "$make_git_tag_latest"
}

make_git_tag_push_latest() {
   make_function_run make_git_tag_shared
   ## Thanks to kilianc - http://stackoverflow.com/a/7979255/2605155
   make_git_tag_latest="$(git describe --tags -- "$(git rev-list --tags --max-count=1)")"
   local repository
   for repository in $make_git_tag_push_targets; do
      make_log_and_run git push -- "$repository" "$make_git_tag_latest"
   done
}

make_reprepro-shared() {
   local package package_absolute_path make_reprepro_codename_list make_reprepro_codename_item

   ## global dist_build_apt_codename
   ## Can be set by derivative-maker.

   [ -n "$make_reprepro_wrapper" ] || make_reprepro_wrapper="dm-reprepro-wrapper"
   command -v "$make_reprepro_wrapper" 2>/dev/null

   if [ "$dist_build_apt_codename" = "local" ]; then
      make_reprepro_codename_list="local"
   else
      make_reprepro_codename_list="local $dist_build_apt_codename"
   fi

   for make_reprepro_codename_item in $make_reprepro_codename_list; do
      ## read by help-steps/variables
      export make_reprepro_codename_item

      if [ "$make_reprepro_cmd" = "add" ]; then
         changes_file_absolute_path="$(readlink -f "$make_main_changes_file")"
         test -f "$changes_file_absolute_path"
         make_log_and_run $make_reprepro_wrapper --ignore=wrongdistribution include "$make_reprepro_codename_item" "$changes_file_absolute_path"
      else
         for package in $make_package_list; do
            make_log_and_run $make_reprepro_wrapper remove "$make_reprepro_codename_item" "$package"
            make_log_and_run $make_reprepro_wrapper removesrc "$make_reprepro_codename_item" "$package"
            ## Avoid the following issue during the next package "include".
            # File "pool/main/a/anon-apt-sources-list/anon-apt-sources-list_6.5-1.dsc" is already registered with different checksums!
            # md5 expected: e6645bc3ef5cbb3769b8be0a008f8b01, got: 3142ef469a2bcab118dd772da437a80b
            # sha1 expected: 154a00a18c2d60d4d10148abab5ce809e85cbe86, got: b6da54d5d481180adf5298cd031e7381bf7253ba
            # sha256 expected: c5312451a92bda546a4d8e4331f835fecf1dbc07ebf99f21d67eab9e5082967d, got: 6a2f2d3aaba452659385a7727c246e45dfbb76af40a98278912a3a1d3c8563c8
            # There have been errors!'
            make_log_and_run $make_reprepro_wrapper deleteunreferenced
            ## Results in:
            # deleting and forgetting pool/main/a/anon-apt-sources-list/anon-apt-sources-list_6.5-1.debian.tar.xz
            # deleting and forgetting pool/main/a/anon-apt-sources-list/anon-apt-sources-list_6.5-1.dsc
            # deleting and forgetting pool/main/a/anon-apt-sources-list/anon-apt-sources-list_6.5-1_all.deb
            # deleting and forgetting pool/main/a/anon-apt-sources-list/anon-apt-sources-list_6.5.orig.tar.xz
         done
      fi
   done
}

make_reprepro-add() {
   make_reprepro_cmd=add
   make_reprepro-shared
}

make_reprepro-remove() {
   make_reprepro_cmd=remove
   make_reprepro-shared
}

make_source_overrides_file() {
   if [ -x "./make-helper-overrides.bsh" ]; then
      bash -n "./make-helper-overrides.bsh"
      source "./make-helper-overrides.bsh"
   fi
   if [ -x "./debian/make-helper-overrides.bsh" ]; then
      bash -n "./debian/make-helper-overrides.bsh"
      source "./debian/make-helper-overrides.bsh"
   fi
}

make_source_overrides_folder() {
   local folder_name
   for folder_name in ./make-helper-overrides.d ./debian/make-helper-overrides.d ; do
      if [ -d "$folder_name" ]; then
         local i
         for i in "$folder_name"*; do
            if [ -x "$i" ]; then
               ## If the last character is a ~, ignore that file,
               ## because it was created by some editor,
               ## which creates backup files.
               if [ "${i: -1}" = "~" ]; then
                  continue
               fi
               ## Skipping files such as .dpkg-old and .dpkg-dist.
               if printf "%s\n" "$i" | grep --quiet -- ".dpkg-" ; then
                  true "skip: $i"
                  continue
               fi
               bash -n "$i"
               source "$i"
            fi
         done
      fi
   done
}

make_function_run() {
   local function_name function_name_return_code
   function_name="$1"
   shift
   if type -t "${function_name}_hook_pre" >/dev/null ; then
      "${function_name}_hook_pre" "$@"
   fi
   if true ; then
      "$function_name" "$@"
      function_name_return_code="$?"
      if [ ! "$function_name_return_code" = "0" ]; then
         true "${green}INFO:${reset} function_name_return_code: $function_name_return_code"
         return "$function_name_return_code"
      fi
   fi
   if type -t "${function_name}_hook_post" >/dev/null ; then
      "${function_name}_hook_post" "$@"
   fi
}

if was_executed "${BASH_SOURCE[0]}"; then
   if [ -f /usr/libexec/helper-scripts/pre.bsh ]; then
      ## pre.bsh would `source` the following folders:
      ## /etc/make-helper-one.bsh_pre.d/*.conf
      ## /usr/local/etc/make-helper-one.bsh_pre.d/*.conf
      source /usr/libexec/helper-scripts/pre.bsh
      true
   fi

   temp="$@"
   if [ "$temp" = "" ]; then
      printf "%s\n" "$0: ${green}INFO:${reset} called without parameters."
   else
      printf "%s\n" "$0: ${green}INFO:${reset} $*"
   fi

   set -e
   set -o pipefail

   if [ -n "${APTGETOPT_SERIALIZED:-}" ]; then
      mapfile -t APTGETOPT <<< "$APTGETOPT_SERIALIZED"
   fi

   make_function_run make_init

   make_function_run make_source_overrides_file "$@"
   make_function_run make_source_overrides_folder "$@"

   make_function_run make_get_distdir
   make_function_run make_get_destdir
   make_function_run make_get_variables

   make_function_run make_parse_cmd "$@"
   make_function_run make_deinit

   true "$0: END"
fi
