Skip to content

Commit 529208a

Browse files
ScIT-RaphaelKristan Kenney
authored andcommitted
Add v-add/delete-web-php scripts to make multiphp modular.
1 parent ab87b1f commit 529208a

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed

bin/v-add-web-php

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
# info: add php fpm version
3+
# options: VERSION
4+
#
5+
# The function checks and delete a fpm php version if not used by any domain.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
version=$1
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'VERSION'
25+
26+
# Set file locations
27+
php_fpm="/etc/init.d/php$version-fpm"
28+
29+
# Verify php version format
30+
if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
31+
echo "The php version format is invalid, it should look like [0-9].[0-9]..."
32+
exit
33+
fi
34+
35+
# Check if php version already exists
36+
if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
37+
echo "Version already installed..."
38+
exit
39+
fi
40+
41+
# Check if php version is supported
42+
if [ ! -f "$HESTIA/install/deb/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
43+
echo "Version is currently not supported or does not exist..."
44+
exit
45+
fi
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
mph="php$version-mbstring php$version-bcmath php$version-cli php$version-curl
52+
php$version-fpm php$version-gd php$version-intl php$version-mysql
53+
php$version-soap php$version-xml php$version-zip php$version-mbstring
54+
php$version-json php$version-bz2 php$version-pspell"
55+
56+
# Check is version is 7.1 or below to add mcrypt
57+
if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
58+
mph="$mph php$version-mcrypt"
59+
fi
60+
61+
# Install php packages
62+
apt-get -qq update
63+
apt-get -y install $mph > /dev/null 2>&1 &
64+
BACK_PID=$!
65+
66+
# Check if package installation is done, print a spinner
67+
echo "Install PHP-$version, please wait..."
68+
spinner="/-\|"
69+
spin_i=1
70+
while kill -0 $BACK_PID > /dev/null 2>&1 ; do
71+
printf "\b${spinner:spin_i++%${#spinner}:1}"
72+
sleep 0.5
73+
done
74+
75+
# Do a blank echo to get the \n back
76+
echo
77+
78+
# Check if installation was sucessfully
79+
if [ ! -f "$php_fpm" ]; then
80+
echo "Installation failed, please run the following command manualy for debuging:"
81+
echo "apt-get install $mph"
82+
fi
83+
84+
# Check if required modules for apache2 are enabled
85+
if [ "$WEB_SYSTEM" = "apache2" ]; then
86+
if ! ls -l /etc/apache2/mods-enabled/ | grep --quiet "proxy_fcgi"; then
87+
a2enmod proxy_fcgi > /dev/null 2>&1
88+
restart_apache2="yes"
89+
fi
90+
if ! ls -l /etc/apache2/mods-enabled/ | grep --quiet "setenvif"; then
91+
a2enmod setenvif > /dev/null 2>&1
92+
restart_apache2="yes"
93+
fi
94+
if [ "$restart_apache2" = "yes" ]; then
95+
service apache2 restart > /dev/null 2>&1
96+
fi
97+
fi
98+
99+
# Configure fpm
100+
v_tpl=$(echo "$version" | sed -e 's/[.]//')
101+
rm -f /etc/php/$version/fpm/pool.d/*
102+
cp -f $HESTIA/install/deb/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
103+
sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
104+
105+
# Install php templates
106+
cp -f $HESTIA/install/deb/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh \
107+
$HESTIA/data/templates/web/$WEB_SYSTEM/
108+
cp -f $HESTIA/install/deb/multiphp/$WEB_SYSTEM/PHP-${version//.}.tpl \
109+
$HESTIA/data/templates/web/$WEB_SYSTEM/
110+
cp -f $HESTIA/install/deb/multiphp/$WEB_SYSTEM/PHP-${version//.}.stpl \
111+
$HESTIA/data/templates/web/$WEB_SYSTEM/
112+
chmod a+x $HESTIA/data/templates/web/$WEB_SYSTEM/PHP-${version//.}.sh
113+
114+
115+
#----------------------------------------------------------#
116+
# Hestia #
117+
#----------------------------------------------------------#
118+
119+
# Logging
120+
log_history "installed php $job"
121+
log_event "$OK" "$ARGUMENTS"
122+
123+
exit

bin/v-delete-web-php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
# info: delete php fpm version
3+
# options: VERSION
4+
#
5+
# The function checks and delete a fpm php version if not used by any domain.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
version=$1
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'VERSION'
25+
26+
# Set file locations
27+
php_fpm="/etc/init.d/php$version-fpm"
28+
29+
# Verify php version format
30+
if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
31+
echo "The php version format is invalid, it should look like [0-9].[0-9]..."
32+
exit
33+
fi
34+
35+
# Check if php version exists
36+
if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
37+
echo "Version is not installed..."
38+
exit
39+
fi
40+
41+
42+
#----------------------------------------------------------#
43+
# Action #
44+
#----------------------------------------------------------#
45+
46+
mph="php$version-mbstring php$version-bcmath php$version-cli php$version-curl
47+
php$version-fpm php$version-gd php$version-intl php$version-mysql
48+
php$version-soap php$version-xml php$version-zip php$version-mbstring
49+
php$version-json php$version-bz2 php$version-pspell"
50+
51+
# Check is version is 7.1 or below to add mcrypt
52+
if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
53+
mph="$mph php$version-mcrypt"
54+
fi
55+
56+
# Purge php packages
57+
apt-get -y purge $mph > /dev/null 2>&1 &
58+
BACK_PID=$!
59+
60+
# Check if package removal is done, print a spinner
61+
echo "Removing PHP-$version, please wait..."
62+
spinner="/-\|"
63+
spin_i=1
64+
while kill -0 $BACK_PID > /dev/null 2>&1 ; do
65+
printf "\b${spinner:spin_i++%${#spinner}:1}"
66+
sleep 0.5
67+
done
68+
69+
# Do a blank echo to get the \n back
70+
echo
71+
72+
# Check if installation was sucessfully
73+
if [ -f "$php_fpm" ]; then
74+
echo "Uninstallation failed, please run the following command manualy for debuging:"
75+
echo "apt-get purge $mph"
76+
fi
77+
78+
# Install php templates
79+
rm -f $HESTIA/data/templates/web/$WEB_SYSTEM/PHP-${version//.}.sh
80+
rm -f $HESTIA/data/templates/web/$WEB_SYSTEM/PHP-${version//.}.tpl
81+
rm -f $HESTIA/data/templates/web/$WEB_SYSTEM/PHP-${version//.}.stpl
82+
83+
84+
#----------------------------------------------------------#
85+
# Hestia #
86+
#----------------------------------------------------------#
87+
88+
# Logging
89+
log_history "removed php $version"
90+
log_event "$OK" "$ARGUMENTS"
91+
92+
exit

0 commit comments

Comments
 (0)