<commit_before>#!/bin/sh

# PHP-FPM can listen on a UNIX socket or a TCP port. Use 'tcp' if your web
# server will load balance to a pool of PHP-FPM servers. Else use sockets
# and avoid the TCP overhead.
PHP_LISTEN_MODE=${PHP_LISTEN_MODE:="socket"}

install_php()
{
	_version="$1"; if [ -z "$_version" ]; then _version="56"; fi

	tell_status "installing PHP $_version"

	_ports="php$_version"
	_modules="$2"

	if [ "$TOASTER_MYSQL" = "1" ]; then
		tell_status "including php mysql module"
		if [ "$_version" = "70" ]; then
			# php 70 doesn't have a plain mysql driver
			_modules="$_modules pdo_mysql"
		else
			_modules="$_modules pdo_mysql mysql"
		fi
	fi

	for m in $_modules
	do
		_ports="$_ports php$_version-$m"
	done

	# shellcheck disable=SC2086
	stage_pkg_install $_ports || exit
	install_php_newsyslog
}

install_php_newsyslog() {
	tell_status "enabling PHP-FPM log file rotation"
	tee "$STAGE_MNT/etc/newsyslog.conf.d/php-fpm" <<EO_FPM_NSL
# rotate the file after it reaches 1M
/var/log/php-fpm.log 600 7	1024	*	BCX	/var/run/php-fpm.pid 30
EO_FPM_NSL
}

configure_php_ini()
{
	local _php_ini="$STAGE_MNT/usr/local/etc/php.ini"

	if [ ! -z "$1" ]; then
		if [ -f "$ZFS_JAIL_MNT/$1/usr/local/etc/php.ini" ]; then
			tell_status "preserving php.ini"
			cp "$ZFS_JAIL_MNT/$1/usr/local/etc/php.ini" "$_php_ini"
			return
		fi
	fi

	cp "$STAGE_MNT/usr/local/etc/php.ini-production" "$_php_ini" || exit
	sed -i .bak \
		-e 's/^;date.timezone =/date.timezone = America\/Los_Angeles/' \
		-e '/^post_max_size/ s/8M/25M/' \
		-e '/^upload_max_filesize/ s/2M/25M/' \
		"$_php_ini"
}

configure_php_fpm() {

	tell_status "enable syslog for PHP-FPM"
	sed -i .bak \
		-e '/^;error_log/ s/^;//' \
		-e '/^error_log/ s/= .*/= syslog/' \
		"$STAGE_MNT/usr/local/etc/php-fpm.conf"
<commit_msg>Set php timezone auto (#216)<commit_after>#!/bin/sh

# PHP-FPM can listen on a UNIX socket or a TCP port. Use 'tcp' if your web
# server will load balance to a pool of PHP-FPM servers. Else use sockets
# and avoid the TCP overhead.
PHP_LISTEN_MODE=${PHP_LISTEN_MODE:="socket"}

install_php()
{
	_version="$1"; if [ -z "$_version" ]; then _version="56"; fi

	tell_status "installing PHP $_version"

	_ports="php$_version"
	_modules="$2"

	if [ "$TOASTER_MYSQL" = "1" ]; then
		tell_status "including php mysql module"
		if [ "$_version" = "70" ]; then
			# php 70 doesn't have a plain mysql driver
			_modules="$_modules pdo_mysql"
		else
			_modules="$_modules pdo_mysql mysql"
		fi
	fi

	for m in $_modules
	do
		_ports="$_ports php$_version-$m"
	done

	# shellcheck disable=SC2086
	stage_pkg_install $_ports || exit
	install_php_newsyslog
}

install_php_newsyslog() {
	tell_status "enabling PHP-FPM log file rotation"
	tee "$STAGE_MNT/etc/newsyslog.conf.d/php-fpm" <<EO_FPM_NSL
# rotate the file after it reaches 1M
/var/log/php-fpm.log 600 7	1024	*	BCX	/var/run/php-fpm.pid 30
EO_FPM_NSL
}

configure_php_ini()
{
	local _php_ini="$STAGE_MNT/usr/local/etc/php.ini"

	if [ ! -z "$1" ]; then
		if [ -f "$ZFS_JAIL_MNT/$1/usr/local/etc/php.ini" ]; then
			tell_status "preserving php.ini"
			cp "$ZFS_JAIL_MNT/$1/usr/local/etc/php.ini" "$_php_ini"
			return
		fi
	fi

	tell_status "getting the timezone"
	TZ=`md5 -q /etc/localtime`
	TIMEZONE=`find /usr/share/zoneinfo -type f | xargs md5 -r | grep  $TZ | awk '{print $2}' |cut -c21- `

	if [ -z "$TIMEZONE" ]; then
		TIMEZONE="America\/Los_Angeles"
	fi

	tell_status "Setting TIMEZONE to :  $TIMEZONE "

	cp "$STAGE_MNT/usr/local/etc/php.ini-production" "$_php_ini" || exit
	sed -i .bak \
		-e "s|^;date.timezone =|date.timezone = $TIMEZONE|" \
		-e '/^post_max_size/ s/8M/25M/' \
		-e '/^upload_max_filesize/ s/2M/25M/' \
		"$_php_ini"

}

configure_php_fpm() {

	tell_status "enable syslog for PHP-FPM"
	sed -i .bak \
		-e '/^;error_log/ s/^;//' \
		-e '/^error_log/ s/= .*/= syslog/' \
		"$STAGE_MNT/usr/local/etc/php-fpm.conf"

{'fraction_non_alphanumeric': 0.15671062839410396, 'fraction_numerical': 0.019136281355055598, 'mean_word_length': 3.5239766081871347, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2523569', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1617, 'n_words': 382}