2011-04-26 21:39:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# _\|/_
|
|
|
|
# (o o)
|
|
|
|
# +----oOO-{_}-OOo-----------------------------------------------------------+
|
|
|
|
# | |
|
|
|
|
# | $0 -- help creating rpm specfiles and automatically update rpm packages |
|
2013-11-07 23:23:30 +01:00
|
|
|
# | Copyright (C) 2004-2013 Davide Madrisan <davide.madrisan@gmail.com> |
|
2011-04-26 21:39:44 +02:00
|
|
|
# | |
|
|
|
|
# | This program is free software; you can redistribute it and/or modify it |
|
|
|
|
# | under the terms of the GNU General Public License version 2 as published |
|
|
|
|
# | by the Free Software Foundation. There is NO warranty; not even for |
|
|
|
|
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
|
|
|
# | |
|
|
|
|
# | Report bugs to <davide.madrisan@gmail.com> |
|
|
|
|
# | |
|
|
|
|
# +--------------------------------------------------------------------------+
|
|
|
|
|
|
|
|
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] &&
|
|
|
|
{ echo $"this script requires bash version 2 or better" >&2 && exit 1; }
|
|
|
|
|
|
|
|
me=(${0##*/} "@version@" "@date@")
|
|
|
|
|
2012-12-01 22:50:46 +01:00
|
|
|
[ -r @libdir@/libtranslate.lib ] ||
|
|
|
|
{ echo "$me: "$"library not found"": @libdir@/libtranslate.lib" 1>&2
|
|
|
|
exit 1; }
|
|
|
|
. @libdir@/libtranslate.lib
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
# default values
|
|
|
|
let "pck_update = 0"
|
|
|
|
let "pck_extract = 0"
|
|
|
|
let "spec_create = 0"
|
|
|
|
let "config_getvar = 0"
|
|
|
|
let "print_help = 0"
|
|
|
|
let "print_version = 0"
|
|
|
|
|
|
|
|
function autospec.version() {
|
|
|
|
echo "\
|
|
|
|
${me[0]} ${me[1]}
|
2022-01-06 14:59:23 +01:00
|
|
|
Copyright (C) 2004-2013 Davide Madrisan <davide.madrisan@gmail.com>
|
|
|
|
Copyright (C) 2013-2022 Silvan Calarco <silvan.calarco@mambasoft.it>"
|
2011-04-26 21:39:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function autospec.copying() {
|
|
|
|
echo "\
|
|
|
|
"$"This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License version 2 as published by the
|
|
|
|
Free Software Foundation. There is NO warranty; not even for MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE."
|
|
|
|
}
|
|
|
|
|
|
|
|
function autospec.usage() {
|
|
|
|
# $1: optional exit code (default is '1')
|
|
|
|
autospec.version
|
|
|
|
echo "
|
|
|
|
"$"Automatically update rpm packages and help creating new specfiles.""
|
|
|
|
|
|
|
|
"$"Operation modes"":
|
|
|
|
-u, --update "$"Update the given package to a specified version and release""
|
|
|
|
-s, --source "$"Try to create a specfile for the specified tarball""
|
|
|
|
-x, --extract "$"Extract a given file or list of files from a srpm archive""
|
|
|
|
--eval "$"Print the value of the given configuration variable""
|
|
|
|
-h, --help "$"Print this help, then exit""
|
|
|
|
-V, --version "$"Print version number, then exit""
|
|
|
|
-q, --quiet "$"Run in quiet mode""
|
|
|
|
-D, --debug "$"Run in debugging mode (very verbose output)""
|
|
|
|
|
2012-11-14 22:42:08 +01:00
|
|
|
"$"Common options"":
|
|
|
|
--colors "$"Select the theme to be used for the colorized output""
|
|
|
|
-C, --config "$"Use an alternate user configuration file""
|
|
|
|
|
2011-04-26 21:39:44 +02:00
|
|
|
"$"Usage"":
|
|
|
|
"$"Use '-u -h', '-s -h', '-x -h', and '--eval -h' to display specific command line options.""
|
|
|
|
|
|
|
|
"$"Report bugs to <davide.madrisan@gmail.com>."
|
|
|
|
|
|
|
|
exit ${1:-1}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ $# -eq 0 ] && autospec.usage
|
|
|
|
|
|
|
|
# load the warning/error/debug/ message handling library
|
|
|
|
# to define the 'notify()' function
|
|
|
|
|
|
|
|
[ -r @libdir@/libmsgmng.lib ] ||
|
|
|
|
{ echo "$me: "$"library not found"": @libdir@/libmsgmng.lib" 1>&2
|
|
|
|
exit 1; }
|
|
|
|
|
|
|
|
. @libdir@/libmsgmng.lib
|
|
|
|
notify.disable_colors
|
|
|
|
|
|
|
|
# load the configuration file(s)
|
|
|
|
[ -r @libdir@/libcfg.lib ] ||
|
|
|
|
{ echo "$me: "$"library not found"": @libdir@/libcfg.lib" 1>&2
|
|
|
|
exit 1; }
|
|
|
|
|
2012-11-11 18:56:52 +01:00
|
|
|
. @libdir@/libcfg.lib
|
2012-11-25 23:21:06 +01:00
|
|
|
|
2012-11-10 15:47:12 +01:00
|
|
|
# Little helper function for reading args from the commandline.
|
|
|
|
# it automatically handles -a b and -a=b variants, and returns 1 if
|
|
|
|
# we need to shift $3.
|
|
|
|
# see. /usr/sbin/mkinitrd (dracut-024)
|
|
|
|
function read_arg() {
|
|
|
|
# $1 = arg name
|
|
|
|
# $2 = arg value
|
|
|
|
# $3 = arg parameter
|
|
|
|
local rematch='^[^=]*=(.*)$'
|
|
|
|
if [[ $2 =~ $rematch ]]; then
|
|
|
|
read "$1" <<< "${BASH_REMATCH[1]}"
|
|
|
|
elif [[ $3 != -* ]]; then
|
|
|
|
# Only read next arg if it not an arg itself.
|
|
|
|
read "$1" <<< "$3"
|
|
|
|
# There is no way to shift our callers args, so
|
|
|
|
# return 1 to indicate they should do it instead.
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:59:40 +01:00
|
|
|
args=()
|
2012-11-25 23:21:06 +01:00
|
|
|
cmdline_vars=()
|
|
|
|
|
2012-11-10 15:47:12 +01:00
|
|
|
while (($# > 0)); do
|
2012-11-13 21:59:40 +01:00
|
|
|
args[${#args[*]}]="$1"
|
2012-11-10 15:47:12 +01:00
|
|
|
case ${1%%=*} in
|
2011-04-26 21:39:44 +02:00
|
|
|
-u|--update)
|
|
|
|
let "pck_update = 1" ;;
|
|
|
|
-s|--source)
|
|
|
|
let "spec_create = 1" ;;
|
|
|
|
-x|--extract)
|
|
|
|
let "pck_extract = 1" ;;
|
|
|
|
--eval|--eval=*)
|
|
|
|
let "config_getvar = 1" ;;
|
|
|
|
-D|--debug)
|
|
|
|
let "verbose = 2" ;;
|
|
|
|
-q|--quiet)
|
|
|
|
let "verbose = 0" ;;
|
|
|
|
-h|--help)
|
|
|
|
let "print_help = 1" ;;
|
|
|
|
-V|--version)
|
|
|
|
let "print_version = 1" ;;
|
2012-11-14 22:42:08 +01:00
|
|
|
--colors)
|
2012-11-25 23:21:06 +01:00
|
|
|
read_arg color_scheme "$@" ||
|
|
|
|
{ shift; args[${#args[*]}]="$1"; }
|
|
|
|
notify.debug "color_scheme = \"$color_scheme\""
|
|
|
|
cmdline_vars[${#cmdline_vars[*]}]="color_scheme=\"$color_scheme\""
|
|
|
|
;;
|
2012-11-14 22:42:08 +01:00
|
|
|
-C|--config)
|
2012-11-25 23:21:06 +01:00
|
|
|
read_arg cfgfile_list_cmdline "$@" ||
|
|
|
|
{ shift; args[${#args[*]}]="$1"; }
|
|
|
|
notify.debug "cfgfile_list_cmdline = \"$cfgfile_list_cmdline\""
|
|
|
|
;;
|
|
|
|
*) ;;
|
2011-04-26 21:39:44 +02:00
|
|
|
esac
|
2012-11-10 15:47:12 +01:00
|
|
|
shift
|
2011-04-26 21:39:44 +02:00
|
|
|
done
|
|
|
|
|
2012-11-10 12:21:10 +01:00
|
|
|
notify.debug "[${me[0]}, "$"version"" ${me[1]}]"
|
2012-11-14 22:42:08 +01:00
|
|
|
|
2012-11-25 23:21:06 +01:00
|
|
|
cfg_load_files "$cfgfile_list_cmdline"
|
2012-11-14 22:42:08 +01:00
|
|
|
|
2012-11-25 23:21:06 +01:00
|
|
|
# otherwrite the configuration variables by set them again using
|
|
|
|
# the values defined via the commanline options
|
|
|
|
for i in ${!cmdline_vars[@]}; do
|
|
|
|
notify.debug "eval \"${cmdline_vars[i]}\""
|
|
|
|
eval "${cmdline_vars[i]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$logging" = "1" ] && color_scheme="none"
|
|
|
|
notify.enable_colors "$color_scheme"
|
2012-11-10 12:21:10 +01:00
|
|
|
|
2011-04-26 21:39:44 +02:00
|
|
|
case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in
|
|
|
|
0) [ "$print_help" = "1" ] && autospec.usage 0
|
|
|
|
if [ "$print_version" = "1" ]; then
|
|
|
|
# only print the version number in quiet mode
|
|
|
|
[ "$verbose" = 0 ] && { echo "${me[1]}"; exit 0; }
|
|
|
|
autospec.version;
|
|
|
|
autospec.copying
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
autospec.usage 1 ;;
|
|
|
|
1) ;;
|
|
|
|
*) autospec.usage 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# checking for errors in the configuration file
|
|
|
|
[ "$config_getvar" = 1 ] || config.integrity
|
|
|
|
|
|
|
|
# load and execute the required plugin...
|
|
|
|
|
|
|
|
[ "$config_getvar" = 1 ] && plugin_to_run="$plugin_config_getvar"
|
|
|
|
[ "$pck_extract" = 1 ] && plugin_to_run="$plugin_pck_extract"
|
|
|
|
[ "$spec_create" = 1 ] && plugin_to_run="$plugin_spec_create"
|
|
|
|
[ "$pck_update" = 1 ] && plugin_to_run="$plugin_pck_update"
|
|
|
|
|
|
|
|
[ -n "$plugin_to_run" ] ||
|
|
|
|
notify.error "\`$plugin_to_run': "$"unset in the configuration files"
|
|
|
|
[ -x "$plugin_to_run" ] ||
|
|
|
|
notify.error $"plugin not found"": \`$plugin_to_run'"
|
|
|
|
|
|
|
|
tmpargfile=$(mktemp -q -t $me.XXXXXXXX)
|
|
|
|
[ $? -eq 0 ] || notify.error $"can't create temporary files"
|
|
|
|
notify.debug "tmpargfile = \`${NOTE}$tmpargfile${NORM}'"
|
|
|
|
|
|
|
|
# workaround to bypass the issues related to bash expansion in multi-word
|
|
|
|
# strings (ex: autospec -u s.spec -a4 1.0 --changelog "here's the problem")
|
|
|
|
echo -n "set -- " > $tmpargfile
|
2012-11-10 15:47:12 +01:00
|
|
|
for i in `seq 1 1 ${#args[@]}`; do
|
|
|
|
echo -n "\"${args[$i-1]}\" " >> $tmpargfile
|
2011-04-26 21:39:44 +02:00
|
|
|
done
|
|
|
|
echo >> $tmpargfile
|
|
|
|
|
|
|
|
notify.debug "\
|
|
|
|
running: \`$plugin_to_run --autospec-args-file=$tmpargfile'"
|
2012-11-13 22:07:36 +01:00
|
|
|
|
|
|
|
notify.debug "[$tmpargfile]"
|
|
|
|
notify.debug "$(cat $tmpargfile)"
|
|
|
|
|
2011-04-26 21:39:44 +02:00
|
|
|
$plugin_to_run --autospec-args-file=$tmpargfile
|
|
|
|
|
|
|
|
exit $?
|