Skip to content

Instantly share code, notes, and snippets.

@weatheredwatcher
Last active November 15, 2023 00:10
Show Gist options
  • Save weatheredwatcher/14dd0d50ee3e876746ff to your computer and use it in GitHub Desktop.
Save weatheredwatcher/14dd0d50ee3e876746ff to your computer and use it in GitHub Desktop.
import os
import sys
import argparse
import wget
import tarfile
if not os.geteuid() == 0:
sys.exit("\nMust be run by root\n")
def main(argv):
##define options here
server_root = '/var/www/vhosts/'
plugin_path = '/var/resources/plugins/'
theme_path = '/var/resources/themes/' # Corrected missing leading slash
options = ''
domain = ''
parser = argparse.ArgumentParser()
parser.add_argument('domain')
args = parser.parse_args(argv)
domain = args.domain
##create folder
if not os.path.exists(server_root):
print("Creating " + server_root)
os.makedirs(server_root)
if not os.path.exists('tmp'):
print("Creating Temp Folder")
os.makedirs('tmp') # Corrected method name to 'makedirs'
##download wordpress
download = wget.download('https://wordpress.org/latest.tar.gz')
archive = tarfile.open(download, 'r:gz')
archive.extractall(server_root)
os.rename(os.path.join(server_root, 'wordpress'), os.path.join(server_root, domain))
##install base theme
##install base plugins
##create vhost file
filename = domain + ".conf"
with open(filename, 'w') as target:
vhost = f"""
<VirtualHost *:80>
ServerName {domain}
ServerAlias www.{domain}
DocumentRoot /var/www/{domain}
<Directory /var/www/{domain}>
Options -Indexes FollowSymLinks -MultiViews
AllowOverride All
</Directory>
CustomLog /var/log/httpd/{domain}-access.log combined
ErrorLog /var/log/httpd/{domain}-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
</VirtualHost>
"""
target.write(vhost)
if __name__ == "__main__":
main(sys.argv[1:])
@weatheredwatcher
Copy link
Author

Made some updates to the code. Updates for latest version of Python. Using f-strings now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment