Skip to content

Commit 699b4e3

Browse files
authored
Add check if group / user exists + Allow user to select php versions (hestiacp#4065)
* Add check if group / user exists + Allow user to select php versions Usage bash hst-install-debian.sh -D /root/ -o 8.2,8.1,8.0 Will install php8.0 to php8.2 A few exceptions: - If user wants to install a non existing version it will create an error and exit it self - If Versions installer are lower then 7.3 it will do the same as our dependencies require it (roundcube) - If PHP version > current supported it will include php8.2 in this case to the supported list. This is mainly for 8.3 and new and or 9.0 versions * Fix shellcheck * Remove debug exit * Request / validate password * Remove hardcode admin * Update install order * Remove debug code
1 parent 3bd26f4 commit 699b4e3

File tree

4 files changed

+125
-35
lines changed

4 files changed

+125
-35
lines changed

func/upgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ upgrade_send_notification_to_email() {
246246

247247
upgrade_send_log_to_email() {
248248
if [ "$UPGRADE_SEND_EMAIL_LOG" = "true" ]; then
249-
admin_email=$($BIN/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
249+
admin_email=$($BIN/v-list-user $ROOT_USER json | grep "CONTACT" | cut -d'"' -f4)
250250
send_mail="$HESTIA/web/inc/mail-wrapper.php"
251251
cat $LOG | $send_mail -s "Update Installation Log - v${new_version}" $admin_email
252252
fi

install/hst-install-debian.sh

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ VERBOSE='no'
3232

3333
# Define software versions
3434
HESTIA_INSTALL_VER='1.9.0~alpha'
35-
# Dependencies
35+
# Supported PHP versions
3636
multiphp_v=("5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2")
37+
# One of the following PHP versions is required for Roundcube / phpmyadmin
38+
multiphp_required=("7.3" "7.4" "8.0" "8.1" "8.2")
39+
# Default PHP version if none supplied
3740
fpm_v="8.2"
41+
# MariaDB version
3842
mariadb_v="10.11"
3943

4044
# Defining software pack for all distros
@@ -178,10 +182,14 @@ sort_config_file() {
178182

179183
# todo add check for usernames that are blocked
180184
validate_username() {
181-
if [[ "$username" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]]; then
182-
# Username valid
183-
return 1
185+
if [[ "$username" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
186+
if [ -n "$(grep ^$username: /etc/passwd /etc/group)" ]; then
187+
echo -e "\nUsername or Group allready exists please select a new user name or delete the user and / or group."
188+
else
189+
return 1
190+
fi
184191
else
192+
echo -e "\nPlease use a valid username (ex. user)."
185193
return 0
186194
fi
187195
}
@@ -306,6 +314,43 @@ while getopts "a:w:v:j:k:m:M:g:d:x:z:Z:c:t:i:b:r:o:q:l:y:s:u:e:p:W:D:fh" Option;
306314
esac
307315
done
308316

317+
if [ -n "$multiphp" ]; then
318+
if [ "$multiphp" != 'no' ] && [ "$multiphp" != 'yes' ]; then
319+
php_versions=$(echo $multiphp | tr ',' "\n")
320+
multiphp_version=()
321+
for php_version in "${php_versions[@]}"; do
322+
if [[ $(echo "${multiphp_v[@]}" | fgrep -w "$php_version") ]]; then
323+
multiphp_version=(${multiphp_version[@]} "$php_version")
324+
else
325+
echo "$php_version is not supported"
326+
exit 1
327+
fi
328+
done
329+
multiphp_v=()
330+
for version in "${multiphp_version[@]}"; do
331+
multiphp_v=(${multiphp_v[@]} $version)
332+
done
333+
fpm_old=$fpm_v
334+
multiphp="yes"
335+
fpm_v=$(printf "%s\n" "${multiphp_version[@]}" | sort -V | tail -n1)
336+
fpm_last=$(printf "%s\n" "${multiphp_required[@]}" | sort -V | tail -n1)
337+
# Allow Maintainer to set minimum fpm version to make sure phpmyadmin and roundcube keep working
338+
if [[ -z $(echo "${multiphp_required[@]}" | fgrep -w $fpm_v) ]]; then
339+
if version_ge $fpm_v $fpm_last; then
340+
multiphp_version=(${multiphp_version[@]} $fpm_last)
341+
fpm_v=$fpm_last
342+
else
343+
# Roundcube and PHPmyadmin doesn't support the version selected.
344+
echo "Selected PHP versions are not supported any more by Dependencies..."
345+
exit 1
346+
fi
347+
fi
348+
349+
software=$(echo "$software" | sed -e "s/php$fpm_old/php$fpm_v/g")
350+
351+
fi
352+
fi
353+
309354
# Defining default software stack
310355
set_default_value 'nginx' 'yes'
311356
set_default_value 'apache' 'yes'
@@ -357,6 +402,7 @@ fi
357402
if [ "$apache" = 'no' ]; then
358403
phpfpm='yes'
359404
fi
405+
360406
if [ "$mysql" = 'yes' ] && [ "$mysql8" = 'yes' ]; then
361407
mysql='no'
362408
fi
@@ -374,14 +420,6 @@ if [ -d "/usr/local/hestia" ]; then
374420
check_result 1 "Hestia install detected. Unable to continue"
375421
fi
376422

377-
# Checking $username user account
378-
if [ -n "$(grep ^$username: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
379-
echo "Please remove $username user account before proceeding."
380-
echo 'If you want to do it automatically run installer with -f option:'
381-
echo -e "Example: bash $0 --force\n"
382-
check_result 1 "User $username exists"
383-
fi
384-
385423
# Clear the screen once launch permissions have been verified
386424
clear
387425

@@ -567,7 +605,11 @@ if [ "$phpfpm" = 'yes' ] && [ "$multiphp" = 'no' ]; then
567605
fi
568606
if [ "$multiphp" = 'yes' ]; then
569607
phpfpm='yes'
570-
echo ' - Multi-PHP Environment'
608+
echo -n ' - Multi-PHP Environment: Version'
609+
for version in "${multiphp_v[@]}"; do
610+
echo -n " php$version"
611+
done
612+
echo ''
571613
fi
572614

573615
# DNS stack
@@ -645,15 +687,12 @@ if [ "$interactive" = 'yes' ]; then
645687
fi
646688

647689
#Validate Username / Password / Email / Hostname even when interactive = no
648-
# Asking for contact email
649690
if [ -z "$username" ]; then
650691
while validate_username; do
651-
echo -e "\nPlease use a valid username (ex. user)."
652692
read -p 'Please enter administrator username: ' username
653693
done
654694
else
655695
if validate_username; then
656-
echo "Please use a valid username (ex. user)."
657696
exit 1
658697
fi
659698
fi

install/hst-install-ubuntu.sh

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ VERBOSE='no'
3232

3333
# Define software versions
3434
HESTIA_INSTALL_VER='1.9.0~alpha'
35-
# Dependencies
35+
# Supported PHP versions
3636
multiphp_v=("5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2")
37+
# One of the following PHP versions is required for Roundcube / phpmyadmin
38+
multiphp_required=("7.3" "7.4" "8.0" "8.1" "8.2")
39+
40+
# Default PHP version if none supplied
3741
fpm_v="8.2"
42+
# MariaDB version
3843
mariadb_v="10.11"
3944

4045
# Defining software pack for all distros
@@ -178,10 +183,14 @@ sort_config_file() {
178183

179184
# todo add check for usernames that are blocked
180185
validate_username() {
181-
if [[ "$username" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]]; then
182-
# Username valid
183-
return 1
186+
if [[ "$username" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
187+
if [ -n "$(grep ^$username: /etc/passwd /etc/group)" ]; then
188+
echo -e "\nUsername or Group allready exists please select a new user name or delete the user and / or group."
189+
else
190+
return 1
191+
fi
184192
else
193+
echo -e "\nPlease use a valid username (ex. user)."
185194
return 0
186195
fi
187196
}
@@ -306,6 +315,43 @@ while getopts "a:w:v:j:k:m:M:g:d:x:z:Z:c:t:i:b:r:o:q:l:y:s:u:e:p:W:D:fh" Option;
306315
esac
307316
done
308317

318+
if [ -n "$multiphp" ]; then
319+
if [ "$multiphp" != 'no' ] && [ "$multiphp" != 'yes' ]; then
320+
php_versions=$(echo $multiphp | tr ',' "\n")
321+
multiphp_version=()
322+
for php_version in "${php_versions[@]}"; do
323+
if [[ $(echo "${multiphp_v[@]}" | fgrep -w "$php_version") ]]; then
324+
multiphp_version=(${multiphp_version[@]} "$php_version")
325+
else
326+
echo "$php_version is not supported"
327+
exit 1
328+
fi
329+
done
330+
multiphp_v=()
331+
for version in "${multiphp_version[@]}"; do
332+
multiphp_v=(${multiphp_v[@]} $version)
333+
done
334+
fpm_old=$fpm_v
335+
multiphp="yes"
336+
fpm_v=$(printf "%s\n" "${multiphp_version[@]}" | sort -V | tail -n1)
337+
fpm_last=$(printf "%s\n" "${multiphp_required[@]}" | sort -V | tail -n1)
338+
# Allow Maintainer to set minimum fpm version to make sure phpmyadmin and roundcube keep working
339+
if [[ -z $(echo "${multiphp_required[@]}" | fgrep -w $fpm_v) ]]; then
340+
if version_ge $fpm_v $fpm_last; then
341+
multiphp_version=(${multiphp_version[@]} $fpm_last)
342+
fpm_v=$fpm_last
343+
else
344+
# Roundcube and PHPmyadmin doesn't support the version selected.
345+
echo "Selected PHP versions are not supported any more by Dependencies..."
346+
exit 1
347+
fi
348+
fi
349+
350+
software=$(echo "$software" | sed -e "s/php$fpm_old/php$fpm_v/g")
351+
352+
fi
353+
fi
354+
309355
# Defining default software stack
310356
set_default_value 'nginx' 'yes'
311357
set_default_value 'apache' 'yes'
@@ -370,14 +416,6 @@ if [ -d "/usr/local/hestia" ]; then
370416
check_result 1 "Hestia install detected. Unable to continue"
371417
fi
372418

373-
# Checking admin user account
374-
if [ -n "$(grep ^admin: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
375-
echo 'Please remove admin user account before proceeding.'
376-
echo 'If you want to do it automatically run installer with -f option:'
377-
echo -e "Example: bash $0 --force\n"
378-
check_result 1 "User admin exists"
379-
fi
380-
381419
# Clear the screen once launch permissions have been verified
382420
clear
383421

@@ -556,7 +594,11 @@ if [ "$phpfpm" = 'yes' ] && [ "$multiphp" = 'no' ]; then
556594
fi
557595
if [ "$multiphp" = 'yes' ]; then
558596
phpfpm='yes'
559-
echo ' - Multi-PHP Environment'
597+
echo -n ' - Multi-PHP Environment: Version'
598+
for version in "${multiphp_v[@]}"; do
599+
echo -n " php$version"
600+
done
601+
echo ''
560602
fi
561603

562604
# DNS stack
@@ -634,15 +676,24 @@ if [ "$interactive" = 'yes' ]; then
634676
fi
635677

636678
#Validate Username / Password / Email / Hostname even when interactive = no
637-
# Asking for contact email
638679
if [ -z "$username" ]; then
639680
while validate_username; do
640-
echo -e "\nPlease use a valid username (ex. user)."
641681
read -p 'Please enter administrator username: ' username
642682
done
643683
else
644684
if validate_username; then
645-
echo "Please use a valid username (ex. user)."
685+
exit 1
686+
fi
687+
fi
688+
689+
#Ask for the password
690+
if [ -z "$vpass" ]; then
691+
while validate_password; do
692+
read -p 'Please enter administrator password: ' vpass
693+
done
694+
else
695+
if validate_password; then
696+
echo "Please use a valid password"
646697
exit 1
647698
fi
648699
fi

src/hst_autocompile.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ if [ "$dontinstalldeps" != 'true' ]; then
293293
apt -qq install -y nodejs > /dev/null 2>&1
294294

295295
nodejs_version=$(/usr/bin/node -v | cut -f1 -d'.' | sed 's/v//g')
296-
echo /usr/bin/node -v
297-
echo $nodejs_version
296+
298297
if [ "$nodejs_version" -lt 18 ]; then
299298
echo "Requires NodeJS 18.x or higher"
300299
exit 1
301300
fi
301+
302302
# Fix for Debian PHP environment
303303
if [ $BUILD_ARCH == "amd64" ]; then
304304
if [ ! -L /usr/local/include/curl ]; then

0 commit comments

Comments
 (0)