myvesta/bin/v-list-php
2024-01-26 22:56:37 +01:00

77 lines
1.7 KiB
Bash

#!/bin/bash
# info: list of installed php versions
# options: [FORMAT]
#
# The function for obtaining the list of installed PHP versions.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
format=${1-shell}
# Includes
source $VESTA/func/main.sh
# JSON list function
json_list() {
counter=$(echo "$phpversions" | wc -l)
i=1
echo '['
for phpversion in $phpversions; do
if [ "$i" -lt "$counter" ]; then
echo -e "\t\"$phpversion\","
else
echo -e "\t\"$phpversion\""
fi
(( ++i))
done
echo "]"
}
# shell list function
shell_list() {
for phpversion in $phpversions; do
echo "$phpversion"
done
}
# PLAIN list function
plain_list() {
for phpversion in $phpversions; do
echo "$phpversion"
done
}
# CSV list function
csv_list() {
for phpversion in $phpversions; do
echo "$phpversion"
done
}
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Obtaining the list of installed PHP-FPM versions
phpversions=$(find /etc/php/ -type d -name 'fpm' | sed "s|/etc/php/||" | sed "s|/fpm||" | sort)
# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list ;;
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit