### # Functions to handle the main Gforge configuration file ### mainconfdir=/etc/gforge mainconffile=$mainconfdir/gforge.conf create_mainconffile () { if [ ! -e $mainconfdir ] ; then mkdir -p $mainconfdir fi if [ ! -e $mainconffile ] ; then touch $mainconffile chmod 600 $mainconffile fi } init_debconf_from_mainconffile () { for i in $(grep -v "^ *#" $mainconffile | sort -u | cut -d= -f1) ; do update_onevar_from_mainconfile $i done } update_onevar_from_mainconfile () { key=$1 update_onevar_from_mainconfile__retcode=0 value=$(grep ^$key= $mainconffile | tail -1 | cut -d= -f2-) if [ ! -z "$value" ] ; then db_set gforge/shared/$key $value || update_onevar_from_mainconfile__retcode=$? || true # case $update_onevar_from_mainconfile__retcode in # 0) # echo "$key = $value injected into Debconf OK" # db_fset gforge/shared/$key seen true || true # ;; # 10) # echo "$key = $value not injected into Debconf (non-existing question maybe?)" # ;; # *) # echo "Something wicked happened" # exit 1 # ;; # esac fi } update_mainconffile () { for key in $@ ; do db_get gforge/shared/$key val=$RET update_onevar_mainconffile $key $val done } update_onevar_mainconffile () { key=$1 val=$2 if grep -q "^$key=" $mainconffile ; then newval=$(echo $val | sed -e 's/@/\\@/g' -e 's/\$/\\$/g') perl -pi -e "s/^$key=.*/$key=$newval/" $mainconffile else echo "$key=$val" >> $mainconffile fi }