generated from demus/basic-rpm-template
134 lines
3.6 KiB
Bash
134 lines
3.6 KiB
Bash
#!/usr/bin/bash
|
|
# Update various generated artifacts in rpm packages.
|
|
# This should be run in the directory containing the spec file.
|
|
# * Go vendor archive and config
|
|
# * COPR source file
|
|
set +e
|
|
shopt -s extglob
|
|
|
|
usage() {
|
|
echo "Usage: $(basename "$0") [OPTION]... <SPEC_FILE>"
|
|
echo "Update generated artifacts belonging to the <SPEC_FILE>."
|
|
echo
|
|
echo "Options:"
|
|
echo " -a Update archive"
|
|
echo " -l Update licenses"
|
|
echo " -s Update sources file"
|
|
echo " -u Ignore unlicensed mods"
|
|
echo " -h Print this message and exit"
|
|
echo
|
|
echo "If none of the update operations are specified, all of them will be performed."
|
|
}
|
|
|
|
parse_args() {
|
|
while getopts ":alsuh" flag; do
|
|
case "$flag" in
|
|
a)
|
|
UPDATE_ARCHIVE=1
|
|
;;
|
|
l)
|
|
UPDATE_LICENSES=1
|
|
;;
|
|
s)
|
|
UPDATE_SOURCES=1
|
|
;;
|
|
u)
|
|
IGNORE_UNLICENSED_ARG="-u "
|
|
;;
|
|
h)
|
|
usage
|
|
exit
|
|
;;
|
|
\?)
|
|
echo "Option -$OPTARG is invalid"
|
|
echo
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
[ "$UPDATE_ARCHIVE" == "" ] && [ "$UPDATE_LICENSES" == "" ] && [ "$UPDATE_SOURCES" == "" ]
|
|
if [ $? -eq 0 ]; then
|
|
UPDATE_ARCHIVE=1
|
|
UPDATE_LICENSES=1
|
|
UPDATE_SOURCES=1
|
|
fi
|
|
|
|
SPEC_FILE="${@:$OPTIND:1}"
|
|
if [ "$SPEC_FILE" == "" ]; then
|
|
echo "The required spec parameter is missing"
|
|
echo
|
|
usage
|
|
exit 1
|
|
fi
|
|
if ! [[ "$SPEC_FILE" =~ .*.\.spec$ ]]; then
|
|
echo "The spec file $SPEC_FILE doesn't have a .spec extension"
|
|
echo
|
|
usage
|
|
exit 2
|
|
fi
|
|
if [ ! -f "$SPEC_FILE" ]; then
|
|
echo "The spec file $SPEC_FILE is not readable"
|
|
echo
|
|
usage
|
|
exit 3
|
|
fi
|
|
}
|
|
|
|
download_sources() {
|
|
if [ ! -v SPEC_FILE ]; then
|
|
echo ERROR: Variable SPEC_FILE in not set
|
|
exit 10
|
|
fi
|
|
# Ensure remote sources are downloaded
|
|
spectool -g "$SPEC_FILE"
|
|
}
|
|
|
|
main() {
|
|
parse_args "$@"
|
|
download_sources
|
|
|
|
# go2rpm creates a go-vendor-tools.toml file when using the vendor profile
|
|
if [[ "$UPDATE_ARCHIVE" -eq 1 || "$UPDATE_LICENSES" -eq 1 ]] && ! grep -q go-vendor-tools.toml "$SPEC_FILE"; then
|
|
echo The spec file is not go-vendor-tools enabled
|
|
exit 4
|
|
fi
|
|
|
|
# Update the go vendors archive
|
|
if [ "$UPDATE_ARCHIVE" -eq 1 ]; then
|
|
echo Updating go vendor archive
|
|
if ! go_vendor_archive create --config go-vendor-tools.toml --write-config "$SPEC_FILE"; then
|
|
echo Archive update failed
|
|
exit 5
|
|
fi
|
|
fi
|
|
|
|
# Update the go vendors license config if it has changed
|
|
if [ "$UPDATE_ARCHIVE" -eq 1 ]; then
|
|
echo Updating go vendor licenses
|
|
if ! go_vendor_license --config go-vendor-tools.toml --path "$SPEC_FILE" report --write-config --prompt --autofill auto --update-spec$IGNORE_UNLICENSED_ARG; then
|
|
echo License update failed
|
|
exit 6
|
|
fi
|
|
fi
|
|
|
|
# Update the sources checksums
|
|
if [ "$UPDATE_ARCHIVE" -eq 1 ]; then
|
|
# The spec file and rpm build directories are excluded
|
|
echo Calculating checksums
|
|
# shellcheck disable=SC2094
|
|
if ! cksum -a sha512 !(sources|*.spec|RPMS|SRPMS|BUILD) > sources; then
|
|
echo Sources checksum update failed
|
|
exit 7
|
|
fi
|
|
fi
|
|
|
|
echo Done
|
|
}
|
|
|
|
# Check if the script is being run directly, not sourced
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
main "$@"
|
|
fi
|