From d889f248e6251547db5a1339ca6671896ad50c37 Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Thu, 17 Dec 2020 15:14:18 +0100 Subject: [PATCH] Prepared php updater for EL --- AppendCMS.sh | 8 +++-- AppendModule.sh | 8 +++-- CoreModules/apache/phpupdate-handeler.sh | 5 ++- PhpUpdater.sh | 42 +++++++++++++++++++++--- Scripts/GenerateApacheList.sh | 19 +++++++++++ Scripts/GeneratePhplist.sh | 2 ++ Scripts/MicroOSDetect.sh | 14 ++++++++ 7 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 Scripts/GenerateApacheList.sh create mode 100644 Scripts/MicroOSDetect.sh diff --git a/AppendCMS.sh b/AppendCMS.sh index 003a060..0966189 100644 --- a/AppendCMS.sh +++ b/AppendCMS.sh @@ -6,11 +6,15 @@ if [ ! -f "/etc/ICTM/selopts.list" ] || [ ! -f "/etc/ICTM/mainvar.list" ] ; then source /etc/ICTM/selopts.list source /etc/ICTM/mainvar.list +if [ -z $shortdist ] ; then source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/MicroOSDetect.sh) ; fi if [ $webserv != nginx_nonphp ]; then - if [ ! -f "/etc/ICTM/phpvar.list" ] ; then echo 'Php var list missing,Please run /Scipts/GeneratePhplist from the repo ' && exit ; fi + if [ ! -f "/etc/ICTM/phpvar.list" ] ; then bash <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/GeneratePhplist.sh) ; fi source /etc/ICTM/phpvar.list fi -if [ -f "/etc/ICTM/apachevar.list" ] ; then source /etc/ICTM/apachevar.list; fi +if [ $webserv = apache ]; then + if [ ! -f "/etc/ICTM/apachevar.list" ] ; then bash <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/GenerateApacheList.sh) ; fi + source /etc/ICTM/apachevar.list +fi rm /tmp/pkg.list > $OUTPUT 2>&1 source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/ModulesMenu.list) diff --git a/AppendModule.sh b/AppendModule.sh index f06e4b3..bdaed34 100644 --- a/AppendModule.sh +++ b/AppendModule.sh @@ -10,11 +10,15 @@ if [ ! -f "/etc/ICTM/selopts.list" ] || [ ! -f "/etc/ICTM/mainvar.list" ] ; then source /etc/ICTM/selopts.list source /etc/ICTM/mainvar.list +if [ -z $shortdist ] ; then source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/MicroOSDetect.sh) ; fi if [ $webserv != nginx_nonphp ]; then - if [ ! -f "/etc/ICTM/phpvar.list" ] ; then echo 'Php var list missing,Please run /Scipts/GeneratePhplist from the repo ' && exit ; fi + if [ ! -f "/etc/ICTM/phpvar.list" ] ; then bash <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/GeneratePhplist.sh) ; fi source /etc/ICTM/phpvar.list fi -if [ -f "/etc/ICTM/apachevar.list" ] ; then source /etc/ICTM/apachevar.list; fi +if [ $webserv = apache ]; then + if [ ! -f "/etc/ICTM/apachevar.list" ] ; then bash <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/GenerateApacheList.sh) ; fi + source /etc/ICTM/apachevar.list +fi rm /tmp/pkg.list source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/ModulesMenu.list) diff --git a/CoreModules/apache/phpupdate-handeler.sh b/CoreModules/apache/phpupdate-handeler.sh index 8abfe21..e91e63d 100644 --- a/CoreModules/apache/phpupdate-handeler.sh +++ b/CoreModules/apache/phpupdate-handeler.sh @@ -1,4 +1,7 @@ -for f in /etc/apache2/sites-available/*; do +if [ ! -f "/etc/ICTM/apachevar.list" ] ; then bash <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/GenerateApacheList.sh) ; fi +source /etc/ICTM/apachevar.list + +for f in $apacheConfDir/sites-available/*; do if [ $IMODE = n ] && [ $PhpPurge = 0 ]; then if (whiptail --title "Update apache config ?" --yesno "Update php version in apache site: ${f##*/} ?" 8 78); then sed -i "s/$phpver/$newphpver/" $f diff --git a/PhpUpdater.sh b/PhpUpdater.sh index cdd0221..b001d11 100644 --- a/PhpUpdater.sh +++ b/PhpUpdater.sh @@ -2,8 +2,12 @@ if [ ! -f "/etc/ICTM/selopts.list" ] || [ ! -f "/etc/ICTM/mainvar.list" ] ; then echo 'This system is not yet setup, please run the main installer first' && exit ; fi PKGI="${PKGM} install -y --no-install-recommends" +rm /tmp/pkg.list #Getting variables source /etc/ICTM/mainvar.list +if [ -z $shortdist ] ; then source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/MicroOSDetect.sh) ; fi +if [ ! -f "/etc/ICTM/phpvar.list" ] ; then bash <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/GeneratePhplist.sh) ; fi +source /etc/ICTM/phpvar.list PPAversion=`apt list php | egrep -o "([0-9]{1,}.)+[0-9]{1,}" | cut -c 3-` && PPAversion=`echo $PPAversion | awk '{print $1; }' | cut -f1 -d"+"` msg () { @@ -60,11 +64,33 @@ if [ $IMODE = l ]; then esac done + #Genereating vars for new php version + if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then + # Debian/Ubunbtu Php variables + newphpPoolDir=/etc/php/${newphpver}/fpm/pool.d + newphpPkgName=php${newphpver} + newphpMainConf=/etc/php/${newphpver}/fpm/php.ini + newphpFPMService=php${newphpver}-fpm + elif [ "$shortdist" = "el8" ]; then + # Centos Php variable + phpPoolDir=/etc/opt/remi/php${newphpver//.}/php-fpm.d/ + newphpPkgName=php${newphpver//.}-php + newphpMainConf=/etc/opt/remi/php${newphpver//.}/php.ini + newphpFPMService=php${newphpver//.}-php-fpm + fi + + + #Install - apt list --installed | less | grep php$phpver | cut -f1 -d"/" | sed "s/$phpver/$newphpver/" | xargs $PKGI + apt list --installed | less | grep php$phpver | cut -f1 -d"/" | sed "s/$phpver/$newphpver/" > /tmp/pkg.list + if [ ${newphpver//.} -ge 80 ] && [ ${newphpver//.} -lt 90 ]; then + sed -i -e "s/php${newphpver//}-xmlrpc//g" -e "s/php${newphpver//}-json//g" /tmp/pkg.list + fi + cat /tmp/pkg.list | xargs $PKGI #Config - cp /etc/php/$phpver/fpm/pool.d/* /etc/php/$newphpver/fpm/pool.d/ + systemctl stop $newphpFPMService + cp $phpPoolDir/* $newphpPoolDir #Purge while true; do @@ -79,13 +105,21 @@ if [ $IMODE = l ]; then done fi -for f in /etc/php/$newphpver/fpm/pool.d/*; do +for f in $phpPoolDir/*; do sed -i "s/$phpver/$newphpver/" $f done -systemctl reload php$newphpver-fpm + +systemctl start $newphpFPMService +systemctl enable $newphpFPMService + sed -i "/phpver/c\phpver=\"$newphpver\"" /etc/ICTM/mainvar.list +mv /etc/ICTM/phpvar.list /etc/ICTM/phpvar"$phpver".list +for storeme in newphpPoolDir newphpPkgName newphpMainConf newphpFPMService; do + declare -p $storeme | cut -d ' ' -f 3- >> /etc/ICTM/phpvar.list +done + if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/CoreModules/"$webserv"/phpupdate-handeler.sh; then source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/CoreModules/"$webserv"/phpupdate-handeler.sh) fi \ No newline at end of file diff --git a/Scripts/GenerateApacheList.sh b/Scripts/GenerateApacheList.sh new file mode 100644 index 0000000..49de67f --- /dev/null +++ b/Scripts/GenerateApacheList.sh @@ -0,0 +1,19 @@ +if [ ! -f "/etc/ICTM/mainvar.list" ] ; then echo 'This system is not yet setup, please run the main installer first' && exit ; fi +source /etc/ICTM/mainvar.list +if [ -z $shortdist ] ; then source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/MicroOSDetect.sh) ; fi + +if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then +# Debian/Ubunbtu apache variables + apacheConfDir=/etc/apache2 + apacheService=apache2 + +elif [ "$shortdist" = "el8" ]; then +# Centos Php variable + apacheConfDir=/etc/httpd + apacheService=httpd +fi + +#Storing vars to config +for storeme in apacheService apacheConfDir; do + declare -p $storeme | cut -d ' ' -f 3- >> /etc/ICTM/apachevar.list +done diff --git a/Scripts/GeneratePhplist.sh b/Scripts/GeneratePhplist.sh index 1a007a1..e848b8e 100644 --- a/Scripts/GeneratePhplist.sh +++ b/Scripts/GeneratePhplist.sh @@ -1,4 +1,6 @@ if [ ! -f "/etc/ICTM/mainvar.list" ] ; then echo 'This system is not yet setup, please run the main installer first' && exit ; fi +source /etc/ICTM/mainvar.list +if [ -z $shortdist ] ; then source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/MicroOSDetect.sh) ; fi if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then # Debian/Ubunbtu Php variables diff --git a/Scripts/MicroOSDetect.sh b/Scripts/MicroOSDetect.sh new file mode 100644 index 0000000..c6ccf85 --- /dev/null +++ b/Scripts/MicroOSDetect.sh @@ -0,0 +1,14 @@ +dist_ver=$(grep --color=never -Po "^VERSION_ID=\K.*" "/etc/os-release") +dist=$(grep --color=never -Po "^ID=\K.*" "/etc/os-release") + +if [[ "${dist}" == *"ubuntu"* ]] && [[ "${dist_ver}" == *"18.04"* ]]; then + shortdist=ubu1804 + elif [[ "${dist}" == *"ubuntu"* ]] && [[ "${dist_ver}" == *"20.04"* ]]; then + shortdist=ubu2004 +elif [[ "${dist}" == *"debian"* ]] && [[ "${dist_ver}" == *"10"* ]]; then + shortdist=deb10 +elif [[ "${dist}" == *"centos"* ]] && [[ "${dist_ver}" == *"8"* ]]; then + shortdist=el8 +else + echo "This os in known" +fi \ No newline at end of file