From 2d8fe68344f1706bdf213ec0231472c3df38d82c Mon Sep 17 00:00:00 2001 From: earnolmartin Date: Wed, 9 Aug 2023 11:16:34 -0600 Subject: [PATCH] Use Python3 Scripts for Newer Operating Systems --- ehcp/ehcpforceupdate.sh | 105 ++++++++++++++++++++++++---------------- ehcp/install_lib.php | 13 ++++- ehcp/install_main.sh | 92 ++++++++++++++++++++--------------- 3 files changed, 125 insertions(+), 85 deletions(-) diff --git a/ehcp/ehcpforceupdate.sh b/ehcp/ehcpforceupdate.sh index 3f31875..8142b28 100755 --- a/ehcp/ehcpforceupdate.sh +++ b/ehcp/ehcpforceupdate.sh @@ -2729,10 +2729,18 @@ function installPythonPamMysql(){ # Copy our libpam-python scripts to /etc/security cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_smtp.conf /etc/security/pam_dbauth_smtp.conf - cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_smtp_ubuntu_20_plus.py /etc/security/pam_dbauth_smtp.py + if [[ "$distro" == "ubuntu" && "$yrelease" -ge "23" ]] || [[ "$distro" == "debian" && "$yrelease" -ge "12" ]]; then + cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_smtp_python3.py /etc/security/pam_dbauth_smtp.py + else + cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_smtp_ubuntu_20_plus.py /etc/security/pam_dbauth_smtp.py + fi cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_vsftpd.conf /etc/security/pam_dbauth_vsftpd.conf - cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_vsftpd_ubuntu_20_plus.py /etc/security/pam_dbauth_vsftpd.py + if [[ "$distro" == "ubuntu" && "$yrelease" -ge "23" ]] || [[ "$distro" == "debian" && "$yrelease" -ge "12" ]]; then + cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_vsftpd_python3.py /etc/security/pam_dbauth_vsftpd.py + else + cp -vf /var/www/new/ehcp/etc/pam/pam_dbauth_vsftpd_ubuntu_20_plus.py /etc/security/pam_dbauth_vsftpd.py + fi if ([[ "$distro" == "ubuntu" && "$yrelease" -ge "16" ]] || [[ "$distro" == "debian" && "$yrelease" -ge "9" ]]) && [[ -e "/usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu.so" ]]; then rm -f /usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu.so @@ -3380,55 +3388,66 @@ function fixSQMailPerms(){ } function installPipManuallyIfNeeded(){ - aptgetInstall "python-pip" curDir=$(pwd) - - if [ ! -e "/usr/bin/python2" ]; then - # We need python2 still - cd "$patchDir" - wget -N "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz" - tar zxvf "Python-2.7.18.tgz" - cd "Python-2.7.18" - ./configure --prefix=/usr --with-ensurepip=install - make - make install - fi - - # Create a symlink for python if one doesn't exist - if [ ! -e "/usr/bin/python" ]; then - if [ -e "/usr/bin/python2" ]; then - ln -s "/usr/bin/python2" "/usr/bin/python" - fi + + if [[ "$distro" == "ubuntu" && "$yrelease" -ge "23" ]] || [[ "$distro" == "debian" && "$yrelease" -ge "12" ]]; then + aptgetInstall "python3" + aptgetInstall "python3-pip" + aptgetInstall "python3-configargparse" + aptgetInstall "python3-passlib" + aptgetInstall "python3-mysqldb" + aptgetInstall "python3-chardet" + aptgetInstall "python3-requests" else - currentPythonVersion=$(python --version 2>&1 | grep -o "Python 3") - if [ ! -z "$currentPythonVersion" ]; then + aptgetInstall "python-pip" + + if [ ! -e "/usr/bin/python2" ]; then + # We need python2 still + cd "$patchDir" + wget -N "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz" + tar zxvf "Python-2.7.18.tgz" + cd "Python-2.7.18" + ./configure --prefix=/usr --with-ensurepip=install + make + make install + fi + + # Create a symlink for python if one doesn't exist + if [ ! -e "/usr/bin/python" ]; then if [ -e "/usr/bin/python2" ]; then - ln -f -s "/usr/bin/python2" "/usr/bin/python" + ln -s "/usr/bin/python2" "/usr/bin/python" + fi + else + currentPythonVersion=$(python --version 2>&1 | grep -o "Python 3") + if [ ! -z "$currentPythonVersion" ]; then + if [ -e "/usr/bin/python2" ]; then + ln -f -s "/usr/bin/python2" "/usr/bin/python" + fi fi fi - fi - - # Create a symlink for python pip 2 if one doesn't exist - if [ ! -e "/usr/bin/pip" ] && [ -e "/usr/bin/pip2" ]; then - ln -s "/usr/bin/pip2" "/usr/bin/pip" - fi - - # Install pip if it's not found on the system manually - currentPip=$(which pip) - insPip2=0 - if [ ! -z "$currentPip" ]; then - currentPipVersion=$(pip --version 2>&1 | grep -o "python3") - if [ ! -z "$currentPipVersion" ]; then + + # Create a symlink for python pip 2 if one doesn't exist + if [ ! -e "/usr/bin/pip" ] && [ -e "/usr/bin/pip2" ]; then + ln -s "/usr/bin/pip2" "/usr/bin/pip" + fi + + # Install pip if it's not found on the system manually + currentPip=$(which pip) + insPip2=0 + if [ ! -z "$currentPip" ]; then + currentPipVersion=$(pip --version 2>&1 | grep -o "python3") + if [ ! -z "$currentPipVersion" ]; then + insPip2=1 + fi + else insPip2=1 fi - else - insPip2=1 - fi - if [ "$insPip2" == 1 ]; then - cd "$patchDir" - curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py - python get-pip.py + if [ "$insPip2" == 1 ]; then + cd "$patchDir" + curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py + python get-pip.py + fi fi cd "$curDir" diff --git a/ehcp/install_lib.php b/ehcp/install_lib.php index da95c99..322f99b 100755 --- a/ehcp/install_lib.php +++ b/ehcp/install_lib.php @@ -1226,7 +1226,12 @@ function installPythonPamMysql(){ // Copy our libpam-python scripts to /etc/security passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_smtp.conf /etc/security/pam_dbauth_smtp.conf"); - passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_smtp_ubuntu_20_plus.py /etc/security/pam_dbauth_smtp.py"); + + if((getIsUbuntu() && getUbuntuReleaseYear() >= "23") || (getIsDebian() && getUbuntuReleaseYear() >= "12")){ + passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_smtp_python3.py /etc/security/pam_dbauth_smtp.py"); + }else{ + passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_smtp_ubuntu_20_plus.py /etc/security/pam_dbauth_smtp.py"); + } if((getIsUbuntu() && getUbuntuReleaseYear() >= "16") || (getIsDebian() && getUbuntuReleaseYear() >= "9")){ if(file_exists("/usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu.so")){ @@ -1235,7 +1240,11 @@ function installPythonPamMysql(){ } passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_vsftpd.conf /etc/security/pam_dbauth_vsftpd.conf"); - passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_vsftpd_ubuntu_20_plus.py /etc/security/pam_dbauth_vsftpd.py"); + if((getIsUbuntu() && getUbuntuReleaseYear() >= "23") || (getIsDebian() && getUbuntuReleaseYear() >= "12")){ + passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_vsftpd_python3.py /etc/security/pam_dbauth_vsftpd.py"); + }else{ + passthru2("cp -vf $ehcpinstalldir/etc/pam/pam_dbauth_vsftpd_ubuntu_20_plus.py /etc/security/pam_dbauth_vsftpd.py"); + } // Replace EHCP mysql password with the correct one replacelineinfile("password=","password=" . $ehcpmysqlpass,"/etc/security/pam_dbauth_smtp.conf", true); diff --git a/ehcp/install_main.sh b/ehcp/install_main.sh index ccbcee7..0e295d1 100755 --- a/ehcp/install_main.sh +++ b/ehcp/install_main.sh @@ -3050,55 +3050,67 @@ function fixSQMailPerms(){ } function installPipManuallyIfNeeded(){ - aptgetInstall "python-pip" curDir=$(pwd) - if [ ! -e "/usr/bin/python2" ]; then - # We need python2 still - cd "$patchDir" - wget -N "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz" - tar zxvf "Python-2.7.18.tgz" - cd "Python-2.7.18" - ./configure --prefix=/usr --with-ensurepip=install - make - make install - fi - - # Create a symlink for python if one doesn't exist - if [ ! -e "/usr/bin/python" ]; then - if [ -e "/usr/bin/python2" ]; then - ln -s "/usr/bin/python2" "/usr/bin/python" - fi + if [[ "$distro" == "ubuntu" && "$yrelease" -ge "23" ]] || [[ "$distro" == "debian" && "$yrelease" -ge "12" ]]; then + aptgetInstall "python3" + aptgetInstall "python3-pip" + aptgetInstall "python3-configargparse" + aptgetInstall "python3-passlib" + aptgetInstall "python3-mysqldb" + aptgetInstall "python3-chardet" + aptgetInstall "python3-requests" else - currentPythonVersion=$(python --version 2>&1 | grep -o "Python 3") - if [ ! -z "$currentPythonVersion" ]; then + aptgetInstall "python-pip" + + if [ ! -e "/usr/bin/python2" ]; then + # We need python2 still + cd "$patchDir" + wget -N "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz" + tar zxvf "Python-2.7.18.tgz" + cd "Python-2.7.18" + ./configure --prefix=/usr --with-ensurepip=install + make + make install + fi + + # Create a symlink for python if one doesn't exist + if [ ! -e "/usr/bin/python" ]; then if [ -e "/usr/bin/python2" ]; then - ln -f -s "/usr/bin/python2" "/usr/bin/python" + ln -s "/usr/bin/python2" "/usr/bin/python" + fi + else + currentPythonVersion=$(python --version 2>&1 | grep -o "Python 3") + if [ ! -z "$currentPythonVersion" ]; then + if [ -e "/usr/bin/python2" ]; then + ln -f -s "/usr/bin/python2" "/usr/bin/python" + fi fi fi - fi - - # Create a symlink for python pip 2 if one doesn't exist - if [ ! -e "/usr/bin/pip" ] && [ -e "/usr/bin/pip2" ]; then - ln -s "/usr/bin/pip2" "/usr/bin/pip" - fi - - # Install pip if it's not found on the system manually - currentPip=$(which pip) - insPip2=0 - if [ ! -z "$currentPip" ]; then - currentPipVersion=$(pip --version 2>&1 | grep -o "python3") - if [ ! -z "$currentPipVersion" ]; then + + # Create a symlink for python pip 2 if one doesn't exist + if [ ! -e "/usr/bin/pip" ] && [ -e "/usr/bin/pip2" ]; then + ln -s "/usr/bin/pip2" "/usr/bin/pip" + fi + + # Install pip if it's not found on the system manually + currentPip=$(which pip) + insPip2=0 + if [ ! -z "$currentPip" ]; then + currentPipVersion=$(pip --version 2>&1 | grep -o "python3") + if [ ! -z "$currentPipVersion" ]; then + insPip2=1 + fi + else insPip2=1 fi - else - insPip2=1 - fi - if [ "$insPip2" == 1 ]; then - cd "$patchDir" - curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py - python get-pip.py + if [ "$insPip2" == 1 ]; then + cd "$patchDir" + curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py + python get-pip.py + fi + fi cd "$curDir"