| Server IP : 133.18.244.157 / Your IP : 216.73.217.20 Web Server : Apache System : Linux o4022v-135.kagoya.net 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : main2 ( 81069) PHP Version : 5.6.34 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /install/ |
Upload File : |
#!/bin/bash
#====================================================================
# Cybozu MailWise 5 Installer ver 1.0 for Linux
# Copyright (C) 2012 Cybozu, Inc.
#====================================================================
arg=$1
EXE_NAME=mw.cgi
INI_NAME=mw.ini
PRODUCT_VERSION=5011
PRODUCT_MAJOR_VERSION=5
PRODUCT_UPGRADE_MIN_VERSION=3000
WWW_PATHS="/var/www /var/apache2 /var/apache /usr/local/apache2 /usr/local/apache /usr/local/www /home/httpd /srv/www"
CGI_BIN_PATHS="`echo $WWW_PATHS | sed -e 's, ,/cgi-bin ,g'`/cgi-bin /usr/lib/cgi-bin"
WEB_PATHS="/var/www/html /var/apache2/htdocs /var/apache/htdocs /usr/local/apache2/htdocs /usr/local/apache/htdocs /usr/local/www/data /home/httpd/html /srv/www/htdocs /var/www"
CGI_MW_DIR=mw
WEB_MW_DIR=cbmw500
DEFAULT_APP_NAME=cbmw
CGI_BIN=/var/www/cgi-bin
WEB_ROOT=/var/www/html
TARGET_OS=lin
USER_DIR_BASE=/var/local/cybozu/mailwise
NUM_0="0."
NUM_1="1."
NUM_2="2."
NUM_3="3."
NUM_4="4."
VERSIONUP_TYPE=0
MSG_PRODUCT_NAME=$"Cybozu(R) MailWise 5"
MSG_PRODUCT_NAME_ja="サイボウズ(R) メールワイズ 5"
MSG_PROMPT_YN="[Y] / [N] : "
MSG_LANGUAGE_QUESTION_1="この日本語が正しく表示されている場合は Y を入力してください。"
MSG_LANGUAGE_QUESTION_2="If you cannot read the above Japanese text, type 'N'."
MSG_NEED_ROOT="Install as the super user (root)."
MSG_NEED_ROOT_ja="スーパーユーザー(root)でインストールしてください。"
MSG_HTTPD_IS_NOT_RUNNING="The Web server is not started. Start the Web server first and then install."
MSG_HTTPD_IS_NOT_RUNNING_ja="Web サーバーが起動していません。Web サーバーを起動してからインストールしてください。"
MSG_PREPARING="Preparing for installation. Please wait."
MSG_PREPARING_ja="インストールの準備をしています。しばらくお待ちください。"
MSG_PREPARING_FAILED="Failed to preparate installation."
MSG_PREPARING_FAILED_ja="インストールの準備に失敗しました。"
MW_MESSAGES_CODESET=$(locale -k messages-codeset | sed -e 's/messages-codeset="//' -e 's/"//')
MW_MESSAGES_ICONV_COMMAND="cat"
if [ -n "$MW_MESSAGES_CODESET" -a x"$MW_MESSAGES_CODESET" != x"UTF-8" ] && echo "$MSG_LANGUAGE_QUESTION_1" | iconv -f utf-8 -t "$MW_MESSAGES_CODESET" >/dev/null 2>&1 ; then
MW_MESSAGES_CODESET="$MW_MESSAGES_CODESET"
MW_MESSAGES_ICONV_COMMAND="iconv -cs -f utf-8 -t \"$MW_MESSAGES_CODESET\""
else
MW_MESSAGES_CODESET=""
fi
_MSG()
{
eval msg='"$MSG_'${1}_$MW_MESSAGES_LANGUAGE'"'
if [ -z "$msg" ]; then eval msg='"$MSG_'${1}'"'; fi
echo -n "$msg"
}
echo_msg()
{
nonewline=""
if [ "$1" = "-n" ]; then nonewline=$1; shift; fi
msg=$(_MSG "$1")
if [ -z "$MW_MESSAGES_CODESET" ]; then
echo $nonewline "$msg"
else
echo $nonewline "$msg" | $MW_MESSAGES_ICONV_COMMAND
fi
}
if [ -z "$MW_LOG_FILE" ]; then
MW_LOG_FILE="`pwd`/install.log"
rm -f $MW_LOG_FILE
printf "Installation starts at `env LANG=C date`\n" > $MW_LOG_FILE
uname -a >> $MW_LOG_FILE
fi
log=$MW_LOG_FILE
while [ $# -ne 0 ]; do
case $1 in
--skip-pager)
PAGER=cat
;;
esac
shift
done
os=`uname -s`
printf "detected OS: ${os}\n" >> $log
unsupported_os()
{
echo "Installation on this platform is not supported!"
echo
exit 1
}
case $os in
Linux)
os=lin
TGZ=tar.gz
UNZIP=gunzip
INIT_TYPE=SYSV
INIT_DIR=/etc/rc.d/init.d
if [ ! -d $INIT_DIR ]; then
INIT_DIR=/etc/init.d
fi
BOOT_DIRS="/etc/rc.d/rc2.d /etc/rc.d/rc3.d /etc/rc.d/rc4.d /etc/rc.d/rc5.d"
SHUTDOWN_DIRS="/etc/rc.d/rc0.d /etc/rc.d/rc1.d /etc/rc.d/rc6.d"
GLIBC_VERSION=""
GLIBC_MAJOR_VERSION=""
GLIBC_MINOR_VERSION=""
CALC_MEM="`free -m | grep Mem: | awk '{print $2}'`"
;;
*)
unsupported_os
;;
esac
if [ "${os}" != "${TARGET_OS}" ]; then
unsupported_os
fi
if [ -z "$MW_MESSAGES_LANGUAGE" ]; then
while [ 1 ]; do
clear
echo_msg LANGUAGE_QUESTION_1
echo_msg LANGUAGE_QUESTION_2
echo_msg -n PROMPT_YN
read reply leftover
case $reply in
y* | Y*)
MW_MESSAGES_LANGUAGE=ja
eval `locale | grep LC_MESSAGES= | sed -e 's/="[^\\."]*/="ja_JP/'`
export LC_MESSAGES
break;;
n* | N*)
MW_MESSAGES_LANGUAGE=en
LANG=C
LC_ALL=C
LC_MESSAGES=C
export LANG LC_ALL LC_MESSAGES
break;;
*)
;;
esac
done
printf "chosen language: ${MW_MESSAGES_LANGUAGE}\n" >> $log
fi
lang=$MW_MESSAGES_LANGUAGE
clear
pid="`ps -o uid= -p $$`"
if [ $pid -ne 0 ]; then
echo_msg NEED_ROOT
echo
exit 1
fi
printf "root test passed!\n" >> $log
if [ "$arg" != "-force" ]; then
clear
httpdfind=0
for httpdname in httpd apache httpsd httpd2-prefork apache2 httpd2
do
ps axw | grep ${httpdname}$ | grep -v "grep" > /dev/null 2>&1
if [ $? -eq 0 ]
then
httpdfind=1
break
fi
ps axw | grep "$httpdname " | grep -v "grep" > /dev/null 2>&1
if [ $? -eq 0 ]
then
httpdfind=1
break
fi
ps axw | grep "\[$httpdname\]" | grep -v "grep" > /dev/null 2>&1
if [ $? -eq 0 ]
then
httpdfind=1
break
fi
done
if [ $httpdfind -eq 0 ]; then
echo_msg HTTPD_IS_NOT_RUNNING
echo
exit 1
fi
printf "webserver start check passed!\n" >> $log
else
printf "webserver not check!\n" >> $log
fi
signal_handler()
{
if [ -e "$MW_TMP_INSTALL_DIR" -a -z "$MW_INSTALL_DEBUG" ]; then
rm -rf "$MW_TMP_INSTALL_DIR"
fi
if [ x"$MW_INSTALL_SUCCESS" != x"yes" -a -e install/crontab.orig ]; then
crontab -u root install/crontab.orig
fi
exit 1
}
trap "signal_handler" HUP INT QUIT TERM EXIT
clear
if [ -z "$MW_TMP_INSTALL_DIR" ]; then
outname="install.${TGZ}"
MW_TMP_INSTALL_DIR="/tmp/cbmw-installer-$$"
echo_msg PREPARING
if [ -e "$MW_TMP_INSTALL_DIR" -a -z "$MW_INSTALL_DEBUG" ]; then
rm -rf "$MW_TMP_INSTALL_DIR"
fi
mkdir -p "$MW_TMP_INSTALL_DIR"
READ_LINES=`expr $(wc -l < $0) + 1 - %HEADER_LINES%`
tail -n $READ_LINES $0 > "$MW_TMP_INSTALL_DIR/$outname"
cd $MW_TMP_INSTALL_DIR
$UNZIP < $outname | tar xf -
rm -f $outname
if [ ! -f install/install.sh ]; then
echo_msg PREPARING_FAILED
print "ERROR: install/install.sh not found\n" >> $log
exit 1
fi
TEXTDOMAINDIR="./install/locale/"
TEXTDOMAIN="mw-install"
export TEXTDOMAINDIR TEXTDOMAIN MW_MESSAGES_LANGUAGE MW_TMP_INSTALL_DIR MW_LOG_FILE
exec install/install.sh $arg
exit $?
fi
###END_OF_BOOTSTRAP_SCRIPT
GLIBC_VERSION="`install/libc-ver`"
GLIBC_MAJOR_VERSION="`install/libc-ver | sed -e "s,^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\),\1,g"`"
GLIBC_MINOR_VERSION="`install/libc-ver | sed -e "s,^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\),\2,g"`"
if [ -z "${GLIBC_VERSION}" ]; then
printf $"Cannot detect the GLIBC version.\n"
echo
exit 1
fi
printf "glibc check passed!\n" >> $log
clear
license_ja="install/doc/LICENSE"
license_en="install/doc/LICENSE.en"
if [ $lang = 'ja' ]; then
license=$license_ja
else
license=$license_en
fi
license_out="install/doc/LICENSE.out"
$MW_MESSAGES_ICONV_COMMAND < $license > $license_out
license=$license_out
PAGER=${PAGER:-more}
if $PAGER -e -r $license 1> /dev/null 2>&1 ; then
PAGER="$PAGER -e -r"
fi
if [ -f $license ]; then
$PAGER $license
else
agreed=1
fi
while [ "x$agreed" = x ]; do
echo
printf $"Do you agree to the above license terms?\n[Y](Yes) / [N](No) : "
read reply leftover
case $reply in
y* | Y*)
agreed=1;;
n* | N*)
printf $"\nThis product cannot be installed if you do not accept to the LICENSE Agreement.\n"
echo
exit 1;;
*)
;;
esac
done
apply_config()
{
sed -e "s,%EXE_NAME%,${EXE_NAME},g" -e "s,%INI_NAME%,${INI_NAME},g" -e "s,%APP_NAME%,${REG_APP_NAME},g" -e "s,%CGI_ROOT%,${CGI_BIN}/${REG_APP_NAME},g" -e "s,%WEB_ROOT%,${WEB_ROOT},g" -e "s,%HTTPD_USER%,${HTTPD_USER},g" -e "s,%INIT_DIR%,${INIT_DIR},g" -e "s,%BOOT_DIRS%,${BOOT_DIRS},g" -e "s,%SHUTDOWN_DIRS%,${SHUTDOWN_DIRS},g" -e "s,%CGI_MW_DIR%,${CGI_MW_DIR},g" -e "s,%WEB_MW_DIR%,${WEB_MW_DIR},g" "$1" > "$1.tmp"
mv -f "$1.tmp" "$1"
if [ $2 -eq 1 ]; then
chmod a+x "$1"
fi
}
detectapp()
{
app_detected_length=0
app_detected=
cgibin_detected=
webroot_detected=
for cgibin in $CGI_BIN_PATHS; do
webpath=`dirname ${cgibin}`
cgiroots=`ls ${cgibin} 2> /dev/null`
for j in ${cgiroots}; do
if echo $j | grep "^${DEFAULT_APP_NAME}" >/dev/null 2>&1; then
if [ -d "${cgibin}/${j}" -a \
-e "${cgibin}/${j}/${EXE_NAME}" ]; then
set `${cgibin}/${j}/${EXE_NAME} -v` > /dev/null
if [ $# -ne 1 ]; then
continue
fi
if echo $1 | grep -v '[0-9][0-9][0-9][0-9]' >/dev/null 2>&1; then
continue
fi
MW_VERSION=$1
if [ ${MW_VERSION} -lt ${PRODUCT_UPGRADE_MIN_VERSION} ]; then
continue
fi
if echo ${MW_VERSION} | grep "^[0-9]\{4\}$" >/dev/null 2>&1; then
if [ ${MW_VERSION} -lt 2000 ]; then
webdir=cbmw
elif [ ${MW_VERSION} -ge 3000 -a ${MW_VERSION} -lt 4000 ]; then
webdir=cbmw3
elif [ ${MW_VERSION} -ge 4000 -a ${MW_VERSION} -lt 5000 ]; then
webdir=cbmw4
elif [ ${MW_VERSION} -ge 5000 ]; then
webdir=cbmw`echo "${MW_VERSION}" | sed -e 's/\(...\)./\1/'`
fi
for k in $webpath/htdocs $webpath/html $webpath/data $WEB_PATHS; do
webroot="$k/$webdir"
if [ -d "$webroot" ]; then
app_detected="$j $app_detected"
cgibin_detected="$cgibin $cgibin_detected"
webroot_detected="$k $webroot_detected"
break
fi
done
fi
fi
fi
done
done
if [ -n "$app_detected" ]; then
cgibin_detected=( ${cgibin_detected} )
webroot_detected=( ${webroot_detected} )
fi
}
selectmenu()
{
detectapp
while [ 1 ]; do
APP_NAME=${DEFAULT_APP_NAME}
clear
printf $"===================== Set Installation Identifier =====================\n"
echo
if [ -n "$app_detected" ]; then
printf $"One or more Cybozu products are currently installed.\n"
printf $"The installation identifiers of the currently installed products are as follows:\n"
for i in $app_detected; do
echo $i
done
echo
echo
printf $"To upgrade or uninstall an already-installed product, specify its installation identifier.\n\n"
printf $"To install a new %s instance, specify a different installation identifier.\n\n" "$MSG_PRODUCT_NAME"
printf $"Leave this blank and press the Enter key to use %s as the installation identifier.\n" "$APP_NAME"
echo
else
printf $"Enter the installation identifier.\n"
printf $"The installation identifier is used as a name of the directory in which the product is installed.\n\n"
printf $"Leave this blank and press the Enter key to use %s as the installation identifier.\n" "$APP_NAME"
printf $"Usually, there is no need to change the installation identifier.\n\n"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
printf $"Upgrading to %s\n\n" "$MSG_PRODUCT_NAME"
printf $"Enter the same installation identifier as the product currently in use.\n"
printf $"The installation identifier can be found in the \"Dir\" section on the \"Operating environment\" screen of the product in use.\n"
printf $"Example: If \"%s/%s/\" is displayed in the \"Dir\" section on the \"Operating environment\" screen of the product in use, the installation identifier is %s.\n" "$APP_NAME" "$APP_NAME"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
echo
fi
printf "\n[${APP_NAME}]: "
read reply leftover
appset=0
if [ "x$reply" != x ]; then
if echo $reply | grep "^[-_+!'()$,a-zA-Z0-9][-_+!'()$,a-zA-Z0-9.]\{0,19\}$" >/dev/null 2>&1; then
if echo $reply | grep "[^.]$" >/dev/null 2>&1; then
appset=1
fi
fi
if [ $appset -eq 1 ]; then
APP_NAME="$reply"
REG_APP_NAME=`echo $APP_NAME | sed -e 's/\,/\\\,/g'`
break
else
clear
echo
printf $"The entered text includes invalid characters.\n"
printf $"Valid characters are \"A-Z\" \"a-z\" \"0-9\" or \"- , ( ) $ ! _ ' . +\".\n"
printf $"You cannnot use \".\" at the beginning or the end of the text. You can enter up to 20 characters.\n"
echo
echo $"-- Press the [Enter] key. --"
read en
fi
else
REG_APP_NAME=`echo $APP_NAME | sed -e 's/\,/\\\,/g'`
break
fi
done
selected=0
if [ -z "$app_detected" ]; then
return
fi
idx=0
for i in $app_detected; do
if [ "$i" = "$APP_NAME" ]; then
CGI_BIN=${cgibin_detected[$idx]}
WEB_ROOT=${webroot_detected[$idx]}
selectmenu2
break;
fi
idx=`expr ${idx} + 1`
done
}
selectmenu2()
{
APP_USER_DIR=`"${CGI_BIN}/${APP_NAME}/${EXE_NAME}" -x config 2>/dev/null | grep '^UserDir=' | sed -e 's/^UserDir=//'`
if [ x"$APP_USER_DIR" = x ]; then
APP_USER_DIR="${CGI_BIN}/${APP_NAME}"
fi
echo APP_USER_DIR=$APP_USER_DIR >>$log
while [ 1 ]; do
clear
printf $"===================== Select Operation =====================\n"
echo
printf $"Select the operation you want to perform with the product (%s).\n\n" "$APP_NAME"
printf $"1: %s\n" $"Upgrade"
if [ -x "${APP_USER_DIR}/uninstall_${APP_NAME}" ]; then
printf $"2: %s\n" $"Uninstall"
printf $"3: %s\n" $"Cancel installation"
printf $"\n[1] / [2] / [3]: "
menu_type=1
else
printf $"2: %s\n" $"Cancel installation"
printf $"\n[1] / [2] : "
menu_type=2
fi
read type leftover
if [ $menu_type -eq 2 -a $type -eq 2 ]; then
reply=3
else
reply=$type
fi
if [ "$reply" = "1" -o "$reply" = "2" ]; then
selected=$reply
break;
elif [ "$reply" = "3" ]; then
clear
printf $"Installation has been cancelled.\n"
echo
exit 1
else
clear
echo
printf $"The entered value is invalid. Enter a number corresponding to a menu item.\n"
echo
echo $"-- Press the [Enter] key. --"
read en
fi
done
}
uninstall()
{
APP_DIR=${APP_USER_DIR}
APP_UNINSTALL=${APP_DIR}/uninstall_${APP_NAME}
if [ -x ${APP_UNINSTALL} ]; then
${APP_UNINSTALL}
else
clear
printf $"Cannot find the executable file used for uninstallation.\n"
echo
exit 1
fi
clear
printf $"===================== Confirm Completion of Uninstallation =====================\n"
echo
printf $"Uninstallation has completed.\n"
echo
exit 0
}
userconfig()
{
APP_DIR=${CGI_BIN}/${APP_NAME}
if [ "x${HTTPD_USER}" = x ]; then
last_user=
last_ppid=
psopt="-A -o comm,user,ppid"
for i in `ps $psopt | egrep '(^httpd |^apache |^httpsd |^httpd2-prefork |^apache2 |^httpd2 )' | grep -v grep | awk '{ printf("%s,%d\n", $2, $3) }'`; do
user=`echo "${i}" | awk -F, '{ print $1 }'`
ppid=`echo "${i}" | awk -F, '{ print $2 }'`
if [ "x${last_ppid}" = "x${ppid}" ]; then
HTTPD_USER="$user"
break
fi
last_ppid="$ppid"
last_user="$user"
done
if [ "x${HTTPD_USER}" = x ]; then
if [ "x${last_user}" = x ]; then
if [ -d $APP_DIR ]; then
HTTPD_USER="`ls -ald ${APP_DIR} | awk '{print $3}'`"
elif [ -d $CGI_BIN ]; then
HTTPD_USER="`ls -ald ${CGI_BIN} | awk '{print $3}'`"
else
HTTPD_USER=nobody
fi
else
HTTPD_USER="$last_user"
fi
fi
fi
clear
printf $"===================== Set Web Server User Name =====================\n"
echo
printf $"Set the web server user name.\n"
echo
printf $"\"%s\" will be set if you enter nothing and press the [Enter] key.\n" "$HTTPD_USER"
printf $"Usually, there is no need to change this.\n"
echo
printf "[${HTTPD_USER}]: "
read reply leftover
if [ "x$reply" != x ]; then
HTTPD_USER="$reply"
fi
}
installconfirmation()
{
UNINST_SCRIPT=${APP_USER_DIR}/uninstall_${APP_NAME}
clear
printf $"===================== Confirm Installation Settings =====================\n"
echo
printf $"Confirm installation settings.\n\n"
printf $"Installation identifier: %s\n" "${APP_NAME}"
printf $"CGI directory: %s\n" "${CGI_BIN}"
printf $"Data directory: %s\n" "${APP_USER_DIR}"
printf $"Document root directory: %s\n" "${WEB_ROOT}"
printf $"Web server user name: %s\n" "${HTTPD_USER}"
printf $"Add crontab entry: %s\n" "${ENABLE_CRON_TASK}"
printf $"The executable file used for uninstallation: %s\n" "${UNINST_SCRIPT}"
echo
}
sub_error()
{
clear
printf "$1"
echo
echo $"-- Press the [Enter] key. --"
read en
}
while [ 1 ]; do
clear
selectmenu
if [ $selected -eq 0 ]; then
while [ 1 ]; do
clear
for cgibin in $CGI_BIN_PATHS; do
if [ -d $cgibin ]; then
CGI_BIN=$cgibin
break
fi
done
printf $"===================== Set CGI Directory =====================\n"
echo
printf $"Enter the CGI directory.\n"
printf $"CGI is a directory to put the executable files in.\n"
printf $"\n"
printf $"Leave this blank and press the Enter key to use the default CGI directory \"%s\".\n" "$CGI_BIN"
printf $"Usually, there is no need to change the CGI directory.\n\n"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
printf $"Upgrading to %s\n\n" "$MSG_PRODUCT_NAME"
printf $"Enter the same CGI directory as the product currently in use.\n"
printf $"The CGI directory can be found in the \"Dir\" section on the \"Operating environment\" screen of the product in use.\n"
printf $"If \"%s/%s/\" is displayed in the \"Dir\" section on the \"Operating environment\" screen of the product in use, the CGI directory is %s.\n" "$CGI_BIN" "$APP_NAME" "$CGI_BIN"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
echo
printf "[${CGI_BIN}]: "
read reply leftover
if [ "x$reply" != x ]; then
CGI_BIN="$reply"
fi
CGI_ROOT="${CGI_BIN}/${APP_NAME}"
echo CGI_ROOT=$CGI_ROOT >>$log
if [ -e ${CGI_ROOT}/${EXE_NAME} ]; then
set `${CGI_ROOT}/${EXE_NAME} -v` > /dev/null
if [ $# -ne 1 ]; then
exit 1
fi
MW_VERSION=$1
echo PRODUCT_VERSION=$PRODUCT_VERSION >>$log
echo MW_VERSION$MW_VERSION >>$log
if [ ${PRODUCT_VERSION} -lt ${MW_VERSION} ]; then
printf $"A product having a newer version than this product is already installed.\n"
printf $"Perform one of the following operatons.\n"
printf $"a) Upgrade the version using the installer for the latest version.\n"
printf $"b) Change the installation identifier and newly install the older version of the product.\n"
echo
echo $"-- Press the [Enter] key. --"
read en
break
fi
if [ ${MW_VERSION} -lt ${PRODUCT_UPGRADE_MIN_VERSION} ]; then
clear
printf $"Cybozu(R) MailWise 2 or older is installed in the specified directory.\n"
printf $"You cannot upgrade to %s from Cybozu(R) MailWise 2 or older.\n\n" "$MSG_PRODUCT_NAME"
printf $"The process of upgrading to %s is as follows:\n\n" "$MSG_PRODUCT_NAME"
printf $"1. Upgrade from the older product to Cybozu(R) MailWise 3.\n"
printf $"2. Upgrade from Cybozu(R) MailWise 3 to %s.\n\n" "$MSG_PRODUCT_NAME"
printf $"For details on upgrading, see the following page:\n"
printf $" http://manual.cybozu.co.jp/mailwise3/install/verup_unix.html\n"
echo
exit 1
fi
if [ ${MW_VERSION} -lt 5000 ]; then
clear
printf $"The older product is currently installed in the specified directory.\n"
printf $"The older product will no longer be usable, if %s is installed.\n\n" "$MSG_PRODUCT_NAME"
printf $"Are you sure you want to install %s in this directory? \n\n" "$MSG_PRODUCT_NAME"
printf $"[Y](Install) / [N](Change the installation identifier) / [Q](Quit installation) : "
read reply leftover
case $reply in
y* | Y*)
VERSIONUP_TYPE=2
break 2
;;
n* | N*)
break 1
;;
q* | Q*)
clear
printf $"Installation has been cancelled.\n"
echo
exit 1
;;
*)
;;
esac
fi
selectmenu2
break
else
break 2
fi
done
fi
if [ $selected -eq 1 ]; then
clear
CGI_ROOT="${CGI_BIN}/${APP_NAME}"
if [ -e ${CGI_ROOT}/${EXE_NAME} ]; then
set `${CGI_ROOT}/${EXE_NAME} -v` > /dev/null
if [ $# -ne 1 ]; then
exit 1
fi
MW_VERSION=$1
if [ ${PRODUCT_VERSION} -lt ${MW_VERSION} ]; then
printf $"A product having a newer version than this product is already installed.\n"
printf $"Perform one of the following operatons.\n"
printf $"a) Upgrade the version using the installer for the latest version.\n"
printf $"b) Change the installation identifier and newly install the older version of the product.\n"
echo
echo $"-- Press the [Enter] key. --"
read en
continue
fi
if [ ${MW_VERSION} -ge 5000 ]; then
VERSIONUP_TYPE=1
else
VERSIONUP_TYPE=2
fi
else
exit 1
fi
break
elif [ $selected -eq 2 ]; then
while [ 1 ]; do
clear
printf $"===================== Confirm Uninstallation =====================\n"
echo
printf $"This product (%s) will be uninstalled. Is this OK?\n\n[Y](Yes) / [N](No) : " "$APP_NAME"
read reply leftover
case $reply in
y* | Y*)
break;;
n* | N*)
clear
printf $"Uninstallation has been cancelled.\n"
echo
exit 1;;
*)
;;
esac
done
uninstall
fi
done
if [ x"${APP_USER_DIR}" = x ]; then
while [ 1 ]; do
APP_USER_DIR="${USER_DIR_BASE}/${APP_NAME}"
clear
printf $"===================== Set Data Directory =====================\n"
echo
printf $"Enter the data directory.\n"
printf $"The data directory is the directory where product data files are located.\n"
printf $"\n"
printf $"Leave this blank and press the Enter key to use the default data directory \"%s\".\n" "$APP_USER_DIR"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
echo
printf "[${APP_USER_DIR}]: "
read reply leftover
if [ "x$reply" != x ]; then
APP_USER_DIR="$reply"
fi
if [ ! -d "$APP_USER_DIR/$CGI_MW_DIR" ]; then
break
fi
UNINSTALL_APP_NAME=`cd "$APP_USER_DIR" && ls uninstall_* | sed -e 's,uninstall_,,' | head -1`
if [ x"$UNINSTALL_APP_NAME" = x ]; then
break
fi
if [ ${VERSIONUP_TYPE} -ne 0 -a x"$UINISTALL_APP_NAME" = "$APP_NAME" ]; then
break
fi
echo
printf $"Another instance of Cybozu(R) Mailwise (%s) is already installed in the specified directory.\n" "$UNINSTALL_APP_NAME"
printf $"To install a new instance of Mailwise, specify a different directory.\n\n"
echo
echo $"-- Press the [Enter] key. --"
read en
continue
done
fi
if [ $selected -ne 1 ]; then
clear
printf $"===================== Set Document Root Directory =====================\n"
echo
WEB_PATH=`dirname ${CGI_BIN}`
for i in $WEB_PATH/htdocs $WEB_PATH/html $WEB_PATH/data $WEB_PATHS
do
if [ -d $i ]; then
WEB_ROOT=$i
break
fi
done
printf $"Enter the document root directory.\n\n"
printf $"The document root is the directory where product image files are located.\n"
printf $"\n"
printf $"Leave this blank and press the Enter key to use the default document root directory \"%s\".\n" "$WEB_ROOT"
printf $"Usually, there is no need to change the document root directory.\n\n"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
printf $"Upgrading to %s\n\n" "$MSG_PRODUCT_NAME"
printf $"Enter the same document root directory as the product currently in use.\n"
printf $"The document root directory can be found in the \"DocumentRoot\" section on the \"Operating Environment\" screen of the product in use.\n"
printf $"Example: If \"/var/www/html\" is displayed in the \"DocumentRoot\" section on the \"Operating environment\" screen of the product in use, the document root directory is \"/var/www/html\".\n"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
echo
printf "[${WEB_ROOT}]: "
read reply leftover
if [ "x$reply" != x ]; then
WEB_ROOT="$reply"
fi
fi
userconfig
clear
printf $"===================== Set Cron Task =====================\n"
echo
ENABLE_CRON_TASK=no
while [ 1 ]; do
echo -e $"Would you like to add a root's crontab entry for receiving e-mail automatically?"
printf "[Y] / [N] : "
read reply leftover
case $reply in
y* | Y*)
ENABLE_CRON_TASK=yes
break;;
n* | N*)
break;;
*)
;;
esac
done
agreed=
while [ "x$agreed" = x ]; do
installconfirmation
echo
printf $"Are you sure you want to install the product with these settings?\n\n[Y](Yes) / [N](No) : "
read reply leftover
case $reply in
y* | Y*)
agreed=1;;
n* | N*)
echo
printf $"Installation has been cancelled.\n"
echo
exit 0;;
*)
;;
esac
done
printf "\n[Deployment Configuration]\n" >> $log
printf "application name: ${APP_NAME}\n" >> $log
printf "httpd user: ${HTTPD_USER}\n" >> $log
printf "cgi-bin: ${CGI_BIN}\n" >> $log
printf "web root: ${WEB_ROOT}\n" >> $log
printf "\n[Installation]\n" >> $log
echo
echo
mkdir -p $CGI_ROOT 2> /dev/null
mkdir -p $APP_USER_DIR 2> /dev/null
diskfreespace="`df -mP ${CGI_ROOT} | tail -n 1 | awk '{print $4}'`"
diskfreespace_userdir="`df -mP ${APP_USER_DIR} | tail -n 1 | awk '{print $4}'`"
limit=25
limit_userdir=100
if [ ${VERSIONUP_TYPE} -eq 2 ]; then
datadirsize="`du -ms ${APP_USER_DIR}/${CGI_MW_DIR}/data | awk '{print $1}'`"
limit_userdir="`expr ${limit_userdir} + ${datadirsize} / 2`"
fi
if [ ${diskfreespace} -lt ${limit} ]; then
printf $"Not enough free disk space.\nPlease free disk space so that the Cybozu product can write in the following location: %s\n" "$CGI_ROOT"
echo
exit 1
fi
if [ ${diskfreespace_userdir} -lt ${limit_userdir} ]; then
printf $"Not enough free disk space.\nPlease free disk space so that the Cybozu product can write in the following location: %s\n" "$APP_USER_DIR"
echo
exit 1
fi
printf "diskfreespace check passed!\n" >> $log
CRONTAB_TASK_PATTERN="[ ]$CGI_ROOT/$EXE_NAME[ ][ ]*-x[ ][ ]*task"
printf $"Stopping Cron Task...\n"
crontab -u root -l > install/crontab.orig
grep -v "$CRONTAB_TASK_PATTERN" install/crontab.orig >install/crontab 2>/dev/null
crontab -u root install/crontab
printf "stopped cron task '$CGI_ROOT/$EXE_NAME -x task'\n" >> $log
cgi_owner=${HTTPD_USER}
if [ -f "${CGI_ROOT}/${EXE_NAME}" ]; then
cgi_owner=`stat -c '%u' "${CGI_ROOT}/${EXE_NAME}"`
fi
chown -R "$cgi_owner" "install/cgi/${EXE_NAME}" 2>/dev/null
STATUS_FILE="${CGI_ROOT}/ConvertDb.status"
PID_FILE="${CGI_ROOT}/ConvertDb.pid"
HEARTBEAT_FILE="${CGI_ROOT}/ConvertDb.beat"
LOST_BEAT_MAX=60
PROGRESS_UPDATE_INTERVAL=1
convert_handler()
{
yes_is_abort="$1"
msg="$2"
while [ 1 ]; do
echo -e "\n${msg}"
printf "[Y] / [N] : "
read reply leftover
case $reply in
y* | Y*)
yes=1
break;;
n* | N*)
yes=0
break;;
*)
;;
esac
done
if [ "$yes" = "1" -a "$yes_is_abort" = "1" ]; then
abort=1
elif [ "$yes" = "0" -a "$yes_is_abort" = "0" ]; then
abort=1
fi
if [ "$abort" == "1" ]; then
X_CYBOZU_MAILWISE_USER_DIR="$APP_USER_DIR" ./install/cgi/${EXE_NAME} -x convertdb -kill > /dev/null
X_CYBOZU_MAILWISE_USER_DIR="$APP_USER_DIR" ./install/cgi/${EXE_NAME} -x convertdb -rollback > /dev/null
rollback_data
signal_handler
exit 1
fi
}
rollback_data()
{
rm -f "$STATUS_FILE"
rm -f "$HEARTBEAT_FILE"
}
convert_signal_handler()
{
yes_is_abort=1
convert_handler "$yes_is_abort" $"Are you sure you want to quit convirting?"
}
freeze_handler()
{
yes_is_abort=0
convert_handler "$yes_is_abort" $"No reply from the converter. Are you sure you want to continiue?"
}
trap "convert_signal_handler" HUP INT QUIT TERM
show_progress()
{
str="$1"
echo -e "\033[0;0H${str}\033[0J"
}
format_remain_str()
{
remain=$1
if [ $remain -lt 0 ]; then
remain_str=""
else
hour=`expr $remain / 3600`
remain=`expr $remain - ${hour} \* 3600`
min=`expr $remain / 60`
sec=`expr $remain - $min \* 60`
if [ ${hour} -gt 0 ]; then
remain_str="${hour} "$"hours"", ${min} "$"minutes"", ${sec} "$"seconds"
elif [ ${min} -gt 0 ]; then
remain_str="${min} "$"minutes"", ${sec} "$"seconds"
else
remain_str="${sec} "$"seconds"
fi
fi
}
execute_convert()
{
rm -f $STATUS_FILE
rm -f $HEARTBEAT_FILE
X_CYBOZU_MAILWISE_USER_DIR="$APP_USER_DIR" ./install/cgi/${EXE_NAME} -x convertdb -b "$CGI_ROOT" -install 2>&1 | sed -e 's/^/[convertdb] /' >>$log &
echo "X_CYBOZU_MAILWISE_USER_DIR=\"$APP_USER_DIR\" ./install/cgi/${EXE_NAME} -x convertdb -b \"$CGI_ROOT\" -install > /dev/null &" >> $log
CONVERTER_PID=$!
show_progress $"Converting a database... "
loop=1
counter=0
remain=-1
prev_beat_size=0
lost_beat=0
freeze=0
failed=0
prev_beat=0
prev_counter=0
while [ $loop -eq 1 ] ; do
converter_running_pid=`ps -o pid= -p ${CONVERTER_PID}`
line=`tail -n 1 $STATUS_FILE 2> /dev/null`
if [ "$line" != "" ]; then
counter=`echo "$line" | awk '{ print $1 }'`
fi
if [ "$counter" != "$prev_counter" ]; then
prev_counter="$counter"
phase=`echo "$line" | awk '{ print $2 }'`
if [ "$phase" = "Check" -o "$phase" = "Convert" ]; then
progress=`echo "$line" | awk '{ print $3 }'`
remain=`echo "$line" | awk '{ print $4 }'`
elif [ "$phase" = "Success" ]; then
loop=0
progress=100
remain=0
elif [ "$phase" = "Fail" ]; then
failed=1
fi
fi
if [ "$loop" -eq 1 -a x"${converter_running_pid}" = x"" ]; then
failed=1
fi
if [ "$failed" -eq 1 ]; then
rollback_data
printf $"Version upgrading failed because the databese conversion is suspended.\nThe database is damaged or the disk space is not enough.\n"
printf "Data File convert failed.\n" >> $log
echo
exit 1
fi
format_remain_str $remain
if [ "$remain_str" = "" ]; then
status="["$"Completed"": ${progress} %]"
else
status="["$"Completed"": ${progress} %, "$"Time remaining"": ${remain_str}]"
fi
if [ "$phase" = "Check" ]; then
show_progress $"Checking a database... "" $status"
elif [ "$phase" = "Convert" -o "$phase" = "Success" ]; then
show_progress $"Converting a database... "" $status"
fi
if [ $loop -eq 1 ]; then
sleep $PROGRESS_UPDATE_INTERVAL
if [ -e $HEARTBEAT_FILE ]; then
beat_size=`cat $HEARTBEAT_FILE | wc -c`
else
beat_size=0
fi
if [ "$beat_size" != "$prev_beat_size" ]; then
prev_beat_size="$beat_size"
if [ $remain -gt 0 ]; then
remain=`expr ${remain} - ${PROGRESS_UPDATE_INTERVAL} - ${lost_beat}`
if [ $remain -lt 1 ]; then
remain=0
fi
fi
lost_beat=0
else
lost_beat=`expr ${lost_beat} + 1`
if [ $lost_beat -gt $LOST_BEAT_MAX ]; then
freeze_handler
lost_beat=0
fi
fi
fi
done
printf "Data File convert finished.\n" >> $log
}
if [ ${VERSIONUP_TYPE} -eq 2 ]; then
execute_convert
fi
printf $"Copying CGI Files...\n"
rm -f $CGI_ROOT/$EXE_NAME
cp -f install/cgi/$EXE_NAME $CGI_ROOT
mkdir -p $APP_USER_DIR/$CGI_MW_DIR 2> /dev/null
printf "CGI Files Copy finished.\n" >> $log
printf $"Creating a Config File...\n"
ini_userdir=""
if [ x"$CGI_ROOT" != x"${APP_USER_DIR}" ]; then
ini_userdir="UserDir=${APP_USER_DIR}"
fi
rm -f $CGI_ROOT/$INI_NAME
cat > $CGI_ROOT/$INI_NAME <<EOF
[Server]
${ini_userdir}
EOF
printf "Config File Create finished.\n" >> $log
if [ -d $APP_USER_DIR/$CGI_MW_DIR/page ]; then
printf $"Performing the backup of the Template Files...\n"
if [ -d $APP_USER_DIR/$CGI_MW_DIR/page/backup ]; then
rm -f $APP_USER_DIR/$CGI_MW_DIR/page/backup/*.html
else
mkdir -p $APP_USER_DIR/$CGI_MW_DIR/page/backup
fi
cp -f $APP_USER_DIR/$CGI_MW_DIR/page/*.html $APP_USER_DIR/$CGI_MW_DIR/page/backup
rm -f $APP_USER_DIR/$CGI_MW_DIR/page/*.html
printf "The backup of the Template Files Copy finished.\n" >> $log
else
mkdir -p $APP_USER_DIR/$CGI_MW_DIR/page
fi
printf $"Copying Template Files...\n"
cp -f install/page/*.html $APP_USER_DIR/$CGI_MW_DIR/page
printf "Template Files Copy finished.\n" >> $log
printf $"Copying Image Files...\n"
WEB_DIR=install/web_root
if [ ! -d ${WEB_ROOT}/${WEB_MW_DIR}/3rd_party_license ]; then
mkdir -p ${WEB_ROOT}/${WEB_MW_DIR}/3rd_party_license 2> /dev/null
fi
if [ ! -d ${WEB_ROOT}/${WEB_MW_DIR}/html ]; then
mkdir -p ${WEB_ROOT}/${WEB_MW_DIR}/html 2> /dev/null
fi
if [ ! -d ${WEB_ROOT}/${WEB_MW_DIR}/image ]; then
mkdir -p ${WEB_ROOT}/${WEB_MW_DIR}/image 2> /dev/null
fi
cp -rf ${WEB_DIR}/3rd_party_license/* ${WEB_ROOT}/${WEB_MW_DIR}/3rd_party_license/
printf "3rd_party_license Files Copy finished.\n" >> $log
cp -rf ${WEB_DIR}/html/* ${WEB_ROOT}/${WEB_MW_DIR}/html/
printf "Html Files Copy finished.\n" >> $log
cp -rf ${WEB_DIR}/image/* ${WEB_ROOT}/${WEB_MW_DIR}/image/
printf "Image Files Copy finished.\n" >> $log
if [ ! -d ${APP_USER_DIR}/${CGI_MW_DIR}/data ]; then
mkdir ${APP_USER_DIR}/${CGI_MW_DIR}/data
fi
MSG_FLAG=0
printf $"Copying Data Files...\n"
for a in `cd install/; find data -type d`; do
mkdir -p $APP_USER_DIR/$CGI_MW_DIR/$a
done
for a in `cd install/; find data -type f`; do
if [ ! -f $APP_USER_DIR/$CGI_MW_DIR/$a ]; then
cp -f install/$a $APP_USER_DIR/$CGI_MW_DIR/$a
printf "%s\n" $a >> $log
fi
done
printf "Data Files Copy finished.\n" >> $log
printf $"Copying LICENSE Files...\n"
rm -f $APP_USER_DIR/LICENSE
$MW_MESSAGES_ICONV_COMMAND < install/doc/LICENSE > $APP_USER_DIR/LICENSE
$MW_MESSAGES_ICONV_COMMAND < install/doc/LICENSE.en > $APP_USER_DIR/LICENSE.en
printf "LICENSE Files Copy finished.\n" >> $log
printf $"Copying README Files...\n"
rm -f $APP_USER_DIR/README
$MW_MESSAGES_ICONV_COMMAND < install/doc/README > $APP_USER_DIR/README
printf "README Files Copy finished.\n" >> $log
for d in file log session tmp dlsrc; do
if [ ! -d $APP_USER_DIR/$CGI_MW_DIR/$d ]; then
mkdir -p $APP_USER_DIR/$CGI_MW_DIR/$d
fi
done
if [ ! -e $CGI_ROOT/.htaccess ]; then
cp -f install/access/exception/.htaccess $CGI_ROOT/.htaccess
printf ".htaccess to CGI Directory Copy finished.\n" >> $log
fi
for i in data page file log session tmp dlsrc; do
if [ ! -e $APP_USER_DIR/$CGI_MW_DIR/$i/.htaccess ]; then
cp -f install/access/deny/.htaccess $APP_USER_DIR/$CGI_MW_DIR/$i/.htaccess
printf ".htaccess to $i Directory Copy finished.\n" >> $log
fi
done
if [ ${VERSIONUP_TYPE} -ne 0 ]; then
printf $"Upgrading a database...\n"
$CGI_ROOT/${EXE_NAME} -x upgrade 2>&1 | sed -e 's/^/[upgrade] /' >>$log
ret=$?
if [ $ret -ne 0 ]; then
printf $"Failed to upgrade the database.(%s)\n" "$ret"
printf "Failed to upgrade the database.\n" >> $log
echo
exit 1
fi
printf "Upgrade database finished.\n" >> $log
fi
printf $"Changing the owner of the directories and files...\n"
chown $HTTPD_USER $CGI_ROOT
chown $HTTPD_USER $CGI_ROOT/$EXE_NAME
chown $HTTPD_USER $CGI_ROOT/$INI_NAME
chown $HTTPD_USER $CGI_ROOT/.htaccess
chown -R $HTTPD_USER $APP_USER_DIR
chmod a+x $CGI_ROOT/$EXE_NAME
chmod -R a+rX $APP_USER_DIR
chown -R $HTTPD_USER ${WEB_ROOT}/${WEB_MW_DIR}
printf "The owner of the Directories and Files Change finished.\n" >> $log
printf $"Copying Uninstall Files...\n"
rm -f ${UNINST_SCRIPT}
cp -f install/uninstall_cbmw.sh ${UNINST_SCRIPT}
apply_config ${UNINST_SCRIPT} 1
chmod 700 ${UNINST_SCRIPT}
printf "Uninstall Files Copy finished.\n" >> $log
if [ x"$ENABLE_CRON_TASK" = x"yes" ]; then
printf $"Configuring Cron Task...\n"
grep "$CRONTAB_TASK_PATTERN" install/crontab.orig >>install/crontab 2>/dev/null
if [ $? -ne 0 ]; then
echo "0-59/1 * * * * $CGI_ROOT/$EXE_NAME -x task" >>install/crontab
fi
crontab -u root install/crontab
printf "Configured Cron Task.\n" >> $log
fi
MW_INSTALL_SUCCESS=yes
ACCESS_PATH="http://"$"(server IP address or hostname)""/"$"(CGI directory)""/"$"(installation identifier)""/${EXE_NAME}"
EXAMPLE_PATH1=$"Ex.: ""http://webserver.cybozu.co.jp/cgi-bin/${APP_NAME}/${EXE_NAME}"
EXAMPLE_PATH2=$"Ex.: ""http://10.10.203.55/cgi-bin/${APP_NAME}/${EXE_NAME}"
if [ $selected -eq 1 ]; then
clear
printf $"===================== Confirm Completion of Upgrade the version =====================\n"
echo
printf $"Version upgrade has completed normally.\n"
echo
printf "\nUpdate finishes at `env LANG=C date`\n" >> $log
else
clear
printf $"===================== Confirm Completion of Installation =====================\n"
echo
printf $"The installation has completed successfully.\n"
printf $"Read the README file before using.\n"
echo
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
printf $"The locations of the LICENSE Agreement and README files are as follows.\n"
echo
printf $"Location of LICENSE Agreement: ""${APP_USER_DIR}/LICENSE\n"
printf $"Location of README : ""${APP_USER_DIR}/README\n"
printf $"_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n"
echo
printf $"Access the following URL from a web browser.\n\n"
echo "$ACCESS_PATH"
echo "$EXAMPLE_PATH1"
echo "$EXAMPLE_PATH2"
echo
printf "\nInstallation finishes at `env LANG=C date`\n" >> $log
fi
exit 0