91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
|
|
from pastafariutils import linux
|
|
import distro
|
|
import argparse
|
|
import os
|
|
import json
|
|
|
|
php_versions=['8.2', '8.3', '8.4']
|
|
|
|
linux_distro=distro.id()
|
|
|
|
parser=argparse.ArgumentParser(prog='save_php_ini.py', description='Script for save php.ini')
|
|
|
|
parser.add_argument('--version', help='The version of php', required=True)
|
|
|
|
#parser.add_argument('--ip', help='The IP where php-fpm receive orders')
|
|
|
|
args=parser.parse_args()
|
|
|
|
version=args.version
|
|
|
|
linux.json_log('Saving php.ini from server', error=0, status=0, progress=0, no_progress=1);
|
|
|
|
path_php_ini='/etc/php/php.ini'
|
|
|
|
if linux_distro=='debian':
|
|
path_php_ini='/etc/php/{}/fpm/php.ini'.format(version)
|
|
|
|
move_php_ini={'debian': 'sudo cp {} {}'.format(path_php_ini, path_php_ini+'.bak')}
|
|
|
|
move_php_ini['ubuntu']=move_php_ini['debian']
|
|
|
|
cp_php_ini={'debian': 'sudo cp ./tmp/php.ini {}'.format(path_php_ini)}
|
|
|
|
cp_php_ini['ubuntu']=cp_php_ini['debian']
|
|
|
|
linux.exec(move_php_ini)
|
|
|
|
linux.exec(cp_php_ini)
|
|
|
|
service_php={'debian': 'php{}-fpm.service'.format(version)}
|
|
|
|
service_php['ubuntu']=service_php['debian']
|
|
|
|
error=0
|
|
|
|
if not linux.systemd_service('restart', service_php):
|
|
|
|
restore_php_ini={'debian': 'sudo cp {} {}'.format(path_php_ini+'.bak', path_php_ini)}
|
|
|
|
restore_php_ini['ubuntu']=restore_php_ini['debian']
|
|
|
|
linux.json_log('Error: cannot save the new php.ini', error=1, status=1, progress=0, no_progress=1)
|
|
else:
|
|
|
|
linux.json_log('php.ini modified successfully', error=0, status=1, progress=100, no_progress=0)
|
|
|
|
# sudo systemctl restart php8.4-fpm
|
|
|
|
#linux.json_log('Getting php.ini from server', error=0, status=0, progress=0, no_progress=1);
|
|
|
|
|
|
|
|
"""
|
|
linux.json_log('Getting php.ini from server', error=0, status=0, progress=0, no_progress=1);
|
|
|
|
if not version in php_versions:
|
|
linux.json_log('Error: php version not supported', error=1, status=1, progress=100, no_progress=0);
|
|
exit(1)
|
|
|
|
path_php_ini='/etc/php/php.ini'
|
|
|
|
if linux_distro=='debian':
|
|
path_php_ini='/etc/php/{}/fpm/php.ini'.format(version)
|
|
|
|
#print(path_php_ini)
|
|
|
|
if not os.path.isfile(path_php_ini):
|
|
|
|
linux.json_log('Error: php.ini not found in {}'.path_php_ini(), error=1, status=1, progress=100, no_progress=0);
|
|
exit(1)
|
|
|
|
php_ini_file=''
|
|
|
|
with open(path_php_ini) as f:
|
|
php_ini_file=f.read()
|
|
|
|
#print(json.dumps({'error': 0, 'status': 1, 'progress': 100, 'no_progress':0, 'message': '{"distro": "'+distro.id()+'"}', 'result': 1}))
|
|
|
|
linux.json_log(json.dumps({'file':php_ini_file}), error=0, status=1, progress=100, no_progress=0, result=1)
|
|
"""
|