#!/usr/bin/env bash set -euo pipefail packager=${1:?packager must be deb or rpm} version=${2:?version is required} release_root=${3:?release target directory is required} dist_dir=${4:-dist} mkdir -p "$dist_dir" if [[ "$packager" == "deb" ]]; then architecture=amd64 system_dependencies=("libc6" "libgcc-s1") else architecture=amd64 system_dependencies=("glibc" "libgcc") fi make_package() { local name=$1 description=$2 shift 2 local config config=$(mktemp) local contents=() while [[ $# -gt 0 && "$1" == content:* ]]; do contents+=("${1#content:}") shift done local dependencies=("$@") { echo "name: $name" echo "arch: $architecture" echo "platform: linux" echo "version: $version" echo "release: 1" echo "section: utils" echo "priority: optional" echo "maintainer: Elias Wendland " echo "description: $description" echo "license: GPL-3.0-only" echo "homepage: https://git.ewenlau.net/ewenlau/convertis" if [[ "$name" == "convertis" ]]; then echo "provides:" echo " - convertis-plugin-api-2" fi if [[ ${#contents[@]} -gt 0 ]]; then echo "contents:" for mapping in "${contents[@]}"; do destination=${mapping#*::} echo " - src: ${mapping%%::*}" echo " dst: $destination" echo " file_info:" if [[ "$destination" == /usr/bin/* || "$destination" == *.so ]]; then echo " mode: 0755" else echo " mode: 0644" fi done fi if [[ ${#dependencies[@]} -gt 0 ]]; then echo "depends:" for dependency in "${dependencies[@]}"; do echo " - $dependency" done fi } > "$config" nfpm package --config "$config" --packager "$packager" --target "$dist_dir/" rm -f "$config" } make_package convertis "Plugin-based universal file converter" \ "content:${release_root}/convertis::/usr/bin/convertis" \ "content:target/man/convertis.1::/usr/share/man/man1/convertis.1" \ "content:README.md::/usr/share/doc/convertis/README.md" \ "content:LICENSE::/usr/share/doc/convertis/LICENSE" \ "content:packaging/plugin-catalog.json::/usr/share/convertis/plugin-catalog.json" \ "${system_dependencies[@]}"