#!/bin/bash
echo "=========================================="
echo "Initializing variables..."
echo "=========================================="
phpPath=`which php` # fetch php executatble path
phpParentPath="$(dirname "$phpPath")" # fetch php parent directory path
phpIniPath=$phpParentPath/php.ini
phpIniPathWindows=`cygpath -d $phpIniPath`
cp $phpIniPath-development $phpIniPath # create production `php.ini` file
cp $phpIniPath $phpParentPath/php.backup.ini # create up of production `php.ini`
echo "=========================================="
echo "Creating Powershell script to configure PHP"
echo "=========================================="
echo "
#!/usr/bin/env pwsh
# ==========================================
# increasing bandwith
# ==========================================
$phpIniPathWindows = Get-Content phpIniPathWindows.txt -Raw
(gc $phpIniPathWindows).replace('upload_max_filesize = 2M','upload_max_filesize = 12M') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace('memory_limit = 128M','memory_limit = 512M') | sc $phpIniPathWindows
# ==========================================
# uncommenting key-value pairs to enable desired capabilities
# ==========================================
(gc $phpIniPathWindows).replace(';date.timezone =','date.timezone =\"UTC\"') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=gd2','extension=gd2') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=curl','extension=curl') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=mysqli','extension=mysqli') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=openssl','extension=openssl') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_gd2.dll','extension=php_gd2.dll') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension_dir = \"ext\"','extension_dir = \"ext\"') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_curl.dll','extension=php_curl.dll') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_mysqli.dll','extension=php_mysqli.dll') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_openssl.dll','extension=php_openssl.dll') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_fileinfo.dll','extension=php_fileinfo.dll') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_mbstring.dll','extension=php_mbstring.dll') | sc $phpIniPathWindows
(gc $phpIniPathWindows).replace(';extension=php_pdo_mysql.dll','extension=php_pdo_mysql.dll') | sc $phpIniPathWindows
" > initialize-php.ps1
echo "=========================================="
echo "Executing aforementioned powershell script"
echo "=========================================="
chmod u+x initialize-php.ps1
powershell ./initialize-php.ps1