diff --git a/vhost-apache2/vhost.py b/vhost-apache2/vhost.py index cab5cae..ebb37a9 100755 --- a/vhost-apache2/vhost.py +++ b/vhost-apache2/vhost.py @@ -4,7 +4,26 @@ import sys, os, platform, subprocess, logging, argparse platform_support = ['Linux'] -def sys_check(): +html_dir_path = "" +logs_dir_path = "" + +def y_n_question(question_str): + + yes = {'yes','y', 'ye', ''} + no = {'no','n'} + + while True: + sys.stdout.write(question_str + " [Y/n]: ") + choice = input().lower() + if choice in yes: + return True + elif choice in no: + return False + else: + sys.stdout.write("\nPlease respond with 'yes' or 'no'\n") + continue + +def sanity_check_system(): # check platform if platform.system() not in platform_support: @@ -19,6 +38,26 @@ def sys_check(): if not r and u: sys.exit("Apache2 (ubuntu-style) not installed on your system. Aborting...") +def sanity_chek_platform(): + + global html_dir_path, logs_dir_path + + usr = os.getlogin() + + html_dir_path = os.path.join('/home', usr, 'html') + logs_dir_path = os.path.join('/home', usr, 'logs') + + if not os.path.exists(html_dir_path): + if y_n_question("Path - " + html_dir_path + ' - does not exists. Create it?'): + os.makedirs(html_dir_path) + else: + sys.exit("Can not configure platform. Aborting...") + + if not os.path.exists(logs_dir_path): + if y_n_question("Path - " + logs_dir_path + ' - does not exists. Create it?'): + os.makedirs(logs_dir_path) + else: + sys.exit("Can not configure platform. Aborting...") if __name__ == "__main__": @@ -30,6 +69,7 @@ if __name__ == "__main__": args = p.parse_args() - print(args) + sanity_check_system() + sanity_chek_platform() + - sys_check()