#!/bin/sh
# @function install Memcached-Server
function InstallMemcached()
{
    ShowResult "[green]正在安装Memcached服务器... [/green]" 1
    
    # install memcached
    eval cd ${_PATH_COMPILATION_} ${_SYS_SHOW_INSTALL_DETAILS_}
    eval rm -rf ./memcached-1.* ${_SYS_SHOW_INSTALL_DETAILS_}
    eval tar zxvf ${_PATH_SOFTWARE_}/memcached-1.* ${_SYS_SHOW_INSTALL_DETAILS_}
    eval cd memcached-1.* ${_SYS_SHOW_INSTALL_DETAILS_}
    
    # configure
    if [ ${_SYS_BIT_} -eq 64 ] ; then # x64
        eval ./configure --enable-64bit ${_SYS_SHOW_INSTALL_DETAILS_}
    else # i686
        eval ./configure ${_SYS_SHOW_INSTALL_DETAILS_}
    fi
    
    # make
    eval make ${_SYS_MAKE_EXT_} ${_SYS_SHOW_INSTALL_DETAILS_}
    eval make install ${_SYS_SHOW_INSTALL_DETAILS_}
    
    ShowStatus $? 1
    
    # set as a service
    eval sed -ri "s/{_mem_size_}/${_MEMCACHED_MAX_MEM_:-64m}/" ${_PATH_CONFIGS_}/memcached ${_SYS_SHOW_INSTALL_DETAILS_}
    
    eval \cp -f ${_PATH_CONFIGS_}/memcached /etc/init.d/memcached ${_SYS_SHOW_INSTALL_DETAILS_}
#    eval \cp -f ${_PATH_CONFIGS_}/memcached /usr/bin/ ${_SYS_SHOW_INSTALL_DETAILS_}
    eval chkconfig --add memcached ${_SYS_SHOW_INSTALL_DETAILS_}
    eval chmod +x /etc/init.d/memcached ${_SYS_SHOW_INSTALL_DETAILS_}
    
    ShowStatus $?
}