Added files
This commit is contained in:
commit
25aaa0a4bf
31 changed files with 4035 additions and 0 deletions
176
scripts/webapps/wordpress/install_wordpress_site.py
Normal file
176
scripts/webapps/wordpress/install_wordpress_site.py
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
#!/usr/bin/python3 -u
|
||||
|
||||
import sys, os
|
||||
import subprocess
|
||||
import argparse
|
||||
import platform
|
||||
import shutil
|
||||
import pathlib
|
||||
import distro
|
||||
import pwd
|
||||
import getpass
|
||||
|
||||
#import pymysql.cursors
|
||||
#pymysql.install_as_MySQLdb
|
||||
|
||||
pyv=platform.python_version_tuple()
|
||||
|
||||
if pyv[0]!='3':
|
||||
print('Need python 3 for execute this script')
|
||||
sys.exit(1)
|
||||
|
||||
parser = argparse.ArgumentParser(description='Script for create a new wordpress site.')
|
||||
|
||||
parser.add_argument('--home_user', help='The name of the new user', required=True)
|
||||
parser.add_argument('--user', help='The name of the new user', required=True)
|
||||
parser.add_argument('--password', help='The password of the new user', required=True)
|
||||
parser.add_argument('--path', help='The path of the wordpress install', required=True)
|
||||
parser.add_argument('--email', help='The email of the new user', required=True)
|
||||
parser.add_argument('--domain', help='The domain of the new wordpress', required=True)
|
||||
parser.add_argument('--title', help='The title of the new wordpress', required=True)
|
||||
|
||||
parser.add_argument('--user_mysql', help='The password of the root mysql', required=True)
|
||||
parser.add_argument('--password_mysql', help='The password of the root mysql', required=True)
|
||||
|
||||
parser.add_argument('--db_mysql', help='Database for new wp site', required=True)
|
||||
|
||||
parser.add_argument('--server_mysql', help='Server of MySQL database', required=True)
|
||||
|
||||
parser.add_argument('--port_mysql', help='The port of the MySQL server', required=True, type=int)
|
||||
|
||||
parser.add_argument('--php_version', help='The version of php used', required=True)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
wp_command='/usr/local/bin/wp'
|
||||
|
||||
php_command=''
|
||||
|
||||
linux_distro=distro.id()
|
||||
|
||||
if linux_distro=='arch':
|
||||
|
||||
php_command='/usr/bin/php-legacy'
|
||||
|
||||
if linux_distro=='fedora' or linux_distro=='rocky':
|
||||
|
||||
php_command='/usr/bin/php'+args.php_version.replace('.', '')
|
||||
|
||||
if linux_distro=='debian' or linux_distro=='ubuntu':
|
||||
|
||||
php_command='/usr/bin/php'+args.php_version
|
||||
|
||||
|
||||
system_user=getpass.getuser()
|
||||
|
||||
apache_cmd='apache2'
|
||||
apachectl='apache2ctl'
|
||||
|
||||
if linux_distro!='debian' and linux_distro!='ubuntu':
|
||||
|
||||
apache_cmd='httpd'
|
||||
apachectl='apachectl'
|
||||
|
||||
if linux_distro=='rocky' or linux_distro=='fedora':
|
||||
apache_group='apache'
|
||||
|
||||
if linux_distro=='arch':
|
||||
apache_group='http'
|
||||
|
||||
|
||||
home_user=args.home_user
|
||||
|
||||
stat_group=os.stat(home_user)
|
||||
uid=stat_group.st_uid
|
||||
|
||||
user=pwd.getpwuid(uid)[0]
|
||||
|
||||
if args.path!='/':
|
||||
|
||||
home_user=args.home_user.replace('/htdocs', args.path)
|
||||
|
||||
if not os.path.isdir(home_user):
|
||||
#os.mkdir(home_user)
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c 'mkdir -p %s'" % (user, home_user), shell=True) > 0:
|
||||
print("Error, cannot create wordpress folder sudo su %s -s /bin/bash -c 'mkdir -p %s'" % (args.user, home_user)+"\n")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Error, exists a directory with same name, i cannot install wordpress in this folder\n")
|
||||
sys.exit(1)
|
||||
|
||||
os.chdir(home_user)
|
||||
else:
|
||||
home_user=args.home_user+'/'
|
||||
|
||||
os.chdir(home_user)
|
||||
|
||||
if os.path.isfile(home_user+'/index.php'):
|
||||
|
||||
print("WARNING, Deleting old installations of wordpress in document root")
|
||||
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s/*'" % (user, home_user), shell=True) > 0:
|
||||
print("Error, ")
|
||||
sys.exit(1)
|
||||
|
||||
# Php-fpm for user
|
||||
|
||||
print('Installing Wordpress...')
|
||||
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c '%s %s core download'" % (user, php_command, wp_command), shell=True) > 0:
|
||||
print('Error')
|
||||
sys.exit(1)
|
||||
|
||||
mysql_user=args.user_mysql
|
||||
mysql_password=args.password_mysql
|
||||
|
||||
host_db=args.server_mysql
|
||||
|
||||
if args.port_mysql!=3306:
|
||||
host_db=host_db+':'+str(args.port_mysql)
|
||||
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c '%s %s config create --dbname=%s --dbuser=%s --dbpass=%s --dbhost=%s'" % (user, php_command, wp_command, args.db_mysql, mysql_user, mysql_password, host_db), shell=True) > 0:
|
||||
print('Error')
|
||||
sys.exit(1)
|
||||
|
||||
print('Created basic config...')
|
||||
|
||||
# Add cronjob for wordpress
|
||||
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c '%s %s core install --url=%s --title=\"%s\" --admin_user=%s --admin_password=%s --admin_email=%s'" % (user, php_command, wp_command, args.domain+args.path, args.title, args.user, args.password, args.email), shell=True) > 0:
|
||||
print('Error: cannot install wordpress')
|
||||
sys.exit(1)
|
||||
else:
|
||||
print('Installed Wordpress successfully...')
|
||||
|
||||
if args.path!='/':
|
||||
|
||||
alias_apache=" Alias {} {} \n\
|
||||
<Directory {}> \n\
|
||||
Options FollowSymLinks MultiViews \n\
|
||||
AllowOverride All \n\
|
||||
Require all granted \n\
|
||||
</Directory> \n\
|
||||
<Location {}>\n\
|
||||
ProxyPass ! \n\
|
||||
</Location> \n\
|
||||
".format(args.path[:-1], home_user, home_user, args.path[:-1])
|
||||
|
||||
name_file='/home/{}/{}-{}.conf'.format(system_user, args.domain, os.path.basename(args.path[:-1]))
|
||||
|
||||
with open(name_file, 'w') as f:
|
||||
f.write(alias_apache)
|
||||
|
||||
|
||||
print('Updating apache configuration for wordpress outside of htdocs...')
|
||||
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra'.format(name_file, apache_cmd), shell=True) > 0:
|
||||
print('Error')
|
||||
sys.exit(1)
|
||||
|
||||
print('Restarting apache...')
|
||||
|
||||
if subprocess.call("sudo systemctl restart "+apache_cmd, shell=True) > 0:
|
||||
print("Error: cannot update and restart apache")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
print('Apache restarted!')
|
||||
34
scripts/webapps/wordpress/install_wp.php
Normal file
34
scripts/webapps/wordpress/install_wp.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use PhangoApp\LeviathanUtils\Linux;
|
||||
|
||||
include('leviathanutils/vendor/autoload.php');
|
||||
|
||||
$user=get_current_user();
|
||||
|
||||
$file_wp='./bin/wp';
|
||||
|
||||
Linux::json_log('Installing WP Wordpress utility...', $error=0, $status=0, $progress=0, $no_progress=1);
|
||||
|
||||
if(is_file($file_wp)) {
|
||||
|
||||
Linux::json_log('Installed, updating wp...', $error=0, $status=0, $progress=0, $no_progress=1);
|
||||
|
||||
Linux::shell_command(['./bin/wp cli update --yes']);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if(!is_dir('./bin')) {
|
||||
|
||||
mkdir('./bin');
|
||||
|
||||
}
|
||||
|
||||
Linux::shell_command(['curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar']);
|
||||
Linux::shell_command(['chmod +x wp-cli.phar']);
|
||||
Linux::shell_command(["mv wp-cli.phar ./bin/wp && sudo ln -s /home/${user}/bin/wp /usr/local/bin/wp"]);
|
||||
|
||||
}
|
||||
|
||||
Linux::json_log('WP utility installed successfully', $error=0, $status=0, $progress=100, $no_progress=0);
|
||||
Loading…
Add table
Add a link
Reference in a new issue