#! /usr/bin/env bash # Init variables APTPKG_VERSION="1.1.0" # Show help show_help(){ cat > /dev/stdout < "$builddir"/DEBIAN/control } # Download a debian package build_deb(){ echo "Getting ${source:?}" wget "$source" -qP dist/ ( cd dist || error_usage_die "Problem with the dist/ directory" && verify ) } # Download and build using files build_file(){ builddir=${name}_${version}-${rev}_amd64 cd "$1" || error_usage_die "Problem with changing directory" mkdir -p "$builddir" for urls in $source; do echo "Getting $source" wget -q "$urls" done verify # Run steps "$@" gen_control_file "$@" for maintfile in preinst postinst prerm postrm; do [ -f $maintfile ] && cin-bin $maintfile "$builddir"/DEBIAN/$maintfile done cd - || error_usage_die "Problem with changing directory" dpkg-deb --build --root-owner-group "$1"/"$builddir" dist/ } # Determine which function to run load_build(){ mkdir -p dist # shellcheck disable=SC1090 # shellcheck disable=SC1091 source "${1:?}/build" case "${type:?}" in deb) build_deb ;; file) build_file "$@" ;; esac } # Autobuild packages based on git list files changed in commit # latest (HEAD) assumed if commit hash not provided change_autobuild_pkgs(){ [ -d .git ] || error_usage_die "Current directory is not a git repository!" commitid=$1 [ -n "$commitid" ] || commitid=HEAD if [[ "$commitid" = HEAD ]]; then before_run=$(git log HEAD^..HEAD | grep aptpkg-auto-run | sed 's#aptpkg-auto-run: ##' | sed 's# ##') if [ -n "$before_run" ]; then for m in $before_run; do build_chg_pre=$(git diff-tree --no-commit-id --name-only -r "$m" | grep "build" | sed 's#/build##') echo "Using $m with files $build_chg_pre" for a in $build_chg_pre; do aptpkg "$a" done done fi fi build_chg=$(git diff-tree --no-commit-id --name-only -r $commitid | grep "build" | sed 's#/build##') echo "Using $commitid with files $build_chg" for f in $build_chg; do aptpkg "$f" done } # Build all in directory build_all_in_dir(){ [ -d "$1" ] || error_usage_die "Provide a directory" buildfile_folders=$(ls -d "$1"/*) for ww in $buildfile_folders; do printf "\nBuilding %s\n\n" "$ww" aptpkg "$ww" done } # Run! case $1 in -h|--help) show_help ;; --all) shift build_all_in_dir "$1" ;; --auto) shift change_autobuild_pkgs "$1" ;; -v|--version) echo "aptpkg $APTPKG_VERSION" ;; *) if [ $# -ne 1 ]; then error_usage_die "You must provide one directory" fi check "$1" load_build "$1" ;; esac