Browse Source

Supported versions

Ernesto Nicolás Carrea 5 years ago
parent
commit
d1524853ed

+ 18 - 9
bin/module/php/add.inc

@@ -2,6 +2,7 @@
 
 
 hestia_module_php_add() {
 hestia_module_php_add() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/func.inc
+    source $HESTIA/bin/module/php/func.inc
 
 
     module_installed=$(hestia_module_isinstalled php)
     module_installed=$(hestia_module_isinstalled php)
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
@@ -15,24 +16,32 @@ hestia_module_php_add() {
         exit 1
         exit 1
     fi
     fi
 
 
+    if [ ! $param_ver ]; then
+        echo "You must specify --ver [php_version]"
+        exit 1
+    fi
+
     # Verify php version format
     # Verify php version format
     if [[ ! $param_ver =~ ^[0-9]\.[0-9]+ ]]; then
     if [[ ! $param_ver =~ ^[0-9]\.[0-9]+ ]]; then
-        echo "The PHP version format is invalid, it should look like [0-9].[0-9]..."
+        echo "The PHP version format is invalid, it should look like [0-9].[0-9]."
         exit
         exit
     fi
     fi
 
 
     # Check version is supported
     # Check version is supported
-    case $param_ver in
-        5.6|7.0|7.1|7.2|7.3|7.4)
+    php_version=''
+    for ver in $PHP_SUPPORTED_VERSIONS; do
+        if [ "$param_ver" == "$ver" ]; then
             php_version=$param_ver
             php_version=$param_ver
-            ;;
-        *)
-            echo "PHP version $param_ver is not supported."
-            exit 1
-    esac
+            break;
+        fi
+    done
+    if [ ! "$php_version" ]; then
+        echo "PHP version $param_ver is not supported."
+        exit 1
+    fi
 
 
     php_withoutdot=${php_version//.}
     php_withoutdot=${php_version//.}
-    php_version_present=$(osal_kv_read $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
+    php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
 
 
     if [ "$php_version_present" ] && [ ! "$param_force" ]; then
     if [ "$php_version_present" ] && [ ! "$param_force" ]; then
         echo "PHP version ${php_version} is already present. See 'hestia module php list'."
         echo "PHP version ${php_version} is already present. See 'hestia module php list'."

+ 16 - 7
bin/module/php/del.inc

@@ -2,6 +2,7 @@
 
 
 hestia_module_php_del() {
 hestia_module_php_del() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/func.inc
+    source $HESTIA/bin/module/php/func.inc
 
 
     module_installed=$(hestia_module_isinstalled php)
     module_installed=$(hestia_module_isinstalled php)
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
@@ -15,6 +16,11 @@ hestia_module_php_del() {
         exit 1
         exit 1
     fi
     fi
 
 
+    if [ ! $param_ver ]; then
+        echo "You must specify --ver [php_version]"
+        exit 1
+    fi
+
     # Verify php version format
     # Verify php version format
     if [[ ! $param_ver =~ ^[0-9]\.[0-9]+ ]]; then
     if [[ ! $param_ver =~ ^[0-9]\.[0-9]+ ]]; then
         echo "The PHP version format is invalid, it should look like [0-9].[0-9]..."
         echo "The PHP version format is invalid, it should look like [0-9].[0-9]..."
@@ -22,14 +28,17 @@ hestia_module_php_del() {
     fi
     fi
 
 
     # Check version is supported
     # Check version is supported
-    case $param_ver in
-        5.6|7.0|7.1|7.2|7.3|7.4)
+    php_version=''
+    for ver in $PHP_SUPPORTED_VERSIONS; do
+        if [ "$param_ver" == "$ver" ]; then
             php_version=$param_ver
             php_version=$param_ver
-            ;;
-        *)
-            echo "PHP version $param_ver is not supported."
-            exit 1
-    esac
+            break;
+        fi
+    done
+    if [ ! "$php_version" ]; then
+        echo "PHP version $param_ver is not supported."
+        exit 1
+    fi
 
 
     php_withoutdot=${php_version//.}
     php_withoutdot=${php_version//.}
 
 

+ 4 - 0
bin/module/php/func.inc

@@ -0,0 +1,4 @@
+#!/bin/sh
+
+PHP_DEFAULT_VERSION=7.3
+PHP_SUPPORTED_VERSIONS='5.6 7.0 7.1 7.2 7.3 7.4'

+ 2 - 3
bin/module/php/install.inc

@@ -2,8 +2,7 @@
 
 
 hestia_module_php_install() {
 hestia_module_php_install() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/func.inc
-
-    PHP_DEFAULT_VERSION=7.3
+    source $HESTIA/bin/module/php/func.inc
 
 
     module_installed=$(hestia_module_isinstalled php)
     module_installed=$(hestia_module_isinstalled php)
     if [ "$module_installed" ] && [ ! "$param_force" ]; then
     if [ "$module_installed" ] && [ ! "$param_force" ]; then
@@ -23,7 +22,7 @@ hestia_module_php_install() {
 
 
     # Add default version
     # Add default version
     echo "Adding default PHP version..."
     echo "Adding default PHP version..."
-    hestia module php add --ver 7.3
+    hestia module php add --ver $PHP_DEFAULT_VERSION
 
 
     exit 0
     exit 0
 }
 }

+ 27 - 0
bin/module/php/list.inc

@@ -0,0 +1,27 @@
+#!/bin/sh
+
+hestia_module_php_list() {
+    source $HESTIA/bin/module/func.inc
+    source $HESTIA/bin/module/php/func.inc
+
+    module_installed=$(hestia_module_isinstalled php)
+    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+        echo "PHP module is not installed. See 'hestia module info php'."
+        exit 1
+    fi
+
+    module_variant=$(hestia_module_getvariant php)
+    if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
+        echo "The installed PHP module is not FPM. See 'hestia module info php'."
+        exit 1
+    fi
+
+    echo "Present PHP (FPM) versions"
+    for php_version in $PHP_SUPPORTED_VERSIONS; do
+        php_withoutdot=${php_version//.}
+        php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
+        echo PHP ${php_version}: $(osal_bool_yes $php_version_present 'present' 'not present')
+    done
+
+    exit 0
+}

+ 1 - 0
bin/module/php/remove.inc

@@ -2,6 +2,7 @@
 
 
 hestia_module_php_remove() {
 hestia_module_php_remove() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/func.inc
+    source $HESTIA/bin/module/php/func.inc
 
 
     module_installed=$(hestia_module_isinstalled php)
     module_installed=$(hestia_module_isinstalled php)
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then