#!/bin/bash
### Copyright 1999-2015. Parallels IP Holdings GmbH. All Rights Reserved.
#

#
# Plesk script
#


### Copyright 1999-2015. Parallels IP Holdings GmbH. All Rights Reserved.


get_phpini_var()
{
	[ -z "$1" ] && return
	cat $php_ini | perl -n -e 'next if(/^;/);  print $5 if(/^(\s*)'$1'(\s*)=(\s*)("*)(.*?)("|\s|;)/);'
}

# Copyright 1999-2014. Parallels IP Holdings GmbH. All Rights Reserved.

[ -z "$PLESK_INSTALLER_DEBUG" ] || set -x
[ -z "$PLESK_INSTALLER_STRICT_MODE" ] || set -e

set_session_path_perms()
{
	local php_ini="/etc/php.ini"

	local session_save_path=`php -c "$php_ini" -r "echo ini_get('session.save_path');" 2>/dev/null || get_phpini_var "session.save_path"`

	# On CentOS7 if session.save_path is not specified, it use /var/lib/php/session
	[ -n "$session_save_path" ] || session_save_path="/var/lib/php/session"

	[ -n "$session_save_path" -a -d "$session_save_path" ] || return 0
	[ "$session_save_path" = "/var/lib/php/session" -o "$session_save_path" = "/var/lib/php5" ] || return 0

	chown root:0 "$session_save_path"
	chmod 1733 "$session_save_path"
}

set_session_path_perms
