diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cdb617d8a202969199f2fd948a345d7f106ae12f..2671946b017772127a819c6bc948610bff03d7b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,7 @@ cache: stages: # List of stages for jobs, and their order of execution - build - test + - packaging build-env-job: # This job runs in the build stage, which runs first. stage: build @@ -35,3 +36,14 @@ validate-job: # This job runs in the test stage. script: - for file in *.xml; do xmllint --noout --schema sigprops.xsd $file; done +debianize-job: + stage:packaging + timeout: 30min + tags: + - "docker" + script: + - ./debianize.sh + artifacts: + paths: + - artifacts/*.{deb,rpm,sh,tar.gz} + - ./*.{deb,rpm,sh,tar.gz} diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000000000000000000000000000000000000..9e55f79d4eec13b301ea5616537c8e846f9b69fe --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,15 @@ +### ENABLE SOME OPTIONAL CHECKS +# use "shellcheck --list-optional" to list available checks +enable=add-default-case +enable=avoid-nullary-conditions +enable=require-variable-braces + + + +### DISABLE CHECKS + +# https://github.com/koalaman/shellcheck/wiki/SC1091 +disable=SC1091 + +# https://github.com/koalaman/shellcheck/issues/2457 +disable=SC2020 diff --git a/debianize.sh b/debianize.sh new file mode 100755 index 0000000000000000000000000000000000000000..262d23e05798c64aab223ffac01b3934857c5613 --- /dev/null +++ b/debianize.sh @@ -0,0 +1,207 @@ +#!/usr/bin/env bash +# based on build_applefonts.sh by Jörg Sachse, licensed as gpl3. + +### META +# AUTHORS: +# - Andreas Romeyke (<Andreas.Romeyke@slub-dresden.de>) + +#hh debianize.sh - creates a debian package in `build/` subdirectory. +#hh +#hh Usage: debianize.sh [-h] [-V] [-m] [-M] +#hh The generated Debian package can be found below the `build/` subdirectory. +#hh This path is also used for all intermediate steps, so you can use it to +#hh debug the package creation or tweak package build options. +#hh +#hh Options: +#hh You can use the following CLI arguments to configure the behaviour of +#hh debianize.sh. Please note that the CLI arguments need to be space +#hh separated. Combining arguments like "-hV" is currently NOT supported. +#hh +#hh -h, --help +#hh Show this help and exit. +#hh -V, --version +#hh Show version number and exit. +#hh -m, --man, --manpage, --manual +#hh Create a manpage from this help section and exit. +#hh Requires "help2man". +#hh -M, --showman +#hh Print the Manpage. +#hh Requires "help2man". + + + +### DEFAULTS + +RED="\\e[31m" +WHITE="\\e[0m" +ERROR="${RED}[ERROR]\t${WHITE}" + +PKG_VERSION="1.0" +PKG_NAME="significant-properties-slubarchive" + + + +### INIT + +SCRIPTPATH="$( dirname "$( realpath "$0" )" )" + +# list external required binaries here (space separated) +REQUIREMENTS="help2man man gzip make dpkg curl p7zip alien tar dh_make" +for REQUIREMENT in ${REQUIREMENTS}; do + command -v "${REQUIREMENT}" >/dev/null 2>&1 || { echo >&2 "${ERROR} '${REQUIREMENT}' required but not installed. Aborting."; exit 1; } +done + +# make sure this runs as root if you use `alien`. We don't. +#[[ ${UID} -ne 0 ]] && echo "Please run this script with sudo. This is required by 'alien' package generator." && exit 1 + + + +### FUNCTIONS + +# Don't just call this function "help()", as that's a reserved command in Bash. +comment_help() { + sed -rn 's/^#hh ?//;T;p' "$0" +} + +create_manpage(){ + # https://www.gnu.org/software/help2man/ + help2man --section 1 --source="SLUB Dresden" --no-info "${0}" | gzip > ./"$( basename "${0}" ".sh" ).gz" +} + +show_manpage(){ + help2man --section 1 --source="SLUB Dresden" --no-info "${0}" | man -l - +} + +get_cli_args(){ + while [[ $# -gt 0 ]]; do + case ${1} in + -h|--help) + comment_help + exit 0 + ;; + -V|--version) + echo "$( basename "${0}" ) v1.0.0" + echo -e "\n\nCopyright (C)\n" + echo "This software is licensed under the GNU General Public License version 3 (GNU GPLv3)." + exit 0 + ;; + -m|--man|--manpage|--manual) + create_manpage + exit 0 + ;; + -M|--showman) + show_manpage + exit 0 + ;; + *) + echo "'${1}' is not a valid parameter. Please use '$( basename "${0}" ) --help'. Exiting." + exit 1 + ;; + esac + done +} + +cleanup_build_dir() { + if [[ -d "${SCRIPTPATH}/build/" ]]; then + rm -rf "${SCRIPTPATH}/build/" + fi +} + +create_build_dir() { + mkdir -p "${SCRIPTPATH}"/build/"${PKG_NAME}"-"${PKG_VERSION}"/usr/share/significant_properties/ + mkdir -p "${SCRIPTPATH}"/build/"${PKG_NAME}"-"${PKG_VERSION}"/usr/share/doc/significant_properties/ + +} + +prepare_sigprops() { + /usr/bin/cp --reflink=auto -t "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/usr/share/significant_properties/" ./*.xml ./*.xsd + /usr/bin/cp --reflink=auto -t "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/usr/share/doc/significant_properties/" ./README.md ./LICENSE.txt +} + +# https://wiki.debian.org/SimplePackagingTutorial +# https://www.internalpointers.com/post/build-binary-deb-package-practical-guide +package_sigprops() { + cd "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/" || exit 1 + + export DEBFULLNAME="Andreas Romeyke" + export DEBEMAIL="langzeitarchiv@slub-dresden.de" + export DPKG_DEB_THREADS_MAX=4 + # As of Debian 12 Bookworm, reprepro doesn't fully support zstd + # compression. Do NOT use `DPKG_DEB_COMPRESSOR_TYPE="zstd"`! Instead, + # use one of 'none', 'gzip', 'xz'. + export DPKG_DEB_COMPRESSOR_TYPE="gzip" + export DPKG_DEB_COMPRESSOR_LEVEL=9 + export DEBIAN_FRONTEND="non-interactive" + dh_make --email "langzeitarchiv@slub-dresden.de" \ + --indep \ + --createorig \ + --packagename "${PKG_NAME}_${PKG_VERSION}" \ + --yes + # remove all unnecessary files from the prepared package directory + rm "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/"*".ex" + rm "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/"*".docs" + rm "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/README"* + rm -rf "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/source/" + # build your own control file + cat <<- EOF > "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/control" + Source: ${PKG_NAME} + Priority: optional + Maintainer: ${DEBFULLNAME} <${DEBEMAIL}> + Section: misc + Package: ${PKG_NAME} + Architecture: all + Description: Significant properties of several digital preservation + workflows of Saxon State library (SLUB) + Version: ${PKG_VERSION} + EOF + echo "10" > "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/compat" + #echo "yep" > "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/copyright" + /usr/bin/cp --reflink=auto ./LICENSE.txt "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/copyright" + sed -i "s/UNRELEASED/stable/" "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/changelog" + # make sure that all mandatory files are present + for FILE in control copyright changelog compat rules; do + if [[ ! -f "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/${FILE}" ]]; then + echo "ERROR: '${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/${FILE}' expected but not found. This file is mandatory for Debian packages." + exit 1 + fi + done + rm -Rf "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}/debian/upstream" + # Rename the debian/ directory, because dpkg-deb expects the name to be all upper case. Smh! -.- + mv "./debian" "./DEBIAN" + cd "${SCRIPTPATH}/build/" || exit + dpkg-deb --root-owner-group --build "${PKG_NAME}-${PKG_VERSION}/" + + #CAUTION: `alien` creates packages that cannot be ingested into `reprepro`, so we cannot use it! + #export EMAIL="langzeitarchiv@slub-dresden.de" + #alien --to-deb \ + # --description "Applefonts grabbed straight from Apple Inc. to be installed on your Debian system." \ + # --version "1.0" \ + # --fixperms \ + # "${SCRIPTPATH}/build/applefonts.tar.gz" + #rm "${SCRIPTPATH}/build/applefonts.tar.gz" +} + +save_deb_package() { + mkdir -p "${SCRIPTPATH}/artifacts/" + mv "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}.deb" "${SCRIPTPATH}/artifacts/" +} + +check_deb_package() { + lintian "${SCRIPTPATH}/build/${PKG_NAME}-${PKG_VERSION}.deb" +} + + + +### MAIN + +get_cli_args "${@}" + +cleanup_build_dir +create_build_dir +prepare_sigprops +package_sigprops +check_deb_package +save_deb_package + +exit 0 +