# file : brep/handler/submit/submit.bash.in # license : MIT; see accompanying LICENSE file # Utility functions useful for implementing package submission handlers. if [ "$brep_handler_submit" ]; then return 0 else brep_handler_submit=true fi @import brep/handler/handler@ # Serialize the package submission result manifest to stdout and exit the # (sub-)shell with the zero status. # reference= # Should be assigned later by the handler, when becomes available. function exit_with_manifest () # { trace_func "$@" local sts="$1" local msg="$2" manifest_serializer_start manifest_serialize "" "1" # Start of manifest. manifest_serialize "status" "$sts" manifest_serialize "message" "$msg" if [ -n "$reference" ]; then manifest_serialize "reference" "$reference" elif [ "$sts" == "200" ]; then error "no reference for code $sts" fi manifest_serializer_finish run exit 0 } # Verify archive is a valid package and extract its manifest into # file. # function extract_package_manifest () # { local arc="$1" local man="$2" # Pass the --deep option to make sure that the bootstrap buildfile is # present and the *-file manifest values are resolvable, so rep-create will # not fail due to this package down the road. Note that we also make sure # that all the manifest values are known (see bpkg-pkg-verify for details). # if ! run_silent bpkg pkg-verify --deep --manifest "$arc" >"$man"; then # Perform the sanity check to make sure that bpkg is runnable. # if ! run bpkg --version >/dev/null; then error "unable to run bpkg" fi exit_with_manifest 400 "archive is not a valid package (run bpkg pkg-verify for details)" fi } # Extract the revision part from the package version. Return 0 if the version # doesn't contain revision. # function version_revision () # version { local r r="$(sed -n -re 's%^(\+?[^+]+)(\+([0-9]+))?$%\3%p' <<<"$1")" if [ -z "$r" ]; then r="0" fi echo "$r" }