autospec/lib/libcfg.lib.in
Davide Madrisan 868c8b882a libs,tests: add a debug message saying that the file is being loaded
Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
2012-12-01 17:54:46 +01:00

147 lines
4.2 KiB
Bash

#!/bin/bash
# libcfg.lib -- @package@ library for loading the configuration file(s)
# Copyright (C) 2008,2011,2012 Davide Madrisan <davide.madrisan@gmail.com>
[ "$libcfg_is_loaded" = 1 ] || {
libcfg_is_loaded=1
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] &&
echo $"this script requires bash version 2 or better" >&2 && exit 1
[ -r @libdir@/libmsgmng.lib ] ||
{ echo "\
libcfg.lib: "$"library not found"": @libdir@/libmsgmng.lib" 1>&2
exit 1; }
. @libdir@/libmsgmng.lib
[ -r @libdir@/libtranslate.lib ] ||
{ echo "\
libcfg.lib: "$"library not found"": @libdir@/libtranslate.lib" 1>&2
exit 1; }
. @libdir@/libtranslate.lib
notify.debug $"loading"": \`libcfg.lib'..."
# list of the configuration file(s)
default_cfg_list=(\
`ls /etc/@package@.conf /etc/@package@.d/*.conf \
~/.@package@ ~/.@package@.d/*.conf 2>/dev/null`)
default_cfg_strlist="/etc/@package@.conf /etc/@package@.d/*.conf"
default_cfg_user_strlist="~/.@package@ ~/.@package@.d/*.conf"
# 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
}
# load configuration files
function cfg_load_files() {
local cfg_file
notify.debug "$FUNCNAME: loading configuration files..."
if [ "$1" ]; then
# 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`" ] ||
notify.error $"configuration file not found"": $1"
# select a different list of user configuration files
cfgfile_list=(\
`ls /etc/@package@.conf /etc/@package@.d/*.conf 2>/dev/null` \
`ls $1 2>/dev/null`)
else
# default configuration files
cfgfile_list=(${default_cfg_list[@]})
fi
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
[ "$cfg_files_num" = 0 ] && notify.error $"configuration file not found"
}
} # endif $libcfg_is_loaded