X-Git-Url: http://git.onelab.eu/?p=plcrt.git;a=blobdiff_plain;f=plcrt.init;h=f72810b97543257c44811ef9e9cbea4bd12c3a93;hp=96aa8f3de2e34daad99d6efda2f1e7850656b1e2;hb=2361d6e83f529403ff1e8801083fc92b1eb720d6;hpb=27c2ea9bbeb04156550fdf5138010d625306dc87 diff --git a/plcrt.init b/plcrt.init index 96aa8f3..f72810b 100644 --- a/plcrt.init +++ b/plcrt.init @@ -38,6 +38,17 @@ if [ -z "$PLC_RT_IP" ] ; then PLC_RT_IP=$( gethostbyname $PLC_RT_HOST ) fi +function check_rt_password () +{ + if [[ -z "$PLC_RT_DBPASSWORD" || "$PLC_RT_DBPASSWORD" = "None" ]] ; then + # NOTE: this provides a simpler string than uuidgen + PLC_RT_DBPASSWORD=$( uuidgen | md5sum - | awk '{print $1}' ) + plc-config --category=plc_rt --variable=dbpassword --value="$PLC_RT_DBPASSWORD" --save=$local_config $local_config + service plc reload + CREATED="true" + fi +} + # NOTE: code duplicated from monitor.functions to allow package to be separate # from it. function check_pg_hba () @@ -49,7 +60,7 @@ function check_pg_hba () CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf if [ ! -f $CONF ] ; then echo "host $NAME $USER 127.0.0.1/32 password" > $CONF - echo "host $NAME $USER $PLC_MONITOR_IP/32 password" >> $CONF + echo "host $NAME $USER $PLC_RT_IP/32 password" >> $CONF WROTE_PG_CONFIG="true" fi @@ -63,44 +74,61 @@ function update_config () file=$3 sed -i -e "s/$pattern/$with/g" $file } - -function check_rt_siteconfig () +function apply_template () { - tmp_siteconfig=$(mktemp) - tmp_initialdata=$(mktemp) + TEMPLATE=$1 + DESTFILE=$2 - # TODO: need a better approach for this. + tmp_file=$(mktemp) + cp $TEMPLATE $tmp_file + update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file + update_config PLC_RT_CC_ADDRESS $PLC_RT_CC_ADDRESS $tmp_file + + update_config PLC_NAME "$PLC_NAME" $tmp_file + update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file + update_config PLC_WWW_HOSTNAME $PLC_WWW_HOST $tmp_file + + update_config RT_DB_NAME $RT3_DB_NAME $tmp_file + update_config RT_DB_USER $RT3_DB_USER $tmp_file + update_config RT_DB_PASSWORD $PLC_RT_DBPASSWORD $tmp_file + + # setup initialdata + update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file + + cp $tmp_file $DESTFILE + rm -f $tmp_file +} + +function check_rt_templates () +{ for f in $PLCRTPATH/conf.d/*.pl ; do - update_config PLC_RT_HOSTNAME $PLC_RT_HOST $f + mkdir -p /etc/rt3/conf.d + if [ $f -nt /etc/rt3/conf.d/`basename $f` ] ; then + apply_template $f /etc/rt3/conf.d/`basename $f` + fi + done + + for f in $PLCRTPATH/setup.d/*.{pl,py,sh} ; do + mkdir -p /etc/rt3/setup.d + if [ $f -nt /etc/rt3/setup.d/`basename $f` ] ; then + apply_template $f /etc/rt3/setup.d/`basename $f` + chmod 751 /etc/rt3/setup.d/`basename $f` + fi done + + # TODO: need a better approach for this. + if [ -f /etc/httpd/conf.d/rt3.conf ] ; then + update_config PLC_RT_HOST $PLC_RT_HOST /etc/httpd/conf.d/rt3.conf + fi # if the templates are newer than the actual config, then replace them. if [ $PLCRTPATH/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ; then # copy templates - cp -f $PLCRTPATH/RT_SiteConfig.pm $tmp_siteconfig - cp -f $PLCRTPATH/initialdata $tmp_initialdata - - # setup RT_SiteConfig.pm - update_config PLC_NAME "$PLC_NAME" $tmp_siteconfig - update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_siteconfig - update_config PLC_WWW_HOSTNAME $PLC_WWW_HOST $tmp_siteconfig - - update_config RT_DB_NAME $RT3_DB_NAME $tmp_siteconfig - update_config RT_DB_USER $RT3_DB_USER $tmp_siteconfig - update_config RT_DB_PASSWORD $PLC_MONITOR_DBPASSWORD $tmp_siteconfig - - # setup initialdata - update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_initialdata - - # copy to live configuration - cp -f $tmp_siteconfig /etc/rt3/RT_SiteConfig.pm - cp -f $tmp_initialdata /etc/rt3/initialdata + apply_template $PLCRTPATH/RT_SiteConfig.pm /etc/rt3/RT_SiteConfig.pm + apply_template $PLCRTPATH/initialdata /etc/rt3/initialdata chmod 644 /etc/rt3/RT_SiteConfig.pm chmod 644 /etc/rt3/initialdata - - rm -f $tmp_siteconfig - rm -f $tmp_initialdata fi } @@ -115,7 +143,13 @@ function check_rt_pghba () USER=$RT3_DB_USER CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf PATTERN="host all postgres 127.0.0.1/32 trust" + if ! grep -q "$PATTERN" $CONF ; then + #### SETUP ACCESS from postgres user to run init for the first time. + echo "$PATTERN" >> $CONF + WROTE_PG_CONFIG="true" + fi + PATTERN="host all postgres $PLC_RT_IP/32 trust" if ! grep -q "$PATTERN" $CONF ; then #### SETUP ACCESS from postgres user to run init for the first time. echo "$PATTERN" >> $CONF @@ -147,14 +181,17 @@ function check_rt_init () { if [ ! -f /etc/rt3/setup.finished ] ; then /usr/sbin/rt-setup-database --action init --dba postgres - for f in $PLCRTPATH/conf.d/*.pl ; do + + for f in /etc/rt3/conf.d/*.pl ; do /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f done # run initial setup scripts (run only once, or for the first time) - if [ -d $PLCRTPATH/setup.d ] ; then - for f in $PLCRTPATH/setup.d/*.{pl,py,sh} ; do - $f + if [ -d /etc/rt3/setup.d ] ; then + for f in /etc/rt3/setup.d/*.{pl,py,sh} ; do + if [ -x $f ] ; then + $f + fi done fi @@ -208,9 +245,13 @@ case "$1" in MESSAGE=$"Bootstrap RT (please wait...)" dialog "$MESSAGE" + check_rt_password check_pg_hba $RT3_DB_NAME $RT3_DB_USER #check_user_and_db $RT3_DB_NAME $RT3_DB_USER - check_rt_siteconfig + check_rt_templates + # TODO: make this dependent on whether a change was made! + service plc restart httpd + check_rt_pghba if [ -n "$WROTE_PG_CONFIG" ] ; then # NOTE: restart db to enable access by users granted above. @@ -223,6 +264,19 @@ case "$1" in check_rt_sendmail check_rt_custom # todo: restart httpd if needed. + # NOTE: remove external permission + # This is needed to allow it to run without localhost + # TODO: find a better way to do this. + + # remove 'trust' entry from .conf file + sed -i -e "s/.*trust//g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf + if [ -n "$WROTE_PG_CONFIG" ] ; then + # NOTE: restart db to enable access by users granted above. + service plc restart postgresql + MESSAGE=$"Bootstrap RT 3 (please wait...)" + dialog "$MESSAGE" + fi + result "$MESSAGE" ;; @@ -237,8 +291,8 @@ case "$1" in dropuser -U postgres $RT3_DB_USER rm -f /etc/rt3/RT_SiteConfig.pm rm -f /etc/rt3/initialdata - PATTERN="host all postgres 127.0.0.1/32 trust" - sed -i -e "s|$PATTERN||g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf + rm -f /etc/rt3/conf.d/*.pl + rm -f $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf sed -i -e "s/.*mailgate.*//g" /etc/aliases rm -f /etc/rt3/setup.finished