#!/bin/sh
# This script is written by DirectAdmin and Martynas Bendorius (smtalk)
BUILDSCRIPT_VER=1.1.44
NAME=custombuild
OS=`uname`
WORKDIR=/usr/local/directadmin/${NAME}
OPTIONS_CONF=${WORKDIR}/options.conf
VERSIONS_FILE=${WORKDIR}/versions.txt
VERSIONS_FILE_CL=${WORKDIR}/versions_cl.txt
LOCKFILE=${WORKDIR}/.custombuild
LOGFILE=${WORKDIR}/custombuild.log
PROFTPD_PREFIX=/usr
B64=0
CPU_CORES=1
LANG=C
LOG_IP=localhost
if [ `who | wc -l` -gt 0 ]; then
if [ ${OS} = "FreeBSD" ]; then
LOG_IP=`env | grep REMOTEHOST | cut -d= -f2`
else
LOG_IP=`echo $SSH_CLIENT | cut -d' ' -f1`
fi
fi
if [ ! -d ${WORKDIR}/patches ]; then
mkdir -p ${WORKDIR}/patches
chmod 700 ${WORKDIR}/patches
fi
if [ ! -e ${LOGFILE} ]; then
touch ${LOGFILE}
chmod 600 ${LOGFILE}
else
if [ ${OS} = "FreeBSD" ]; then
LOGSIZE=`stat -f %z ${LOGFILE}`
else
LOGSIZE=`stat -c %s ${LOGFILE}`
fi
#Rotate the logfile if the size is >10MB
if [ ${LOGSIZE} -gt 10485760 ]; then
rm -f ${LOGFILE}.1
mv ${LOGFILE} ${LOGFILE}.1
touch ${LOGFILE}
chmod 600 ${LOGFILE}
fi
fi
showVersion(){
echo "${BUILDSCRIPT_VER}";
}
B64COUNT=`uname -m | grep -c 64`
if [ "$B64COUNT" -eq 1 ]; then
B64=1
LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib:/lib64:/lib
export LD_LIBRARY_PATH
fi
if [ ${OS} = "FreeBSD" ]; then
#if [ "`sysctl -a | grep kern.threads.virtual_cpu | cut -d' ' -f2`" -gt 1 ]; then
# CPU_CORES="`sysctl -a | grep kern.threads.virtual_cpu | cut -d' ' -f2`"
#fi
CPU_CORES=`/sbin/sysctl hw.ncpu | cut -d\ -f2`
PROFTPD_PREFIX=/usr/local
else
if [ "`cat /proc/cpuinfo | grep 'model name' | wc -l`" -gt 0 ]; then
CPU_CORES="`cat /proc/cpuinfo | grep 'model name' | wc -l`"
fi
fi
#if [ -e /usr/lib64 ]; then
#if [ "`ls /usr/lib64/ | grep -v libmudflap | wc -l`" -gt "5" ]; then
# B64=1
# LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
# export LD_LIBRARY_PATH
#fi
#fi
#check path for /usr/local/bin
COUNT=`echo "${PATH}" | grep -c /usr/local/bin:`
if [ "${COUNT}" -eq 0 ]; then
export PATH=/usr/local/bin:$PATH
fi
DA_MYSQL=/usr/local/directadmin/conf/mysql.conf
#Set MySQL host
if [ -s $DA_MYSQL ] && [ `grep -c -e "^host=" ${DA_MYSQL}` -gt "0" ]; then
MYSQLHOST=`grep "^host=" ${DA_MYSQL} | cut -d= -f2`
else
MYSQLHOST=localhost
fi
# Main variables
HTTPDDIR=/etc/httpd
HTTPDCONF=/etc/httpd/conf
HTTPD_CONF=${HTTPDCONF}/httpd.conf
DEBIAN_VERSION=/etc/debian_version
WWWDIR=/var/www/html
# Variables for jailed shell
SHELLS=/etc/shells
JAIL_DIR=${WORKDIR}/jail
DACONF_FILE=/usr/local/directadmin/conf/directadmin.conf
DACONF_TEMPLATE_FILE=/usr/local/directadmin/data/templates/directadmin.conf
SERVICES=/usr/local/directadmin/data/admin/services.status
#CWD=`pwd`
CWD=${WORKDIR}
FORCE=0
HIDE_CHANGES=0
# Applications variables
APPUSER=webapps
ECHO=echo
if [ "${OS}" = "FreeBSD" ]; then
WGET=/usr/local/bin/wget
TAR=/usr/bin/tar
CHOWN=/usr/sbin/chown
MYSQL_DATA=/home/mysql
MYSQL_BIN=/usr/local/mysql/bin/mysql
else
WGET=/usr/bin/wget
TAR=/bin/tar
CHOWN=/bin/chown
if [ -e /etc/debian_version ]; then
MYSQL_DATA=/home/mysql
MYSQL_BIN=/usr/local/mysql/bin/mysql
ECHO=/bin/echo
else
MYSQL_DATA=/var/lib/mysql
MYSQL_BIN=/usr/bin/mysql
fi
fi
# Check if workdir exists
if [ ! -d ${WORKDIR} ]; then
echo "Directory ${WORKDIR} does not exist."
exit 1
fi
# Write options.conf
if [ ! -e ${OPTIONS_CONF} ]; then
echo "Cannot find ${OPTIONS_CONF}, writing defaults."
echo -n "" > ${OPTIONS_CONF}
echo "#PHP settings. default_php possible values - 4 or 5, php5_ver - 5.2, 5.3 or 5.4" >> ${OPTIONS_CONF}
echo "default_php=5" >> ${OPTIONS_CONF}
echo "php5_ver=5.2" >> ${OPTIONS_CONF}
echo "php4_cli=no" >> ${OPTIONS_CONF}
echo "php4_cgi=no" >> ${OPTIONS_CONF}
echo "php5_cli=yes" >> ${OPTIONS_CONF}
echo "php5_cgi=no" >> ${OPTIONS_CONF}
echo "ioncube=no" >> ${OPTIONS_CONF}
echo "zend=no" >> ${OPTIONS_CONF}
echo "#Possible values - recommended or dist" >> ${OPTIONS_CONF}
echo "php_ini_type=recommended" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Possible values - 5.0, 5.1, 5.5, 5.6" >> ${OPTIONS_CONF}
echo "mysql=5.0" >> ${OPTIONS_CONF}
echo "mysql_inst=no" >> ${OPTIONS_CONF}
echo "mysql_backup=yes" >> ${OPTIONS_CONF}
echo "mysql_backup_dir=/usr/local/directadmin/custombuild/mysql_backups" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Possible values - 1.3, 2.0, 2.2 or 2.4" >> ${OPTIONS_CONF}
echo "apache_ver=2.2" >> ${OPTIONS_CONF}
echo "secure_htaccess=no" >> ${OPTIONS_CONF}
echo "harden-symlinks-patch=yes" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Web applications" >> ${OPTIONS_CONF}
echo "phpmyadmin=yes" >> ${OPTIONS_CONF}
echo "atmail=no" >> ${OPTIONS_CONF}
echo "squirrelmail=yes" >> ${OPTIONS_CONF}
echo "roundcube=no" >> ${OPTIONS_CONF}
echo "uebimiau=no" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Mail options" >> ${OPTIONS_CONF}
echo "exim=no" >> ${OPTIONS_CONF}
echo "eximconf=no" >> ${OPTIONS_CONF}
echo "clamav=no" >> ${OPTIONS_CONF}
echo "mailman=no" >> ${OPTIONS_CONF}
echo "spamassassin=no" >> ${OPTIONS_CONF}
echo "mail-header-patch=yes" >> ${OPTIONS_CONF}
echo "dovecot=yes" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Statistics" >> ${OPTIONS_CONF}
echo "awstats=no" >> ${OPTIONS_CONF}
echo "webalizer=yes" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#FTP options" >> ${OPTIONS_CONF}
echo "proftpd=yes" >> ${OPTIONS_CONF}
echo "pureftpd=no" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Jailed shell (beta)" >> ${OPTIONS_CONF}
echo "jail=no" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Autoconf/automake/libtool options" >> ${OPTIONS_CONF}
echo "autoconf=yes" >> ${OPTIONS_CONF}
echo "automake=yes" >> ${OPTIONS_CONF}
echo "libtool=yes" >> ${OPTIONS_CONF}
echo "curl=yes" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#new version of zlib and libxml2 (experts only)" >> ${OPTIONS_CONF}
echo "new_zlib=no" >> ${OPTIONS_CONF}
echo "new_xml2=no" >> ${OPTIONS_CONF}
echo "new_suphp=no" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#CustomBuild options" >> ${OPTIONS_CONF}
echo "custombuild=1.1" >> ${OPTIONS_CONF}
echo "autover=no" >> ${OPTIONS_CONF}
echo "bold=yes" >> ${OPTIONS_CONF}
echo "clean=yes" >> ${OPTIONS_CONF}
echo "clean_old_tarballs=no" >> ${OPTIONS_CONF}
echo "clean_old_webapps=yes" >> ${OPTIONS_CONF}
echo "downloadserver=files.directadmin.com" >> ${OPTIONS_CONF}
echo "cleanapache=no" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Cron settings" >> ${OPTIONS_CONF}
echo "cron=no" >> ${OPTIONS_CONF}
echo "cron_frequency=daily" >> ${OPTIONS_CONF}
echo "email=email@domain.com" >> ${OPTIONS_CONF}
echo "notifications=yes" >> ${OPTIONS_CONF}
echo "da_autoupdate=no" >> ${OPTIONS_CONF}
echo "updates=no" >> ${OPTIONS_CONF}
echo "webapps_updates=yes" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#CustomBuild 1.2 settings" >> ${OPTIONS_CONF}
echo "php6_cli=no" >> ${OPTIONS_CONF}
echo "php6_cgi=no" >> ${OPTIONS_CONF}
echo "php_ini=no" >> ${OPTIONS_CONF}
echo "" >> ${OPTIONS_CONF}
echo "#Cloudlinux settings" >> ${OPTIONS_CONF}
echo "cloudlinux=no" >> ${OPTIONS_CONF}
echo "cagefs=no" >> ${OPTIONS_CONF}
fi
# Check if options.conf exists
if [ ! -e ${OPTIONS_CONF} ]; then
echo "Options file options.conf does not exist."
exit 1
fi
####################################################
writeLog()
{
echo "`date +'%Y-%m-%d %H:%m:%S'` ${LOG_IP}: $@" >> ${LOGFILE}
}
getVer()
{
grep -m1 $1: ${VERSIONS_FILE} | cut -d ':' -f 2
}
getMD5()
{
grep -m1 $1: ${VERSIONS_FILE} | cut -d ':' -f 3
}
removeLockfile()
{
rm -f ${LOCKFILE}
trap - INT TERM EXIT
}
do_exit()
{
if [ "$2" != "" ]; then
echo "$2";
fi
removeLockfile
exit $1
}
getOpt()
{
#$1 is option name
#$2 is default value
COUNT_OPT="`grep -c -e "^$1=" ${OPTIONS_CONF}`"
if [ "${COUNT_OPT}" -eq 0 ]; then
echo "$1=$2" >> ${OPTIONS_CONF}
fi
COUNT_OPT="`grep -c -e "^$1=" ${OPTIONS_CONF}`"
if [ "${COUNT_OPT}" -ne 1 ]; then
do_exit 1 "${OPTIONS_CONF} value $1 is damaged. Please check or delete it."
fi
grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2
}
have_php_system()
{
#Checks to see if we can use system() based on the disable_functions
if [ ! -s "${PHP_INI}" ]; then
echo 1;
return;
fi
C=`grep -c ^disable_functions ${PHP_INI}`
if [ "${C}" -eq 0 ]; then
echo 1;
return;
fi
C=`grep ^disable_functions ${PHP_INI} | grep -c system`
if [ "${C}" -eq 1 ]; then
echo 0;
return;
fi
echo 1;
return;
}
secure_phpini(){
if [ -e $1 ]; then
COUNT_DISABLE_FUNCT="`grep -c -e disable_functions $1`"
if [ "${COUNT_DISABLE_FUNCT}" -gt 0 ]; then
CURRENT_DISABLE_FUNCT="`grep -m1 'disable_functions' $1`"
NEW_DISABLE_FUNCT="exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source"
perl -pi -e "s#${CURRENT_DISABLE_FUNCT}#disable_functions \= ${NEW_DISABLE_FUNCT}#" $1
else
echo "Unable to find disable_functions in $1"
fi
perl -pi -e 's/^register_globals = On/register_globals = Off/' $1
fi
}
#sets the value of $1 to $2 in the file $3
setVal()
{
if [ ! -e $3 ]; then
return;
fi
COUNT=`grep -c ${1}= ${3}`
if [ "$COUNT" -eq 0 ]; then
#ok, it's not there, add it.
echo "$1=$2" >> $3
return;
else
#ok, the value is already in the file $3, so use perl to regex it.
perl -pi -e "s/`grep ${1}= ${3}`/${1}=${2}/" ${3}
fi
}
#A > B: 1
#A = B: 0
#A < B: -1
#3rd option is descriptor
version_cmp()
{
A=`echo $1 | cut -d- -f1`
B=`echo $2 | cut -d- -f1`
if [ "$A" = "" ] || [ "$B" = "" ]; then
echo "version_cmp has a blank value when checking $3";
return;
fi
A1=`echo $A | cut -d. -f1`
B1=`echo $B | cut -d. -f1`
if [ "$A1" -gt "$B1" ]; then
echo 1;
return;
fi
if [ "$A1" -lt "$B1" ]; then
echo -1;
return;
fi
A2=`echo $A | cut -d. -f2`
B2=`echo $B | cut -d. -f2`
if [ "$A2" -gt "$B2" ]; then
echo 1;
return;
fi
if [ "$A2" -lt "$B2" ]; then
echo -1;
return;
fi
A3=`echo $A | cut -d. -f3`
B3=`echo $B | cut -d. -f3`
if [ "$A3" = "" ] && [ "$B3" = "" ]; then
echo 0;
return;
fi
if [ "$A3" = "" ]; then
echo 1;
return;
fi
if [ "$B3" = "" ]; then
echo -1;
return;
fi
if [ "$A3" -gt "$B3" ]; then
echo 1;
return;
fi
if [ "$A3" -lt "$B3" ]; then
echo -1;
return;
fi
echo 0;
}
####################################################
#CloudLinux
CLINUX_OPT=`getOpt cloudlinux no`
CAGEFS_OPT=`getOpt cagefs no`
# Read options.conf
MYSQLBACK_OPT=`getOpt mysql_backup yes`
MYSQLBACKDIR_OPT=`getOpt mysql_backup_dir /usr/local/directadmin/custombuild/mysql_backups`
MYSQL_OPT=`getOpt mysql 5.0`
MYSQLINST_OPT=`getOpt mysql_inst no`
DEFPHP=`getOpt default_php 5`
PHP4_CLI_OPT=`getOpt php4_cli no`
PHP4_CGI_OPT=`getOpt php4_cgi no`
PHP5_CLI_OPT=`getOpt php5_cli yes`
PHP5_CGI_OPT=`getOpt php5_cgi no`
PHP5_VER_OPT=`getOpt php5_ver 5.2`
APACHE_OPT=`getOpt apache_ver 2.2`
SECURE_HTACCESS=`getOpt secure_htaccess no`
HARDEN_SYMLINK_PATCH=`getOpt harden-symlinks-patch no`
OLD_APR_UTIL=`getOpt old_apr_util no`
MAIL_HEADER_PATCH=`getOpt mail-header-patch yes`
DOVECOT_OPT=`getOpt dovecot yes`
PROFTPD_OPT=`getOpt proftpd yes`
PUREFTPD_OPT=`getOpt pureftpd no`
ZEND_OPT=`getOpt zend no`
IONCUBE_OPT=`getOpt ioncube no`
EXIM_OPT=`getOpt exim no`
EXIMCONF_OPT=`getOpt eximconf no`
JAIL_OPT=`getOpt jail no`
SPAMASSASSIN_OPT=`getOpt spamassassin no`
CLAMAV_OPT=`getOpt clamav no`
MAILMAN_OPT=`getOpt mailman no`
CUSTOMBUILD_OPT=`getOpt custombuild 1.1`
DOWNLOADSERVER_OPT=`getOpt downloadserver files.directadmin.com`
AUTOCONF_OPT=`getOpt autoconf yes`
AUTOMAKE_OPT=`getOpt automake yes`
LIBTOOL_OPT=`getOpt libtool yes`
CURL_OPT=`getOpt curl yes`
NEW_ZLIB_OPT=`getOpt new_zlib no`
NEW_XML2_OPT=`getOpt new_xml2 no`
NEW_SUPHP_OPT=`getOpt new_suphp no`
WEBPATH=http://${DOWNLOADSERVER_OPT}/services/custombuild
WEBPATH_SERVICES=http://${DOWNLOADSERVER_OPT}/services
WEBPATH_BACKUP=http://69.162.69.58/services/custombuild
WEBPATH_CL=http://repo.cloudlinux.com/cloudlinux/sources/da
#Applications
ATMAIL_OPT=`getOpt atmail no`
PHPMYADMIN_OPT=`getOpt phpmyadmin yes`
SQUIRRELMAIL_OPT=`getOpt squirrelmail yes`
ROUNDCUBE_OPT=`getOpt roundcube no`
UEBIMIAU_OPT=`getOpt uebimiau no`
#Statistics software
AWSTATS_OPT=`getOpt awstats no`
WEBALIZER_OPT=`getOpt webalizer yes`
#CustomBuild
AUTOVER_OPT=`getOpt autover no`
BOLD_OPT=`getOpt bold yes`
CLEAN_OPT=`getOpt clean yes`
CLEAN_OLD_TARBALLS_OPT=`getOpt clean_old_tarballs yes`
CLEAN_OLD_WEBAPPS_OPT=`getOpt clean_old_webapps yes`
#Cron
CRON_OPT=`getOpt cron no`
CRON_FREQUENCY_OPT=`getOpt cron_frequency daily`
EMAIL_OPT=`getOpt email email@domain.com`
NOTIFICATIONS_OPT=`getOpt notifications yes`
DA_AUTOUPDATE_OPT=`getOpt da_autoupdate no`
UPDATES_OPT=`getOpt updates no`
WEBAPPS_UPDATES_OPT=`getOpt webapps_updates yes`
# Variables for bolded text
boldon=""
boldoff=""
if [ "${BOLD_OPT}" = "yes" ]; then
boldon="`tput -Txterm bold`"
boldoff="`tput -Txterm sgr0`"
fi
setOpt()
{
#$1 is option name
#$2 is value
if [ "$1" = "email" ]; then
OPT_VALUE1="`grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2 | cut -d\@ -f 1`"
OPT_VALUE2="`grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2 | cut -d\@ -f 2`"
OPT_NEW_VALUE1="`echo "$2" | cut -d\@ -f 1`"
OPT_NEW_VALUE2="`echo "$2" | cut -d\@ -f 2`"
perl -pi -e "s#$1=${OPT_VALUE1}\@${OPT_VALUE2}#$1=${OPT_NEW_VALUE1}\@${OPT_NEW_VALUE2}#" ${WORKDIR}/options.conf
if [ "${HIDE_CHANGES}" = "0" ]; then
echo "Changed ${boldon}$1${boldoff} option from ${boldon}${OPT_VALUE1}@${OPT_VALUE2}${boldoff} to ${boldon}$2${boldoff}"
fi
else
OPT_VALUE="`grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2`"
perl -pi -e "s#$1=${OPT_VALUE}#$1=$2#" ${WORKDIR}/options.conf
if [ "${HIDE_CHANGES}" = "0" ]; then
echo "Changed ${boldon}$1${boldoff} option from ${boldon}${OPT_VALUE}${boldoff} to ${boldon}$2${boldoff}"
fi
fi
}
doChecks()
{
if [ "${PHP4_CLI_OPT}" = "yes" ] && [ "${PHP5_CLI_OPT}" = "yes" ]; then
echo "Cannot install PHP4 and PHP5 as CLI."
exit 1
elif [ "${PHP4_CLI_OPT}" = "yes" ] && [ "${PHP4_CGI_OPT}" = "yes" ] || [ "${PHP5_CLI_OPT}" = "yes" ] && [ "${PHP5_CGI_OPT}" = "yes" ]; then
echo "Cannot install one PHP version as CLI and CGI."
exit 1
elif [ "${PHP4_CLI_OPT}" = "no" ] && [ "${PHP4_CGI_OPT}" = "no" ] && [ "${PHP5_CLI_OPT}" = "no" ] && [ "${PHP5_CGI_OPT}" = "no" ]; then
echo "You do not have any PHP version set in options.conf."
exit 1
fi
if [ "${PROFTPD_OPT}" = "yes" ] && [ "${PUREFTPD_OPT}" = "yes" ]; then
echo "Cannot install both Pure-FTPd and ProFTPd. Please deselect one in options.conf file."
exit 1
fi
if [ "${DEFPHP}" != "4" ] && [ "${DEFPHP}" != "5" ]; then
echo "There is wrong default PHP in ${OPTIONS_CONF} set."
exit 1
fi
if [ "${PHP5_VER_OPT}" != "5.2" ] && [ "${PHP5_VER_OPT}" != "5.3" ] && [ "${PHP5_VER_OPT}" != "5.4" ]; then
echo "Wrong php5_ver value set in ${OPTIONS_CONF}."
exit 1
fi
if [ "${APACHE_OPT}" != "1.3" ] && [ "${APACHE_OPT}" != "2.0" ] && [ "${APACHE_OPT}" != "2.2" ] && [ "${APACHE_OPT}" != "2.4" ]; then
echo "Wrong apache_ver value set in ${OPTIONS_CONF}."
exit 1
fi
if [ "${MYSQL_OPT}" != "5.0" ] && [ "${MYSQL_OPT}" != "5.1" ] && [ "${MYSQL_OPT}" != "5.5" ] && [ "${MYSQL_OPT}" != "5.6" ] && [ "${MYSQL_OPT}" != "4.1" ]; then
echo "Wrong mysql_ver value set in ${OPTIONS_CONF}."
exit 1
fi
if [ "${PUREFTPD_OPT}" = "yes" ]; then
if [ -s "$DACONF_FILE" ]; then
UNIFIED_FTP=`/usr/local/directadmin/directadmin c | grep unified_ftp_password_file | cut -d= -f2`
if [ "$UNIFIED_FTP" != "1" ]; then
echo "unified_ftp_password_file is not set to 1. You must convert before you can use pureftpd";
echo "Please read this guide: http://www.directadmin.com/features.php?id=1134";
echo "";
echo "Simulation:";
echo " cd /usr/local/directadmin";
echo " echo 'action=convert&value=unifiedftp&simulate=yes' >> data/task.queue";
echo " ./dataskq d1";
echo "";
echo "Conversion:";
echo " cd /usr/local/directadmin";
echo " echo 'unified_ftp_password_file=1' >> conf/directadmin.conf";
echo " echo 'action=convert&value=unifiedftp' >> data/task.queue";
echo " ./dataskq d1";
echo "";
exit 1;
fi
fi
fi
if [ "${CRON_FREQUENCY_OPT}" != "daily" ] && [ "${CRON_FREQUENCY_OPT}" != "weekly" ] && [ "${CRON_FREQUENCY_OPT}" != "monthly" ]; then
echo "Wrong cron_frequency value set in ${OPTIONS_CONF}";
echo "Current value: ${CRON_FREQUENCY_OPT}";
echo "Valid values: daily, weekly, or monthly";
exit 1;
fi
}
#Which PHP is the default one?
if [ "${DEFPHP}" = "4" ]; then
ADDITPHP=5
elif [ "${DEFPHP}" = "5" ]; then
ADDITPHP=4
fi
#Is the default PHP running as CGI?
DEFPHP_CGI="`grep php${DEFPHP}_cgi ${WORKDIR}/options.conf | cut -d= -f2`"
# Get apache version from directadmin.conf
DACONF_APACHE_VER=1.3
if [ -e ${DACONF_FILE} ]; then
DACONF_APACHE_VER=`grep "^apache_ver=" ${DACONF_FILE} | cut -d= -f2`
fi
# Download versions.txt if AUTOVER_OPT is set to "yes"
if [ "${AUTOVER_OPT}" = "yes" ]; then
wget ${WEBPATH}/versions.txt -O ${VERSIONS_FILE} 2> /dev/null
fi
# Check if ld.so.conf has /usr/local/lib
if [ ! -e /etc/ld.so.conf ] || [ "`grep -c -E '/usr/local/lib$' /etc/ld.so.conf`" = "0" ]; then
echo "/usr/local/lib" >> /etc/ld.so.conf
/sbin/ldconfig
fi
####################################################
checkMD5()
{
#$1 is the local file
#$2 is the versions.txt variable
#return values:
#1 for error, try agian
#0 for nothing to report.
if [ ${OS} = "FreeBSD" ]; then
MD5SUM=/sbin/md5
else
MD5SUM=/usr/bin/md5sum
fi
if [ ! -e $MD5SUM ]; then
echo 0;
return;
fi
if [ ! -e "$1" ]; then
echo 1;
fi
VMD5=`getMD5 $2`
if [ "$VMD5" = "" ]; then
echo 0;
return;
fi
if [ ${OS} = "FreeBSD" ]; then
FMD5=`$MD5SUM -q $1`
else
FMD5=`$MD5SUM $1 | cut -d\ -f1`
fi
if [ "$FMD5" = "$VMD5" ]; then
echo 0;
else
echo 1;
fi
}
getFile() {
cd ${CWD};
if [ ! -s ${1} ]
then
$ECHO -e "Downloading\t\t$1...";
if [ ${OS} = "FreeBSD" ]; then
fetch -o ${CWD}/${1} ${WEBPATH}/${1};
else
wget -O ${CWD}/${1} ${WEBPATH}/${1}
fi
if [ ! -s $1 ]
then
echo "Downloaded file ${CWD}/${1} does not exist or is empty after download";
echo "cwd is: `pwd`";
echo "Fileserver might be down, using the backup file server..";
if [ ${OS} = "FreeBSD" ]; then
fetch -o ${CWD}/${1} ${WEBPATH_BACKUP}/${1};
else
wget -O ${CWD}/${1} ${WEBPATH_BACKUP}/${1};
fi
fi
else
$ECHO -e "File already exists:\t${1}";
fi
if [ "$#" -eq 2 ]; then
M=`checkMD5 ${1} ${2}`
if [ "$M" != "0" ]; then
echo "";
echo "${boldon}*** MD5 Checksum for $1 Failed. Redownloading...***${boldoff}";
echo "";
#we will call it recursively but will *not* pass $2 for the md5 cus it would get stuck in a loop.
rm -f $1
getFile $1
M=`checkMD5 ${1} ${2}`
if [ "$M" != "0" ]; then
echo "";
echo "";
echo "${boldon}*** MD5 Checksum for $1 failed *again*.***${boldoff}";
echo "The md5 checksum value may be incorrect, or a wrong file is being downloaded.";
echo "Install continuing with this possibly corrupted file. (it may also be fine)";
echo "";
echo "";
else
echo "MD5 Checksum on $1 passed."
fi
else
echo "MD5 Checksum on $1 passed."
fi
fi
}
getMD5CL()
{
grep -m1 $1: ${VERSIONS_FILE_CL} | cut -d ':' -f 3
}
checkMD5CL()
{
#$1 is the local file
#$2 is the versions_cl.txt variable
#return values:
#1 for error, try agian
#0 for nothing to report.
MD5SUM=/usr/bin/md5sum
if [ ! -e $MD5SUM ]; then
echo 0;
return;
fi
if [ ! -e "$1" ]; then
echo 1;
fi
VMD5=`getMD5CL $2`
if [ "$VMD5" = "" ]; then
echo 0;
return;
fi
FMD5=`$MD5SUM $1 | cut -d\ -f1`
if [ "$FMD5" = "$VMD5" ]; then
echo 0;
else
echo 1;
fi
}
getFileCL() {
cd ${CWD};
if [ ! -s ${1} ]
then
$ECHO -e "Downloading\t\t$1...";
wget -O ${CWD}/${1} ${WEBPATH_CL}/${1}
tar xzf ${1}
fi
if [ "$#" -eq 2 ]; then
M=`checkMD5CL ${1} ${2}`
if [ "$M" != "0" ]; then
echo "";
echo "${boldon}*** MD5 Checksum for $1 Failed. Redownloading...***${boldoff}";
echo "";
#we will call it recursively but will *not* pass $2 for the md5 cus it would get stuck in a loop.
rm -f $1
getFileCL $1
tar xzf ${1}
M=`checkMD5CL ${1} ${2}`
if [ "$M" != "0" ]; then
echo "";
echo "";
echo "${boldon}*** MD5 Checksum for $1 failed *again*.***${boldoff}";
echo "The md5 checksum value may be incorrect, or a wrong file is being downloaded.";
echo "Install continuing with this possibly corrupted file. (it may also be fine)";
echo "";
echo "";
fi
fi
fi
}
if [ "${CLINUX_OPT}" = "yes" ]; then
wget ${WEBPATH_CL}/versions.txt -O ${VERSIONS_FILE_CL} 2> /dev/null
getFileCL cl-apache-patches.tar.gz cl-apache-patches
getFileCL mod_hostinglimits.tar.gz mod_hostinglimits
fi
####################################################
# Rewrite directadmin-vhosts.conf
doVhosts(){
if [ ! -d ${HTTPDCONF}/extra ]; then
mkdir -p ${HTTPDCONF}/extra
fi
echo -n '' > ${HTTPDCONF}/extra/directadmin-vhosts.conf
#for i in `ls /usr/local/directadmin/data/users`; do { echo "Include /usr/local/directadmin/data/users/$i/httpd.conf" >> ${HTTPDCONF}/extra/directadmin-vhosts.conf; }; done;
for i in `ls /usr/local/directadmin/data/users/*/httpd.conf`; do { echo "Include $i" >> ${HTTPDCONF}/extra/directadmin-vhosts.conf; }; done;
}
####################################################
# init.d scripts
if [ "${OS}" = "FreeBSD" ]; then
INITDDIR=/usr/local/etc/rc.d
else
INITDDIR=/etc/init.d
fi
# check if we have versions.txt
if [ ! -s ${VERSIONS_FILE} ]; then
cd ${WORKDIR}
getFile versions.txt
fi
if [ ! -s ${VERSIONS_FILE} ]; then
echo "There is no versions.txt file. Unable to download."
exit 0;
fi
#####################################################
# User Variables
DIRECTADMIN_VER=`getVer directadmin`
MODSSL_VER=`getVer mod_ssl`
if [ "${APACHE_OPT}" = "1.3" ]; then
APACHE_VER=`getVer apache`
elif [ "${APACHE_OPT}" = "2.0" ]; then
APACHE2_VER=`getVer apache2.0`
elif [ "${APACHE_OPT}" = "2.2" ]; then
APACHE2_VER=`getVer apache2.2`
elif [ "${APACHE_OPT}" = "2.4" ]; then
APACHE2_VER=`getVer apache2.4`
fi
APR_VER=`getVer apr`
APR_UTIL_VER=`getVer apr-util`
if [ "${OLD_APR_UTIL}" = "yes" ]; then
APR_UTIL_VER=1.4.1
#apache 2.4.7 requires apr-util 1.5.0
#but with old_apr_util, we don't have it, so fall back.
if [ "${APACHE_OPT}" = "2.4" ]; then
AP2_MINOR_VER=`echo ${APACHE2_VER} | cut -d. -f3`
if [ "${AP2_MINOR_VER}" -ge 7 ]; then
echo "${boldon}old_apr_util=yes is set. Apache ${APACHE2_VER} requires apr-util 1.5.0 or newer.${boldoff}";
echo "${boldon}Forcing the apache version back to 2.4.6${boldoff}";
APACHE2_VER=2.4.6
fi
fi
fi
PHP4_VER=`getVer php4`
PHP_INI_SOURCE=php.ini-dist
if [ "${PHP5_VER_OPT}" = "5.2" ]; then
PHP5_VER=`getVer php5`
elif [ "${PHP5_VER_OPT}" = "5.3" ]; then
PHP5_VER=`getVer php53`
PHP_INI_SOURCE=php.ini-production
elif [ "${PHP5_VER_OPT}" = "5.4" ]; then
PHP5_VER=`getVer php54`
PHP_INI_SOURCE=php.ini-production
fi
if [ "${MYSQL_OPT}" = "5.0" ]; then
MYSQL_VER=`getVer mysql5.0`
MYSQL_REL=`getVer mysql5.0_release`
elif [ "${MYSQL_OPT}" = "5.1" ]; then
MYSQL_VER=`getVer mysql5.1`
MYSQL_REL=`getVer mysql5.1_release`
elif [ "${MYSQL_OPT}" = "5.5" ]; then
MYSQL_VER=`getVer mysql5.5`
MYSQL_REL=`getVer mysql5.5_release`
elif [ "${MYSQL_OPT}" = "5.6" ]; then
MYSQL_VER=`getVer mysql5.6`
MYSQL_REL=`getVer mysql5.6_release`
elif [ "${MYSQL_OPT}" = "4.1" ]; then
MYSQL_VER=`getVer mysql4.1`
MYSQL_REL=`getVer mysql4.1_release`
fi
if [ "$MYSQL_REL" = "" ]; then
MYSQL_REL=0;
fi
#http://choon.net/opensource/php/php-${PHP_VER}-mail-header.patch
APPLY_MAIL_HEADER_PATCH=${MAIL_HEADER_PATCH}
MAIL_HEADER_FILE_PHP4=php-${PHP4_VER}-mail-header.patch
MAIL_HEADER_FILE_PHP5=php-${PHP5_VER}-mail-header.patch
if [ "${APPLY_MAIL_HEADER_PATCH}" = "yes" ]; then
if [ "${PHP5_VER_OPT}" != "5.2" ]; then
echo "mail-header-patch=yes is set in the options.conf, but is not required with this php version.";
echo "To enable the X-Mail header, set mail.add_x_header to 1 in your php.ini";
fi
fi
PCRE_VER=`getVer pcre`
CURL_VER=`getVer curl`
ZLIB_VER=`getVer zlib`
MCRYPT_VER=`getVer mcrypt`
if [ "${APACHE_OPT}" = "1.3" ]; then
MODPERL_VER=`getVer mod_perl`
MODPERL_INDEX=mod_perl
elif [ "${APACHE_OPT}" = "2.0" ] || [ "${APACHE_OPT}" = "2.2" ] || [ "${APACHE_OPT}" = "2.4" ]; then
MODPERL_VER=`getVer mod_perl2`
MODPERL_INDEX=mod_perl2
fi
MHASH_VER=`getVer mhash`
SUPHP_VER=`getVer suphp`
if [ "$NEW_SUPHP_OPT" = "yes" ]; then
SUPHP_VER=`getVer suphp_current`
fi
DOVECOT_VER=`getVer dovecot`
EXIM_VER=`getVer exim`
PROFTPD_VER=`getVer proftpd`
PUREFTPD_VER=`getVer pureftpd`
AUTOCONF_VER=`getVer autoconf`
AUTOMAKE_VER=`getVer automake`
M4_VER=`getVer m4`
LIBTOOL_VER=`getVer libtool`
LIBXML2_VER=`getVer libxml2`
LIBXSLT_VER=`getVer libxslt`
FREETYPE_VER=`getVer freetype`
ICONV_VER=`getVer iconv`
ICU_VER=`getVer icu4c`
CLAMAV_VER=`getVer clamav`
MAILMAN_VER=`getVer mailman`
AWSTATS_VER=`getVer awstats`
if [ "$NEW_ZLIB_OPT" = "yes" ]; then
ZLIB_VER=`getVer zlib-current`
LIBXML2_VER=`getVer libxml2-current`
fi
if [ "$NEW_XML2_OPT" = "yes" ]; then
LIBXML2_VER=`getVer libxml2-current`
fi
ZEND_VER=`getVer ZendOptimizer-linux-glibc23-i386`
FBSD4_ZEND_VER=`getVer ZendOptimizer-freebsd4.3-i386`
FBSD5_ZEND_VER=`getVer ZendOptimizer-freebsd5.4-i386`
FBSD6_64_ZEND_VER=`getVer ZendOptimizer-freebsd6.0-amd64`
IONCUBE_VER=`getVer ioncube_loaders_lin_x86`
FBSD4_IONCUBE_VER=`getVer ioncube_loaders_fre_4_x86`
if [ "${B64}" = "1" ]; then
PNG_VER=`getVer libpng64`
else
PNG_VER=`getVer libpng`
fi
# Applications versions
if [ "${PHP5_CLI_OPT}" = "yes" ] || [ "${PHP5_CGI_OPT}" = "yes" ]; then
if [ "${DEFPHP}" = "5" ]; then
PHPMYADMIN_MAIN=3
PHPMYADMIN_VER=`getVer phpmyadmin3`
else
PHPMYADMIN_MAIN=2
PHPMYADMIN_VER=`getVer phpmyadmin`
fi
else
PHPMYADMIN_MAIN=2
PHPMYADMIN_VER=`getVer phpmyadmin`
fi
ATMAIL_VER=`getVer atmail`
ROUNDCUBE_VER=`getVer roundcubemail`
ROUNDCUBE_MAJOR_VER=`echo ${ROUNDCUBE_VER} | cut -d. -f1`
SQUIRRELMAIL_VER=`getVer squirrelmail`
SQUIRRELMAIL_LOCALE_VER=`getVer squirrelmail_locale`
UEBIMIAU_VER=`getVer uebimiau`
roundcube_version()
{
RCVERFILE=/var/www/html/roundcube/program/include/iniset.php
if [ ! -e $RCVERFILE ]; then
echo 0;
return;
fi
grep RCMAIL_VERSION $RCVERFILE | cut -d\' -f4
}
# Jailed shell
JAIL_VER=`getVer jail`
COREUTILS_VER=`getVer coreutils`
NB_SMTP_VER=`getVer nbsmtp`
# SpamAssassin versions
SPAMASSASSIN_VER=`getVer spamassassin`
# Variable for proftpd
PROFTPD_CONFIGURE=configure/proftpd/configure.proftpd
if [ -e custom/proftpd/configure.proftpd ]; then
PROFTPD_CONFIGURE=custom/proftpd/configure.proftpd
fi
# Variable for pureftpd
PUREFTPD_CONFIGURE=configure/pureftpd/configure.pureftpd
if [ -e custom/pureftpd/configure.pureftpd ]; then
PUREFTPD_CONFIGURE=custom/pureftpd/configure.pureftpd
fi
# Variables for apache
APACHE_SSL_CONFIGURE=configure/ap1/configure.apache_ssl
if [ -e custom/ap1/configure.apache_ssl ]; then
APACHE_SSL_CONFIGURE=custom/ap1/configure.apache_ssl
fi
APACHE2_CONFIGURE=configure/ap2/configure.apache
if [ -e custom/ap2/configure.apache ]; then
APACHE2_CONFIGURE=custom/ap2/configure.apache
fi
SUPHP_HTTPD=/etc/httpd/conf/extra/httpd-suphp.conf
PHP_HANDLERS_HTTPD=/etc/httpd/conf/extra/httpd-php-handlers.conf
if [ "${APACHE_OPT}" = "1.3" ]; then
PHP4_CONFIGURE=configure/ap1/configure.php4
if [ -e custom/ap1/configure.php4 ]; then
PHP4_CONFIGURE=custom/ap1/configure.php4
fi
PHP5_CONFIGURE=configure/ap1/configure.php5
if [ -e custom/ap1/configure.php5 ]; then
PHP5_CONFIGURE=custom/ap1/configure.php5
fi
elif [ "${APACHE_OPT}" = "2.0" ] || [ "${APACHE_OPT}" = "2.2" ] || [ "${APACHE_OPT}" = "2.4" ]; then
PHP4_CONFIGURE=configure/ap2/configure.php4
if [ -e custom/ap2/configure.php4 ]; then
PHP4_CONFIGURE=custom/ap2/configure.php4
fi
PHP5_CONFIGURE=configure/ap2/configure.php5
if [ -e custom/ap2/configure.php5 ]; then
PHP5_CONFIGURE=custom/ap2/configure.php5
fi
else
echo "Cannot find Apache ${APACHE_OPT} configure files."
fi
AP1CONFDIR=${WORKDIR}/configure/ap1/conf
AP1CUSTOMCONFDIR=0
#custom/configure isn't supposed to be there
if [ -d ${WORKDIR}/custom/configure/ap1/conf ]; then
AP1CUSTOMCONFDIR=${WORKDIR}/custom/configure/ap1/conf
fi
if [ -d ${WORKDIR}/custom/ap1/conf ]; then
AP1CUSTOMCONFDIR=${WORKDIR}/custom/ap1/conf
fi
AP2CONFDIR=${WORKDIR}/configure/ap2/conf
AP2CUSTOMCONFDIR=0
if [ -d ${WORKDIR}/custom/configure/ap2/conf ]; then
AP2CUSTOMCONFDIR=${WORKDIR}/custom/configure/ap2/conf
fi
if [ -d ${WORKDIR}/custom/ap2/conf ]; then
AP2CUSTOMCONFDIR=${WORKDIR}/custom/ap2/conf
fi
AP2CERTCONF=configure/ap2/cert_config
if [ -e custom/configure/ap2/cert_config ]; then
AP2CERTCONF=custom/configure/ap2/cert_config
fi
if [ -e custom/ap2/cert_config ]; then
AP2CERTCONF=custom/ap2/cert_config
fi
# Variables for suPHP
PHP4_CONFIGURE_SUPHP=configure/suphp/configure.php4
if [ -e custom/suphp/configure.php4 ]; then
PHP4_CONFIGURE_SUPHP=custom/suphp/configure.php4
fi
PHP5_CONFIGURE_SUPHP=configure/suphp/configure.php5
if [ -e custom/suphp/configure.php5 ]; then
PHP5_CONFIGURE_SUPHP=custom/suphp/configure.php5
fi
SUPHP_CONFIGURE=configure/suphp/configure.suphp
if [ -e custom/suphp/configure.suphp ]; then
SUPHP_CONFIGURE=custom/suphp/configure.suphp
fi
SUPHP_PATH=/usr/local/suphp
SUPHP_CONF_FILE=${SUPHP_PATH}/etc/suphp.conf
SUPHP_SO=/usr/lib/apache/mod_suphp.so
PHP_INI=/usr/local/lib/php.ini
PHP_INI_SUPHP4=/usr/local/etc/php4/cgi/php.ini
PHP_INI_SUPHP5=/usr/local/etc/php5/cgi/php.ini
PHP_BIN=/usr/local/bin/php
PHP_BIN_SUPHP5=/usr/local/php5/bin/php-cgi
PHP_BIN_SUPHP4=/usr/local/php4/bin/php
#custom script configs
PMA_CONFIG=${CWD}/custom/phpmyadmin/config.inc.php
PMA_THEMES=${CWD}/custom/phpmyadmin/themes
SQUIRREL_CONFIG=${CWD}/custom/squirrelmail/config.php
ROUNDCUBE_CONFIG=${CWD}/custom/roundcube/config.inc.php
ROUNDCUBE_CONFIG_DB=${ROUNDCUBE_CONFIG}
ROUNDCUBE_CONFIG_OLD=${CWD}/custom/roundcube/main.inc.php
ROUNDCUBE_CONFIG_DB_OLD=${CWD}/custom/roundcube/db.inc.php
if [ ${ROUNDCUBE_MAJOR_VER} -eq 0 ]; then
ROUNDCUBE_CONFIG=${ROUNDCUBE_CONFIG_OLD}
ROUNDCUBE_CONFIG_DB=${ROUNDCUBE_CONFIG_DB_OLD}
fi
ROUNDCUBE_PLUGINS=${CWD}/custom/roundcube/plugins
ROOT_GRP=root
if [ ${OS} = "FreeBSD" ]; then
ROOT_GRP=wheel
fi
USER_INPUT=1
INPUT_VALUE=d
if [ ${OS} = "FreeBSD" ]; then
OS_VER=`uname -r | cut -d- -f1`
elif [ -e /etc/fedora-release ]; then
OS=fedora
if [ "`cat /etc/fedora-release | awk '{ print $1, $2 }'`" = "Fedora Core" ]; then
OS_VER=`cat /etc/fedora-release | awk '{ print $4 }'`
elif [ "`cat /etc/fedora-release | awk '{ print $1, $2 }'`" = "Fedora release" ]; then
OS_VER=`cat /etc/fedora-release | awk '{ print $3 }'`
fi
elif [ -e ${DEBIAN_VERSION} ]; then
OS_VER=3.1
else
OS_VER=`cat /etc/redhat-release | cut -d\ -f5`
if [ "${OS_VER}" = "" ]; then
OS_VER=`cat /etc/redhat-release | cut -d\ -f1`
fi
fi
if [ ! -e /usr/bin/m4 ]; then
if [ -e /usr/bin/yum ]; then
yum -y install m4
fi
fi
MAINVER=""
if [ "${OS}" = "FreeBSD" ]; then
MAINVER=`echo ${OS_VER} | cut -d. -f1`
case "${MAINVER}" in
4) ZEND_VER=$FBSD4_ZEND_VER
ZENDNAME=ZendOptimizer-${ZEND_VER}-freebsd4.3-i386
IONCUBE_VER=$FBSD4_IONCUBE_VER
IONCUBENAME=ioncube_loaders_fre_4_x86
;;
5) ZEND_VER=$FBSD5_ZEND_VER
ZENDNAME=ZendOptimizer-${ZEND_VER}-freebsd5.4-i386
IONCUBENAME=ioncube_loaders_fre_5_x86
;;
6) ZENDNAME=ZendOptimizer-${ZEND_VER}-freebsd6.0-i386
IONCUBENAME=ioncube_loaders_fre_6_x86
;;
7) ZENDNAME=ZendOptimizer-${ZEND_VER}-freebsd6.0-i386
IONCUBENAME=ioncube_loaders_fre_7_x86
if [ ${B64} -eq 1 ]; then
IONCUBENAME=ioncube_loaders_fre_7_x86-64
fi
;;
8) IONCUBENAME=ioncube_loaders_fre_8_x86-64
;;
9) IONCUBENAME=ioncube_loaders_fre_9_x86-64
;;
esac
else
ZENDNAME=ZendOptimizer-${ZEND_VER}-linux-glibc23-i386
IONCUBENAME=ioncube_loaders_lin_x86
if [ "${PHP5_VER_OPT}" = "5.3" ]; then
if [ "${PHP5_CLI_OPT}" = "yes" ] || [ "${PHP5_CGI_OPT}" = "yes" ]; then
ZENDNAME=ZendGuardLoader-php-5.3-linux-glibc23-i386
fi
fi
fi
if [ ${B64} -eq 1 ]; then
if [ "${OS}" = "FreeBSD" ]; then
ZEND_VER=$FBSD6_64_ZEND_VER
ZENDNAME=ZendOptimizer-${ZEND_VER}-freebsd6.0-amd64
else
ZENDNAME=ZendOptimizer-${ZEND_VER}-linux-glibc23-x86_64
IONCUBENAME=ioncube_loaders_lin_x86-64
if [ "${PHP5_VER_OPT}" = "5.3" ]; then
if [ "${PHP5_CLI_OPT}" = "yes" ] || [ "${PHP5_CGI_OPT}" = "yes" ]; then
ZENDNAME=ZendGuardLoader-php-5.3-linux-glibc23-x86_64
fi
fi
fi
fi
ZENDFILE=${ZENDNAME}.tar.gz
IONCUBEFILE=${IONCUBENAME}.tar.gz
JPEGFILE=jpegsrc.v6b.tar.gz
JPEGDIR=jpeg-6b
WEBALIZER_VER=`getVer webalizer`
WEBALIZER=webalizer-${WEBALIZER_VER}
WEBALIZER_FILE=webalizer-${WEBALIZER_VER}-src.tgz
# More variables for jailed shell
SU_FILE=${JAIL_DIR}/ap${APACHE_OPT}/suexec.c
#####################################################
ensureVersion() {
PERL_VER=`perl -v | head -n2 | tail -n1 | cut -d\ -f4 | cut -dv -f2`
NUM1=`echo $PERL_VER | cut -d. -f1`
NUM2=`echo $PERL_VER | cut -d. -f2`
NUM3=`echo $PERL_VER | cut -d. -f3`
if [ $NUM1 -gt 5 ]; then
return 1;
fi
if [ $NUM2 -gt 6 ]; then
return 1;
fi
if [ $NUM3 -gt 0 ]; then
return 1;
fi
echo "Your perl version is $PERL_VER. You require at least perl 5.6.1 for Mail-SpamAssassin-${SPAMASSASSIN_VER}.";
exit 1;
}
####################################################
downloadMake() {
cd $CWD
VER=`getVer ${1}`
NAME=${1}-${VER}
getFile ${NAME}.tar.gz ${1}
tar xvzf ${NAME}.tar.gz
cd ${NAME}
perl Makefile.PL
make
make install
cd $CWD
}
####################################################
clean_tarball(){
#clean_tarball name current_version extension
if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
echo "Skipping $1 tarball, needs more arguments in doclean_old_tarballs()."
return;
fi
for i in `ls ${WORKDIR} | grep "${1}-[0-9]" | grep -v "$2" | grep "$3"`; do {
rm -f ${WORKDIR}/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing ${WORKDIR}/$i...";
fi
};
done;
}
doclean_old_tarballs() {
if [ "${APACHE_OPT}" = "1.3" ]; then
clean_tarball apache ${APACHE_VER} tar.gz
clean_tarball mod_ssl ${MODSSL_VER}-${APACHE_VER} tar.gz;
elif [ "${APACHE_OPT}" = "2.0" ] || [ "${APACHE_OPT}" = "2.2" ] || [ "${APACHE_OPT}" = "2.4" ]; then
clean_tarball httpd ${APACHE2_VER} tar.gz;
clean_tarball apr ${APR_VER} tar.gz;
clean_tarball apr-util ${APR_UTIL_VER} tar.gz;
fi
clean_tarball mod_perl ${MODPERL_VER} tar.gz;
clean_tarball clamav ${CLAMAV_VER} tar.gz;
clean_tarball Mail-SpamAssassin ${SPAMASSASSIN_VER} tar.gz;
clean_tarball curl ${CURL_VER} tar.gz;
clean_tarball pcre ${PCRE_VER} tar.gz;
clean_tarball zlib ${ZLIB_VER} tar.gz;
clean_tarball libpng ${PNG_VER} tar.gz;
clean_tarball libmcrypt ${MCRYPT_VER} tar.gz;
clean_tarball mhash ${MHASH_VER} tar.gz;
clean_tarball freetype ${FREETYPE_VER} tar.gz;
clean_tarball libiconv ${ICONV_VER} tar.gz;
clean_tarball libxslt ${LIBXSLT_VER} tar.gz;
clean_tarball libxml2 ${LIBXML2_VER} tar.gz;
clean_tarball icu4c ${ICU_VER}-src tgz;
clean_tarball ZendOptimizer ${ZEND_VER} tar.gz;
clean_tarball webalizer ${WEBALIZER_VER}-src tgz;
clean_tarball proftpd ${PROFTPD_VER} tar.gz;
clean_tarball pure-ftpd ${PUREFTPD_VER} tar.gz;
clean_tarball ${MODPERL_INDEX} ${MODPERL_VER} tar.gz;
clean_tarball dovecot ${DOVECOT_VER} tar.gz;
clean_tarball exim ${EXIM_VER} tar.gz;
clean_tarball suphp ${SUPHP_VER} tar.gz;
clean_tarball autoconf ${AUTOCONF_VER} tar.gz;
clean_tarball m4 ${M4_VER} tar.gz;
clean_tarball automake ${AUTOMAKE_VER} tar.gz;
clean_tarball libtool ${LIBTOOL_VER} tar.gz;
clean_tarball coreutils ${COREUTILS_VER} tar.gz;
clean_tarball roundcubemail ${ROUNDCUBE_VER} tar.gz;
clean_tarball squirrelmail ${SQUIRRELMAIL_VER} tar.gz;
clean_tarball awstats ${AWSTATS_VER} tar.gz;
clean_tarball atmail ${ATMAIL_VER} tar.gz;
clean_tarball phpMyAdmin ${PHPMYADMIN_VER} tar.gz;
#PHP bit needs to be different
for i in `ls ${WORKDIR} | grep 'php' | grep -v "${PHP5}" | grep -v "${PHP4}" | grep 'tar.gz'`; do {
rm -f ${WORKDIR}/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing ${WORKDIR}/$i...";
fi
};
done;
#PHP bit for mail-header-patch needs to be different
for i in `ls ${WORKDIR} | grep '^php-' | grep -v "${PHP5_VER}" | grep -v "${PHP4_VER}"`; do {
rm -f ${WORKDIR}/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing ${WORKDIR}/$i...";
fi
};
done;
}
####################################################
doclean_old_webapps() {
if [ "${CLEAN_OLD_WEBAPPS_OPT}" != "yes" ]; then
echo "You cannot clean webapps, because you do not have it set in options.conf file.";
exit 1;
fi
#Clean phpMyAdmin
if [ "${PHPMYADMIN_OPT}" = "yes" ] && [ -e /var/www/html/phpMyAdmin ]; then
PHPMYADMIN_CUR=`ls -ld /var/www/html/phpMyAdmin | cut -d\> -f2 | cut -d- -f2,3,4`
for i in `ls /var/www/html/ | grep phpMyAdmin- | grep -v "${PHPMYADMIN_CUR}"`; do {
rm -rf /var/www/html/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing /var/www/html/$i...";
fi
};
done;
fi
#Clean SquirrelMail
if [ "${SQUIRRELMAIL_OPT}" = "yes" ] && [ -e /var/www/html/squirrelmail ]; then
SQUIRRELMAIL_CUR=`ls -ld /var/www/html/squirrelmail | cut -d\> -f2 | cut -d- -f2,3`
for i in `ls /var/www/html/ | grep squirrelmail- | grep -v -e "${SQUIRRELMAIL_CUR}\$"`; do {
rm -rf /var/www/html/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing /var/www/html/$i...";
fi
};
done;
fi
#Clean Atmail
if [ "${ATMAIL_OPT}" = "yes" ] && [ -e /var/www/html/atmail ]; then
ATMAIL_CUR=`ls -ld /var/www/html/atmail | cut -d\> -f2 | cut -d- -f2`
for i in `ls /var/www/html/ | grep atmail- | grep -v "${ATMAIL_CUR}"`; do {
rm -rf /var/www/html/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing /var/www/html/$i...";
fi
};
done;
fi
#Clean RoundCube
if [ "${ROUNDCUBE_OPT}" = "yes" ] && [ -e /var/www/html/roundcube ]; then
#ROUNDCUBE_CUR=`ls -ld /var/www/html/roundcube | cut -d\> -f2 | cut -d- -f2`
ROUNDCUBE_CUR=`roundcube_version`
for i in `ls /var/www/html/ | grep roundcubemail- | grep -v "${ROUNDCUBE_CUR}"`; do {
rm -rf /var/www/html/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing /var/www/html/$i...";
fi
};
done;
fi
#Clean AWstats
if [ "${AWSTATS_OPT}" = "yes" ] && [ -e /usr/local/awstats ]; then
AWSTATS_CUR=`ls -ld /usr/local/awstats | cut -d\> -f2 | cut -d- -f2`
for i in `ls /usr/local/ | grep awstats- | grep -v "${AWSTATS_CUR}"`; do {
rm -rf /usr/local/$i;
if [ "${CLEAN_OPT}" = "no" ]; then
echo "Removing /usr/local/$i...";
fi
};
done;
fi
}
#####################################################
doClean() {
cd ${CWD}
if [ -e .custombuild ]; then
return;
fi
rm -rf apache_${APACHE_VER};
rm -rf mod_ssl-${MODSSL_VER}-${APACHE_VER};
rm -rf php-${PHP4_VER};
rm -rf php-${PHP5_VER};
rm -rf mod_perl-${MODPERL_VER};
rm -rf curl-${CURL_VER};
rm -rf pcre-${PCRE_VER};
rm -rf zlib-${ZLIB_VER};
rm -rf ${JPEGDIR};
rm -rf libpng-${PNG_VER};
rm -rf libmcrypt-${MCRYPT_VER};
rm -rf mhash-${MHASH_VER};
rm -rf freetype-${FREETYPE_VER};
rm -rf libiconv-${ICONV_VER};
rm -rf libxslt-${LIBXSLT_VER};
rm -rf libxml2-${LIBXML2_VER};
rm -rf icu4c-${ICU_VER}-src;
rm -rf icu;
rm -rf ${ZENDNAME};
rm -rf ${WEBALIZER};
rm -rf proftpd-${PROFTPD_VER};
rm -rf pure-ftpd-${PUREFTPD_VER};
rm -rf httpd-${APACHE2_VER};
rm -rf ${MODPERL2_DIR};
rm -rf dovecot-${DOVECOT_VER};
rm -rf exim-${EXIM_VER};
rm -rf suphp-${SUPHP_VER}
rm -rf autoconf-${AUTOCONF_VER};
rm -rf m4-${M4_VER};
rm -rf automake-${AUTOMAKE_VER};
rm -rf libtool-${LIBTOOL_VER};
rm -rf Mail-SpamAssassin-${SPAMASSASSIN_VER};
rm -rf clamav-${CLAMAV_VER};
rm -rf mailman-${MAILMAN_VER};
# Jailed shell
rm -rf coreutils-${COREUTILS_VER}
rm -f ${JAIL_DIR}/su
rm -f ${JAIL_DIR}/jail
rm -rf nbsmtp-${NB_SMTP_VER}
rm -f nbsmtp
if [ "${CLEAN_OLD_TARBALLS_OPT}" = "yes" ]; then
doclean_old_tarballs;
fi
if [ "${CLEAN_OLD_WEBAPPS_OPT}" = "yes" ]; then
doclean_old_webapps;
fi
if [ "${CLEAN_OPT}" = "no" ]; then
echo "All clean!";
fi
}
####################################################
if [ "${CLEAN_OPT}" = "yes" ]; then
doClean;
fi
####################################################
showHelp() {
echo " +--------------------------------------------------------+";
echo " | |";
echo " | DirectAdmin WebServices Installer |";
echo " | Written by Martynas Bendorius and DirectAdmin |";
echo " | Version: ${BUILDSCRIPT_VER} |";
echo " | |";
echo " +--------------------------------------------------------+";
echo " | To build everything run: |";
echo " | $0 all |";
echo " | |";
echo " | ${boldon}NOTE${boldoff}: Command all will compile everything as it is set |";
echo " | in the options.conf file, please take a look at |";
echo " | \"${boldon}$0 options${boldoff}\"! |";
echo " +--------------------------------------------------------+";
echo " | Install/update server components: |";
echo " | $0 apache |";
echo " | $0 autoconf |";
echo " | $0 automake |";
echo " | $0 awstats |";
echo " | $0 clamav |";
echo " | $0 curl |";
echo " | $0 dovecot |";
echo " | $0 exim |";
echo " | $0 freetype |";
echo " | $0 iconv |";
echo " | $0 icu |";
echo " | $0 ioncube |";
echo " | $0 libjpeg |";
echo " | $0 libpng |";
echo " | $0 libtool |";
echo " | $0 libxml2 |";
echo " | $0 libxslt |";
echo " | $0 m4 |";
echo " | $0 mailman |";
echo " | $0 mcrypt |";
echo " | $0 mhash |";
echo " | $0 mod_perl |";
echo " | $0 mysql |";
echo " | $0 pcre |";
echo " | $0 php |";
echo " | $0 proftpd |";
echo " | $0 pureftpd |";
echo " | $0 suphp |";
echo " | $0 spamassassin |";
echo " | $0 webalizer |";
echo " | $0 zend |";
echo " | $0 zlib |";
echo " +--------------------------------------------------------+";
echo " | Components configuration options: |";
echo " | $0 exim_conf |";
echo " | $0 rewrite_confs |";
echo " | $0 secure_php |";
echo " +--------------------------------------------------------+";
echo " | Install/update web applications: |";
echo " | $0 phpmyadmin |";
echo " | $0 atmail |";
echo " | $0 roundcube |";
echo " | $0 squirrelmail |";
echo " | $0 uebimiau |";
echo " +--------------------------------------------------------+";
echo " | CustomBuild related options/functions: |";
echo " | $0 create_options |";
echo " | $0 cron |";
echo " | $0 options |";
echo " | $0 set option_name value |";
echo " | $0 set_fastest |";
echo " | $0 set_fastest_quiet |";
echo " | $0 update_da |";
echo " | $0 update_versions |";
echo " | $0 update_webapps |";
echo " | $0 used_configs |";
echo " | $0 versions |";
echo " +--------------------------------------------------------+";
echo " | Jailed shell (beta): |";
echo " | $0 all_jail |";
echo " | $0 coreutils |";
echo " | $0 shell |";
echo " | $0 smtp_mail |";
echo " | ./jail/jail_user.sh ${boldon}user${boldoff} |";
echo " +--------------------------------------------------------+";
echo " | Remove old build data: |";
echo " | $0 clean |";
echo " | $0 clean_old_webapps |";
echo " +--------------------------------------------------------+";
echo " | Get latest build script or (and) data: |";
echo " | $0 update |";
echo " | $0 update_script |";
echo " +--------------------------------------------------------+";
echo " | Get data for current build script: |";
echo " | $0 update_data |";
echo " +--------------------------------------------------------+";
echo " | Recommended ${boldon}for experienced users only (!)${boldoff}: |";
echo " | $0 php5-cli |";
echo " | $0 php6-cli |";
echo " | $0 php5-cgi |";
echo " | $0 php6-cgi |";
echo " | $0 todovecot |";
echo " +--------------------------------------------------------+";
echo " | You can pass a 2nd argument to automate the input: |";
echo " | $0