2011-04-26 21:39:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# libcfg.lib -- @package@ library for loading the configuration file(s)
|
2012-11-08 22:09:52 +01:00
|
|
|
# Copyright (C) 2008,2011,2012 Davide Madrisan <davide.madrisan@gmail.com>
|
2011-04-26 21:39:44 +02:00
|
|
|
|
2012-11-25 15:54:34 +01:00
|
|
|
[ "$libcfg_is_loaded" = 1 ] || {
|
|
|
|
libcfg_is_loaded=1
|
|
|
|
|
2011-04-26 21:39:44 +02:00
|
|
|
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] &&
|
|
|
|
echo $"this script requires bash version 2 or better" >&2 && exit 1
|
|
|
|
|
|
|
|
[ -r @libdir@/libmsgmng.lib ] ||
|
2012-12-01 17:40:21 +01:00
|
|
|
{ echo "\
|
|
|
|
libcfg.lib: "$"library not found"": @libdir@/libmsgmng.lib" 1>&2
|
2011-04-26 21:39:44 +02:00
|
|
|
exit 1; }
|
|
|
|
. @libdir@/libmsgmng.lib
|
|
|
|
|
2012-11-30 22:02:42 +01:00
|
|
|
[ -r @libdir@/libtranslate.lib ] ||
|
2012-12-01 17:40:21 +01:00
|
|
|
{ echo "\
|
|
|
|
libcfg.lib: "$"library not found"": @libdir@/libtranslate.lib" 1>&2
|
2012-11-30 22:02:42 +01:00
|
|
|
exit 1; }
|
|
|
|
. @libdir@/libtranslate.lib
|
2011-04-26 21:39:44 +02:00
|
|
|
|
2012-12-01 17:54:46 +01:00
|
|
|
notify.debug $"loading"": \`libcfg.lib'..."
|
|
|
|
|
2011-04-26 21:39:44 +02:00
|
|
|
# list of the configuration file(s)
|
2012-11-14 22:42:08 +01:00
|
|
|
default_cfg_list=(\
|
2012-05-05 23:33:18 +02:00
|
|
|
`ls /etc/@package@.conf /etc/@package@.d/*.conf \
|
|
|
|
~/.@package@ ~/.@package@.d/*.conf 2>/dev/null`)
|
2011-04-26 21:39:44 +02:00
|
|
|
|
2012-11-07 22:24:08 +01:00
|
|
|
default_cfg_strlist="/etc/@package@.conf /etc/@package@.d/*.conf"
|
|
|
|
default_cfg_user_strlist="~/.@package@ ~/.@package@.d/*.conf"
|
|
|
|
|
2011-04-26 21:39:44 +02:00
|
|
|
# check if the user configurations file for autospec is present
|
|
|
|
function config.check4user() {
|
|
|
|
local user_data=$(getent passwd 2>/dev/null | grep "x:$(id -u):")
|
|
|
|
local user_fullname=$(echo "$user_data" | cut -d: -f 5)
|
|
|
|
local email_infof_kde
|
|
|
|
|
|
|
|
if [ -r "$HOME/.kde/share/config/emaildefaults" ]; then
|
|
|
|
email_infof_kde="$HOME/.kde/share/config/emaildefaults"
|
|
|
|
elif [ -r "$HOME/.kde4/share/config/emaildefaults" ]; then
|
|
|
|
email_infof_kde="$HOME/.kde4/share/config/emaildefaults"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$email_infof_kde" && -z "$packager_email" ]]; then
|
|
|
|
packager_email="$(\
|
|
|
|
sed -n "/EmailAddress/{s/.*=//p}" "$email_infof_kde" 2>/dev/null)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -r ~/.@package@ ] || notify.error $"\
|
|
|
|
configuration file not found"": ${HOME:-~}/.@package@
|
|
|
|
---------------------------------------
|
|
|
|
${NOTE}"$"Hint"":${NORM}
|
|
|
|
packager_fullname=\"${user_fullname:-Your Name}\"
|
|
|
|
packager_email=\"${packager_email:-email@domain}\"
|
|
|
|
ftp_rw_user[1]=\"user\"
|
|
|
|
ftp_rw_passwd[1]=\"passwd\"
|
|
|
|
---------------------------------------
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
function config.security() {
|
|
|
|
if [ -n "$packager_group" ]; then
|
|
|
|
[ "$(groups 2>/dev/null | grep $packager_group 2>/dev/null)" ] ||
|
|
|
|
notify.error $"\
|
|
|
|
user \`$(id -nu)' does not belong to group \`$packager_group'"
|
|
|
|
else
|
|
|
|
notify.warning "\`packager_group' "$"unset in the configuration files"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# checking for errors in the configuration file
|
|
|
|
function config.integrity() {
|
|
|
|
mandatory_cfg_vars='
|
|
|
|
DISTRO
|
|
|
|
DISTRO_rpm
|
|
|
|
VENDOR
|
|
|
|
packager_fullname
|
|
|
|
packager_email
|
|
|
|
ftpurl_ro_rpms
|
|
|
|
ftpurl_ro_srpms
|
|
|
|
packager_group
|
|
|
|
allowed_libdirs
|
|
|
|
library_group
|
|
|
|
library_summary
|
|
|
|
library_group_devel
|
|
|
|
library_group_perl
|
|
|
|
format_buildroot_value
|
|
|
|
man_compress_ext
|
|
|
|
info_compress_ext
|
|
|
|
library_name_structure
|
|
|
|
perl_module_name_structure
|
|
|
|
patch_name_structure
|
|
|
|
source0_name_structure
|
|
|
|
plugindir
|
|
|
|
plugin_pck_update
|
|
|
|
plugin_spec_create
|
|
|
|
plugin_pck_extract
|
|
|
|
plugin_config_getvar'
|
|
|
|
|
|
|
|
# note: use indirect references to 'mandatory_cfg_vars' variables
|
|
|
|
for cfg_var in $mandatory_cfg_vars; do
|
|
|
|
(set -u; : ${!cfg_var}) 2>/dev/null ||
|
|
|
|
notify.error $"\
|
|
|
|
missing variable in the configuration file"" -- \`$cfg_var'"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-11-14 22:42:08 +01:00
|
|
|
# load configuration files
|
|
|
|
function cfg_load_files() {
|
2012-11-18 20:09:15 +01:00
|
|
|
local cfg_file
|
|
|
|
|
2012-11-14 22:42:08 +01:00
|
|
|
notify.debug "$FUNCNAME: loading configuration files..."
|
2012-11-18 20:09:15 +01:00
|
|
|
|
2012-11-14 22:42:08 +01:00
|
|
|
if [ "$1" ]; then
|
2012-11-18 20:09:15 +01:00
|
|
|
# this will catch some error cases when the files do not exist,
|
|
|
|
# like /etc/donotexists.conf or /etc/nofiles*.conf
|
|
|
|
[ "`ls $1 2>/dev/null`" ] ||
|
2012-11-18 20:16:52 +01:00
|
|
|
notify.error $"configuration file not found"": $1"
|
2012-11-14 22:42:08 +01:00
|
|
|
# select a different list of user configuration files
|
|
|
|
cfgfile_list=(\
|
2012-11-25 23:21:06 +01:00
|
|
|
`ls /etc/@package@.conf /etc/@package@.d/*.conf 2>/dev/null` \
|
|
|
|
`ls $1 2>/dev/null`)
|
2012-11-14 22:42:08 +01:00
|
|
|
else
|
|
|
|
# default configuration files
|
|
|
|
cfgfile_list=(${default_cfg_list[@]})
|
2011-04-26 21:39:44 +02:00
|
|
|
fi
|
|
|
|
|
2012-11-14 22:42:08 +01:00
|
|
|
notify.debug "$FUNCNAME: cfgfile_list = (${cfgfile_list[*]})"
|
|
|
|
|
|
|
|
local cfg_files_num=0
|
|
|
|
for cfg_file in ${cfgfile_list[*]}; do
|
|
|
|
if [ -e "$cfg_file" ]; then
|
|
|
|
cfg_files_num=$(($cfg_files_num + 1))
|
|
|
|
notify.debug $"loading"": \`$cfg_file'..."
|
|
|
|
[ -r "$cfg_file" ] || notify.error $"cannot read"" \`$cfg_file'"
|
|
|
|
. "$cfg_file"
|
|
|
|
else
|
|
|
|
notify.error $"configuration file not found"": $cfg_file"
|
|
|
|
fi
|
|
|
|
done
|
2011-04-26 21:39:44 +02:00
|
|
|
|
2012-11-14 22:42:08 +01:00
|
|
|
[ "$cfg_files_num" = 0 ] && notify.error $"configuration file not found"
|
|
|
|
}
|
2012-11-25 15:54:34 +01:00
|
|
|
|
|
|
|
} # endif $libcfg_is_loaded
|