prepare_install											&&

# move docs
mkdir -p /usr/share/doc/openwebmail       &&
mv html/doc/* /usr/share/doc/openwebmail  &&
rmdir html/doc                            &&

# check for previous config file
if [ -e /etc/openwebmail.conf ]; then
  message " "                                                                       &&
  message "${MESSAGE_COLOR}Previous config file detected..."                        &&
  message "The new sample config file will be named openwebmail-new.conf."          &&
  message "Your actual config is maintained (beware of conf file format changes)."  &&
  message " ${DEFAULT_COLOR}"                                                       &&
  mv ./cgi-bin/openwebmail/etc/openwebmail.conf /etc/openwebmail-new.conf 
else
  mv ./cgi-bin/openwebmail/etc/openwebmail.conf /etc/openwebmail.conf
fi &&

# run the install process
install_www_files &&

#link /etc/openwebmail.conf to the one in the cgi-bin dir
ln -sfn $TRACK_ROOT/etc/openwebmail.conf get_install_www_files_dir/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf  &&

message "${MESSAGE_COLOR}Setting up log... ${DEFAULT_COLOR}" 					&&
[ -x /var/log/openwebmail.log ] || touch /var/log/openwebmail.log               &&
chown nobody.nogroup /var/log/openwebmail.log							        &&
chmod 660            /var/log/openwebmail.log							        &&

# not really sure what to do with this stuff...
#echo "auth       required     /lib/security/pam_unix.so" > /etc/pam.d/openwebmail		&&
#echo "account    required     /lib/security/pam_unix.so">> /etc/pam.d/openwebmail		&&
#echo "password   required     /lib/security/pam_unix.so">> /etc/pam.d/openwebmail		&&

# Tune OWM defaults to SMGL style
message "${MESSAGE_COLOR}Tuning OpenWebMail defaults to SMGL style... ${DEFAULT_COLOR}"	&&

message "${MESSAGE_COLOR}Directories... ${DEFAULT_COLOR}"        				                                                                                                       &&
sedit "s|/var/mail/|/var/spool/mail|" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf                                                                   &&
sedit "s|/usr/local/www/data/openwebmail|$(get_install_www_files_dir)/${SPELL}/html|" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf                   &&
sedit "s|/usr/local/www/cgi-bin/openwebmail|$(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail|" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf &&

message "${MESSAGE_COLOR}Perl db extentions... ${DEFAULT_COLOR}"        			                                                   &&
sedit "s/^dbm_ext.*$/dbm_ext .db/" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf                      &&
sedit "s/^dbmopen_ext.*$/dbmopen_ext %dbm_ext%/" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf        &&
sedit "s/^dbmopen_haslock.*$/dbmopen_haslock yes/" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf      &&
sedit "s/^spellcheck.*$/spellcheck \/usr\/bin\/ispell/" $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/openwebmail.conf &&

message "${MESSAGE_COLOR}Passwd files in OWM auth_unix.pl file... ${DEFAULT_COLOR}"                                                    &&
sedit "s/\/etc\/master.passwd/\/etc\/shadow/"  $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/defaults/auth_unix.conf   &&
sedit "s/\/usr\/sbin\/pwd_mkdb/none/"  $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/defaults/auth_unix.conf           &&

# Initialize openwebmail
if [ "$MAIL_STATS" == "n" ]; then
  MAIL_OPT="--no"
else
  MAIL_OPT="--yes"
fi &&

# Overwrite dbm.conf file 
cp -f $SCRIPT_DIRECTORY/dbm.conf $(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/etc/defaults/ &&

message "${MESSAGE_COLOR}Initializing OpenWebmail... ${DEFAULT_COLOR}"                          &&
$(get_install_www_files_dir)/${SPELL}/cgi-bin/openwebmail/openwebmail-tool.pl --init $MAIL_OPT  &&

# link index.html to the redirect page
ln -sf redirect.html $LOC/htdocs/openwebmail/index.html
