Added brepo php support
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
Name: hestiacp-php-selector
|
Name: hestiacp-php-selector
|
||||||
Summary: Utility for manage php cli for HestiaCP
|
Summary: Utility for manage php cli for HestiaCP
|
||||||
Version: 0.1.0
|
Version: 0.2.0
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}.%{brepo_dist}.<CI_CNT>.<B_CNT>
|
||||||
License: GPL-2.0-or-later
|
License: GPL-2.0-or-later
|
||||||
Group: System Environment/Base
|
Group: System Environment/Base
|
||||||
URL: https://www.inferit.ru
|
URL: https://www.inferit.ru
|
||||||
@@ -42,7 +42,7 @@ if [ $1 -eq 1 ]; then
|
|||||||
/usr/local/hestia_php_selector/hestiacp_php_selector_installer install
|
/usr/local/hestia_php_selector/hestiacp_php_selector_installer install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
%postun
|
%preun
|
||||||
if [ $1 -eq 0 ]; then
|
if [ $1 -eq 0 ]; then
|
||||||
/usr/local/hestia_php_selector/hestiacp_php_selector_installer delete
|
/usr/local/hestia_php_selector/hestiacp_php_selector_installer delete
|
||||||
fi
|
fi
|
||||||
@@ -59,5 +59,8 @@ fi
|
|||||||
/usr/local/hestia_php_selector/*
|
/usr/local/hestia_php_selector/*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Thu Jan 16 2025 Alexey Berezhok <a@bayrepo.ru> 0.2.0-1
|
||||||
|
- Added support brepo php's
|
||||||
|
|
||||||
* Wed Aug 21 2024 Alexey Berezhok <a@bayrepo.ru> 0.1.0-1
|
* Wed Aug 21 2024 Alexey Berezhok <a@bayrepo.ru> 0.1.0-1
|
||||||
- Added hestiacp-php-selector
|
- Added hestiacp-php-selector
|
||||||
|
|||||||
16
installer.sh
16
installer.sh
@@ -5,8 +5,15 @@ function restore_system() {
|
|||||||
if [ "$current_php" == "/usr/bin/hestiacp-php-selector" ]; then
|
if [ "$current_php" == "/usr/bin/hestiacp-php-selector" ]; then
|
||||||
if [ -e /etc/hestia_php_selector/system/php.path ]; then
|
if [ -e /etc/hestia_php_selector/system/php.path ]; then
|
||||||
php_sys=$(cat /etc/hestia_php_selector/system/php.path)
|
php_sys=$(cat /etc/hestia_php_selector/system/php.path)
|
||||||
if [ -n "$php_sys" ]; then
|
if [ -n "$php_sys" -o "$php_sys" == "/usr/bin/hestiacp-php-selector" ]; then
|
||||||
update-alternatives --display php | grep "/usr/bin/php82"
|
inst_tp="/usr/bin/php82"
|
||||||
|
if [ -e /usr/local/hestia/conf/hestia.conf ]; then
|
||||||
|
res=$(cat /usr/local/hestia/conf/hestia.conf | grep "LOCAL_PHP" | grep "yes")
|
||||||
|
if [ -n "$res" ]; then
|
||||||
|
inst_tp="/opt/brepo/php82/bin/php"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
update-alternatives --display php | grep "$inst_tp"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
update-alternatives --set php "$php_sys"
|
update-alternatives --set php "$php_sys"
|
||||||
else
|
else
|
||||||
@@ -34,13 +41,16 @@ fi
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
install)
|
install)
|
||||||
echo "Try to find php-selector for hestiacp"
|
echo "Try to find php-selector for hestiacp"
|
||||||
|
current_path_to_php=""
|
||||||
|
if [ -e /usr/bin/php ]; then
|
||||||
|
current_path_to_php=$(readlink -f /usr/bin/php)
|
||||||
|
fi
|
||||||
update-alternatives --display php | grep hestiacp-php-selector
|
update-alternatives --display php | grep hestiacp-php-selector
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Register php-selector"
|
echo "Register php-selector"
|
||||||
update-alternatives --install /usr/bin/php php /usr/bin/hestiacp-php-selector 1
|
update-alternatives --install /usr/bin/php php /usr/bin/hestiacp-php-selector 1
|
||||||
if [ ! -e /etc/hestia_php_selector/system/php.path ]; then
|
if [ ! -e /etc/hestia_php_selector/system/php.path ]; then
|
||||||
mkdir -p /etc/hestia_php_selector/system/
|
mkdir -p /etc/hestia_php_selector/system/
|
||||||
current_path_to_php=$(readlink -f /usr/bin/php)
|
|
||||||
echo "$current_path_to_php" >/etc/hestia_php_selector/system/php.path
|
echo "$current_path_to_php" >/etc/hestia_php_selector/system/php.path
|
||||||
chmod 644 /etc/hestia_php_selector/system/php.path
|
chmod 644 /etc/hestia_php_selector/system/php.path
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -26,9 +26,54 @@ const (
|
|||||||
PATH_TO_LOCAL_PHP = PATH_TO_LOCAL_PHP_ROOT + PATH_TO_CONFIG_NAME
|
PATH_TO_LOCAL_PHP = PATH_TO_LOCAL_PHP_ROOT + PATH_TO_CONFIG_NAME
|
||||||
LOCK_PATH = "lock"
|
LOCK_PATH = "lock"
|
||||||
PHP_SEL_CONF = "/etc/hestia_php_selector/php_sel_path.conf"
|
PHP_SEL_CONF = "/etc/hestia_php_selector/php_sel_path.conf"
|
||||||
PHP_TEMPLATE = "/usr/bin/php%s"
|
PHP_TEMPLATE_REMI = "/usr/bin/php%s"
|
||||||
|
PHP_TEMPLATE_BREPO = "/opt/brepo/php%s/bin/php"
|
||||||
|
HESTIA_CONF = "/usr/local/hestia/conf/hestia.conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isFileExists(path string) (bool, bool, error) {
|
||||||
|
if fi, err := os.Stat(path); err == nil {
|
||||||
|
return true, fi.IsDir(), nil
|
||||||
|
} else if errors.Is(err, os.ErrNotExist) {
|
||||||
|
return false, false, nil
|
||||||
|
} else {
|
||||||
|
return false, false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_php_type() string {
|
||||||
|
res := "remi"
|
||||||
|
ext, isd, err := isFileExists(HESTIA_CONF)
|
||||||
|
if err == nil && ext && !isd {
|
||||||
|
f, err := os.Open(HESTIA_CONF)
|
||||||
|
if err != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
formatedLine := strings.SplitN(strings.TrimSpace(line), "=", 2)
|
||||||
|
if len(formatedLine) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(formatedLine[0]) == "LOCAL_PHP" {
|
||||||
|
result := strings.Trim(formatedLine[1], "' ")
|
||||||
|
if result == "yes" {
|
||||||
|
res = "brepo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func escapeUserName(username string) string {
|
func escapeUserName(username string) string {
|
||||||
username0 := strings.TrimSpace(username)
|
username0 := strings.TrimSpace(username)
|
||||||
uname := strings.Split(username0, "/")
|
uname := strings.Split(username0, "/")
|
||||||
@@ -54,7 +99,11 @@ func getPathtpPHP(phpVer string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(PHP_TEMPLATE, phpVer)
|
if get_php_type() == "remi" {
|
||||||
|
return fmt.Sprintf(PHP_TEMPLATE_REMI, phpVer)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf(PHP_TEMPLATE_BREPO, phpVer)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,16 +187,6 @@ func setUserPHPVer(username string, php_ver string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isFileExists(path string) (bool, bool, error) {
|
|
||||||
if fi, err := os.Stat(path); err == nil {
|
|
||||||
return true, fi.IsDir(), nil
|
|
||||||
} else if errors.Is(err, os.ErrNotExist) {
|
|
||||||
return false, false, nil
|
|
||||||
} else {
|
|
||||||
return false, false, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setUserPhpPathVer(username string, php_ver string, php_path string) error {
|
func setUserPhpPathVer(username string, php_ver string, php_path string) error {
|
||||||
un := escapeUserName(username)
|
un := escapeUserName(username)
|
||||||
if un == "" {
|
if un == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user