Improve Logs and tests

This commit is contained in:
Shivam Mathur
2019-10-17 01:41:13 +05:30
parent 62beed29e3
commit a6aaa1db78
20 changed files with 615 additions and 360 deletions

View File

@ -1,5 +1,25 @@
tick="✓"
cross="✗"
step_log() {
message=$1
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
}
add_log() {
mark=$1
subject=$2
message=$3
if [ "$mark" = "$tick" ]; then
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi
}
existing_version=$(php-config --version | cut -c 1-3)
version=$1
status="Switched to PHP$version"
step_log "Setup PHP and Composer"
if [ "$existing_version" != "$1" ]; then
if [ ! -e "/usr/bin/php$1" ]; then
sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y >/dev/null 2>&1
@ -9,13 +29,22 @@ if [ "$existing_version" != "$1" ]; then
else
sudo DEBIAN_FRONTEND=noninteractive apt install -y php"$1" php"$1"-dev curl php"$1"-curl >/dev/null 2>&1
fi
status="Installed PHP$version"
fi
for tool in php phar phar.phar php-cgi php-config phpize; do
if [ -e "/usr/bin/$tool$1" ]; then
sudo update-alternatives --set $tool /usr/bin/"$tool$1" &
sudo update-alternatives --set $tool /usr/bin/"$tool$1" >/dev/null 2>&1 &
fi
done
fi
fi
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo chmod 777 "$ini_file"
sudo mkdir -p /run/php
add_log "$tick" "PHP" "$status"
if [ ! -e "/usr/bin/composer" ]; then
curl -s -L https://getcomposer.org/installer > composer-setup.php
@ -27,28 +56,22 @@ if [ ! -e "/usr/bin/composer" ]; then
fi
rm composer-setup.php
fi
composer global require hirak/prestissimo >/dev/null 2>&1
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo chmod 777 "$ini_file"
sudo mkdir -p /run/php
php -v
composer -V
add_log "$tick" "Composer" "Installed"
add_extension()
{
extension=$1
install_command=$2
prefix=$3
log_prefix=$4
if ! php -m | grep -i -q "$extension" && [ -e "$ext_dir/$extension.so" ]; then
echo "$prefix=$extension" >> "$ini_file" && echo "\033[32;1m$log_prefix: Enabled $extension\033[0m";
echo "$prefix=$extension" >> "$ini_file" && add_log "$tick" "$extension" "Enabled"
elif php -m | grep -i -q "$extension"; then
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q "$extension"; then
eval "$install_command" && \
echo "\033[32;1m$log_prefix: Installed and enabled $extension\033[0m" || \
echo "\033[31;1m$log_prefix: Could not find php$version-$extension on APT repository\033[0m";
(
eval "$install_command" && \
add_log "$tick" "$extension" "Installed and enabled"
) || add_log "$cross" "$extension" "Could not find php$version-$extension"
fi
}
}