def install(): parser = argparse.ArgumentParser(description='Domogik installation.') parser.add_argument('--no-setup', dest='setup', action="store_true", default=False, help='Don\'t install the python packages') parser.add_argument('--no-test', dest='test', action="store_true", default=False, help='Don\'t run a config test') parser.add_argument('--no-config', dest='config', action="store_true", default=False, help='Don\'t run a config writer') parser.add_argument('--no-create-user', dest='user_creation', \ action="store_false", \ default=True, help='Don\'t create a user') parser.add_argument('--no-db-upgrade', dest='db', action="store_true", default=False, help='Don\'t do a db upgrade') parser.add_argument("--user", help="Set the domogik user") # generate dynamically all arguments for the various config files # notice that we MUST NOT have the same sections in the different files! parser.add_argument('--command-line', dest='command_line', \ action="store_true", default=False, \ help='Configure the configuration files from the command line only') add_arguments_for_config_file(parser, \ "src/domogik/examples/config/domogik.cfg.sample") add_arguments_for_config_file(parser, \ "src/domogik/xpl/hub/examples/config/xplhub.cfg.sample") args = parser.parse_args() try: # CHECK python version if sys.version_info < (2, 6): print "Python version is to low, at least python 2.6 is needed" exit(0) # CHECK sources not in / or /root info("Check the sources location (not in /root/ or /") print os.getcwd() assert os.getcwd().startswith("/root/") == False, "Domogik sources must not be located in the /root/ folder" # CHECK run as root info("Check this script is started as root") assert os.getuid() == 0, "This script must be started as root" ok("Correctly started with root privileges.") # RUN setup.py if not args.setup: info("Run setup.py") os.system('python setup.py develop') # ask for the domogik user if args.user == None or args.user == '': user = ask_user_name() else: ok("User setted to '{0}' from the command line".format(args.user)) user = args.user # create user if args.user_creation: create_user(user) # Copy files copy_files(user) update_default(user) # write config file if args.command_line: info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile_from_command_line(args) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile_from_command_line(args) else: if not args.config and needupdate(): info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile(False) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile(False) # upgrade db if not args.db: try: user_entry = pwd.getpwnam(user) except KeyError: raise KeyError("The user %s does not exists, you MUST create it or change the DOMOGIK_USER parameter in %s. Please report this as a bug if you used install.sh." % (user, file)) # launch db_install as the domogik user #uid = user_entry.pw_uid #user_home = user_entry.pw_dir #os.setreuid(0,uid) #old_home = os.environ['HOME'] #os.environ['HOME'] = user_home #os.system('python src/domogik/install/db_install.py') #os.setreuid(0,0) #os.environ['HOME'] = old_home try: import traceback # we must activate the domogik module as setup.py is launched from install.py and just after we try # to import something from the domogik package but the module is not known without doing anything... pkg_resources.get_distribution("domogik").activate() from domogik.install.db_install import DbInstall except: print("Trace: {0}".format(traceback.format_exc())) dbi = DbInstall() dbi.install_or_upgrade_db() # change permissions to some files created as root during the installation to the domogik user os.chown("/var/log/domogik/db_api.log", user_entry.pw_uid, -1) os.chown("/var/lock/domogik/config.lock", user_entry.pw_uid, -1) if not args.test: os.system('python test_config.py') print("\n\n") except: fail(sys.exc_info())
def install(): parser = argparse.ArgumentParser(description='Domogik installation.') parser.add_argument('--no-setup', dest='setup', action="store_true", default=False, help='Don\'t install the python packages') parser.add_argument('--no-test', dest='test', action="store_true", default=False, help='Don\'t run a config test') parser.add_argument('--no-config', dest='config', action="store_true", default=False, help='Don\'t run a config writer') parser.add_argument('--no-create-user', dest='user_creation', \ action="store_false", \ default=True, help='Don\'t create a user') parser.add_argument('--no-db-upgrade', dest='db', action="store_true", default=False, help='Don\'t do a db upgrade') parser.add_argument("--user", help="Set the domogik user") # generate dynamically all arguments for the various config files # notice that we MUST NOT have the same sections in the different files! parser.add_argument('--command-line', dest='command_line', \ action="store_true", default=False, \ help='Configure the configuration files from the command line only') add_arguments_for_config_file(parser, \ "src/domogik/examples/config/domogik.cfg.sample") add_arguments_for_config_file(parser, \ "src/domogik/xpl/hub/examples/config/xplhub.cfg.sample") args = parser.parse_args() try: # CHECK python version if sys.version_info < (2, 6): print "Python version is to low, at least python 2.6 is needed" exit(0) # CHECK run as root info("Check this script is started as root") assert os.getuid() == 0, "This script must be started as root" ok("Correctly started with root privileges.") # RUN setup.py if not args.setup: info("Run setup.py") os.system('python setup.py develop') # ask for the domogik user if args.user == None or args.user == '': user = ask_user_name() else: ok("User setted to '{0}' from the command line".format(args.user)) user = args.user # create user if args.user_creation: create_user(user) # Copy files copy_files(user) update_default(user) # write config file if args.command_line: info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile_from_command_line(args) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile_from_command_line(args) else: if not args.config and needupdate(): info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile(False) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile(False) # upgrade db if not args.db: try: user_entry = pwd.getpwnam(user) except KeyError: raise KeyError("The user %s does not exists, you MUST create it or change the DOMOGIK_USER parameter in %s. Please report this as a bug if you used install.sh." % (user, file)) # launch db_install as the domogik user #uid = user_entry.pw_uid #user_home = user_entry.pw_dir #os.setreuid(0,uid) #old_home = os.environ['HOME'] #os.environ['HOME'] = user_home #os.system('python src/domogik/install/db_install.py') #os.setreuid(0,0) #os.environ['HOME'] = old_home try: import traceback # we must activate the domogik module as setup.py is launched from install.py and just after we try # to import something from the domogik package but the module is not known without doing anything... pkg_resources.get_distribution("domogik").activate() from domogik.install.db_install import DbInstall except: print("Trace: {0}".format(traceback.format_exc())) dbi = DbInstall() dbi.install_or_upgrade_db() # change permissions to some files created as root during the installation to the domogik user os.chown("/var/log/domogik/db_api.log", user_entry.pw_uid, -1) os.chown("/var/lock/domogik/config.lock", user_entry.pw_uid, -1) if not args.test: os.system('python test_config.py') print("\n\n") except: fail(sys.exc_info())
def install(): parser = argparse.ArgumentParser(description='Domogik installation.') parser.add_argument('--dist-packages', dest='dist_packages', action="store_true", default=False, help='Try to use distribution packages instead of pip packages') parser.add_argument('--no-create-database', dest='no_create_database', action="store_true", default=False, help='create and allow domogik to access to it, if it is not already created') parser.add_argument('--no-setup', dest='setup', action="store_true", default=False, help='Don\'t install the python packages') parser.add_argument('--no-test', dest='test', action="store_true", default=False, help='Don\'t run a config test') parser.add_argument('--no-config', dest='config', action="store_true", default=False, help='Don\'t run a config writer') parser.add_argument('--no-create-user', dest='user_creation', \ action="store_false", \ default=True, help='Don\'t create a user') parser.add_argument('--no-db-upgrade', dest='db', action="store_true", default=False, help='Don\'t do a db upgrade') parser.add_argument('--no-mq-check', dest='mq', action="store_true", default=False, help='Don\'t check the mq package') parser.add_argument('--no-db-backup', dest='skip_database_backup', action="store_true", default=False, help='Don\'t do a db backup') parser.add_argument("--user", help="Set the domogik user") parser.add_argument("--user-shell", dest="user_shell", help="Set the domogik user shell") parser.add_argument('--advanced', dest='advanced_mode', action="store_true", default=False, help='Allow to configure all options in interactive mode') # generate dynamically all arguments for the various config files # notice that we MUST NOT have the same sections in the different files! parser.add_argument('--command-line', dest='command_line', \ action="store_true", default=False, \ help='Configure the configuration files from the command line only') add_arguments_for_config_file(parser, \ "src/domogik/examples/config/domogik.cfg.sample") add_arguments_for_config_file(parser, \ "src/domogik/xpl/hub/examples/config/xplhub.cfg.sample") args = parser.parse_args() print(args) try: # CHECK python version if sys.version_info < (2, 6): fail("Python version is to low, at least python 2.6 is needed") exit(0) # CHECK sources not in / or /root info("Check the sources location (not in /root/ or /") print(os.getcwd()) assert os.getcwd().startswith("/root/") == False, "Domogik sources must not be located in the /root/ folder" # CHECK mysql or mariaDB release do_we_need_mariadb(get_mysql_or_mariadb_release(), args.command_line) # CHECK mq installed if not args.mq: info("Check that domogik-mq is installed") try: import domogikmq except ImportError: fail("Please install Domogik MQ first! (https://github.com/domogik/domogik-mq)") exit(0) # Execute database fix for some 0.2/0.3 databases #info("Process some database upgrade issues with previous releases") #cmd = "sh ./src/domogik/install/db_fix_03.sh" #p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) #lines_iterator = iter(p.stdout.readline, b"") #for line in lines_iterator: # print(line) if args.dist_packages: dist_packages_install_script = '' #platform.dist() and platform.linux_distribution() #doesn't works with ubuntu/debian, both say debian. #So I not found pettiest test :( if os.system(' bash -c \'[ "`lsb_release -si`" == "Debian" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' elif os.system(' bash -c \'[ "`lsb_release -si`" == "Ubuntu" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' elif os.system(' bash -c \'[ "`lsb_release -si`" == "Raspbian" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' if dist_packages_install_script == '' : raise OSError("The option --dist-packages is not implemented on this distribution. \nPlease install the packages manually.\n When packages have been installed, you can re reun the installation script without the --dist-packages option.") if os.system(dist_packages_install_script) != 0: raise OSError("Cannot install packages correctly script '%s'" % dist_packages_install_script) # RUN setup.py if not args.setup: info("Run setup.py") if os.system('python setup.py develop') != 0: raise OSError("setup.py doesn't finish correctly") # ask for the domogik user if args.user == None or args.user == '': user = ask_user_name() else: ok("User setted to '{0}' from the command line".format(args.user)) user = args.user # create user if args.user_creation: if args.user_shell: create_user(user, args.user_shell) else: create_user(user) # Copy files copy_files(user) update_default(user) # write config file if args.command_line: info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile_from_command_line(args) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile_from_command_line(args) else: if not args.config and needupdate(): # select the correct interface intf = find_interface() # if 'lo' not int intf, add it (because domoweb by default try to catch REST on 127.0.0.1) if 'lo' not in intf: intf = "lo,{0}".format(intf) # update the config file info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile(args.advanced_mode, intf) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile(args.advanced_mode, intf) # upgrade db if not args.db: # check if alembic version is at least 0.7.4. Else raise an error from alembic import __version__ as alembic_version if version.StrictVersion(alembic_version) < version.StrictVersion("0.7.4"): fail("The 'alembic' version installed on this system ({0}) is not recent enough. Please install at least alembic >= 0.7.4".format(alembic_version)) exit(0) # do db upgrade try: user_entry = pwd.getpwnam(user) except KeyError: raise KeyError("The user %s does not exists, you MUST create it or change the DOMOGIK_USER parameter in %s. Please report this as a bug if you used install.sh." % (user, file)) # launch db_install as the domogik user #uid = user_entry.pw_uid #user_home = user_entry.pw_dir #os.setreuid(0,uid) #old_home = os.environ['HOME'] #os.environ['HOME'] = user_home #os.system('python src/domogik/install/db_install.py') #os.setreuid(0,0) #os.environ['HOME'] = old_home try: import traceback # we must activate the domogik module as setup.py is launched from install.py and just after we try # to import something from the domogik package but the module is not known without doing anything... pkg_resources.get_distribution("domogik").activate() from domogik.install.db_install import DbInstall except: print("Trace: {0}".format(traceback.format_exc())) dbi = DbInstall() if not args.no_create_database: dbi.create_db() dbi.install_or_upgrade_db(args.skip_database_backup) # change permissions to some files created as root during the installation to the domogik user os.chown("/var/log/domogik/db_api.log", user_entry.pw_uid, -1) os.chown("/var/lock/domogik/config.lock", user_entry.pw_uid, -1) if not args.test: os.system('python test_config.py') print("\n\n") except SystemExit: # a sys.exit have been called, do not raise more errors pass except: import traceback print("========= TRACEBACK =============") print(traceback.format_exc()) print("=================================") fail(sys.exc_info())
def install(): parser = argparse.ArgumentParser(description='Domogik installation.') parser.add_argument('--dist-packages', dest='dist_packages', action="store_true", default=False, help='Try to use distribution packages instead of pip packages') parser.add_argument('--create-database', dest='create_database', action="store_true", default=False, help='create and allow domogik to access to it, if it is not already created') parser.add_argument('--no-setup', dest='setup', action="store_true", default=False, help='Don\'t install the python packages') parser.add_argument('--no-test', dest='test', action="store_true", default=False, help='Don\'t run a config test') parser.add_argument('--no-config', dest='config', action="store_true", default=False, help='Don\'t run a config writer') parser.add_argument('--no-create-user', dest='user_creation', \ action="store_false", \ default=True, help='Don\'t create a user') parser.add_argument('--no-db-upgrade', dest='db', action="store_true", default=False, help='Don\'t do a db upgrade') parser.add_argument('--no-mq-check', dest='mq', action="store_true", default=False, help='Don\'t check the mq package') parser.add_argument('--no-db-backup', dest='skip_database_backup', action="store_true", default=False, help='Don\'t do a db backup') parser.add_argument("--user", help="Set the domogik user") parser.add_argument("--user-shell", dest="user_shell", help="Set the domogik user shell") # generate dynamically all arguments for the various config files # notice that we MUST NOT have the same sections in the different files! parser.add_argument('--command-line', dest='command_line', \ action="store_true", default=False, \ help='Configure the configuration files from the command line only') add_arguments_for_config_file(parser, \ "src/domogik/examples/config/domogik.cfg.sample") add_arguments_for_config_file(parser, \ "src/domogik/xpl/hub/examples/config/xplhub.cfg.sample") args = parser.parse_args() try: # CHECK python version if sys.version_info < (2, 6): fail("Python version is to low, at least python 2.6 is needed") exit(0) # CHECK sources not in / or /root info("Check the sources location (not in /root/ or /") print os.getcwd() assert os.getcwd().startswith("/root/") == False, "Domogik sources must not be located in the /root/ folder" # CHECK mq installed if not args.mq: info("Check that domogik-mq is installed") try: import domogikmq except ImportError: fail("Please install Domogik MQ first! (https://github.com/domogik/domogik-mq)") exit(0) if args.dist_packages: dist_packages_install_script = '' #platform.dist() and platform.linux_distribution() #doesn't works with ubuntu/debian, both say debian. #So I not found pettiest test :( if os.system(' bash -c \'[ "`lsb_release -si`" == "Debian" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' if dist_packages_install_script == '' : raise OSError("This argument is not implemented on this distribution.") if os.system(dist_packages_install_script) != 0: raise OSError("Cannot install packages correctly script '%s'" % dist_packages_install_script) # RUN setup.py if not args.setup: info("Run setup.py") if os.system('python setup.py develop') != 0: raise OSError("setup.py doesn't finish correctly") # ask for the domogik user if args.user == None or args.user == '': user = ask_user_name() else: ok("User setted to '{0}' from the command line".format(args.user)) user = args.user # create user if args.user_creation: if args.user_shell: create_user(user, args.user_shell) else: create_user(user) # Copy files copy_files(user) update_default(user) # write config file if args.command_line: info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile_from_command_line(args) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile_from_command_line(args) else: if not args.config and needupdate(): info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile(False) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile(False) # upgrade db if not args.db: try: user_entry = pwd.getpwnam(user) except KeyError: raise KeyError("The user %s does not exists, you MUST create it or change the DOMOGIK_USER parameter in %s. Please report this as a bug if you used install.sh." % (user, file)) # launch db_install as the domogik user #uid = user_entry.pw_uid #user_home = user_entry.pw_dir #os.setreuid(0,uid) #old_home = os.environ['HOME'] #os.environ['HOME'] = user_home #os.system('python src/domogik/install/db_install.py') #os.setreuid(0,0) #os.environ['HOME'] = old_home try: import traceback # we must activate the domogik module as setup.py is launched from install.py and just after we try # to import something from the domogik package but the module is not known without doing anything... pkg_resources.get_distribution("domogik").activate() from domogik.install.db_install import DbInstall except: print("Trace: {0}".format(traceback.format_exc())) dbi = DbInstall() if args.create_database: dbi.create_db() dbi.install_or_upgrade_db(args.skip_database_backup) # change permissions to some files created as root during the installation to the domogik user os.chown("/var/log/domogik/db_api.log", user_entry.pw_uid, -1) os.chown("/var/lock/domogik/config.lock", user_entry.pw_uid, -1) if not args.test: os.system('python test_config.py') print("\n\n") except: import traceback print "========= TRACEBACK =============" print traceback.format_exc() print "=================================" fail(sys.exc_info())
def install(): parser = argparse.ArgumentParser(description='Domogik installation.') parser.add_argument( '--dist-packages', dest='dist_packages', action="store_true", default=False, help='Try to use distribution packages instead of pip packages') parser.add_argument( '--no-create-database', dest='no_create_database', action="store_true", default=False, help= 'create and allow domogik to access to it, if it is not already created' ) parser.add_argument('--no-setup', dest='setup', action="store_true", default=False, help='Don\'t install the python packages') parser.add_argument('--no-test', dest='test', action="store_true", default=False, help='Don\'t run a config test') parser.add_argument('--no-config', dest='config', action="store_true", default=False, help='Don\'t run a config writer') parser.add_argument('--no-create-user', dest='user_creation', \ action="store_false", \ default=True, help='Don\'t create a user') parser.add_argument('--no-db-upgrade', dest='db', action="store_true", default=False, help='Don\'t do a db upgrade') parser.add_argument('--no-mq-check', dest='mq', action="store_true", default=False, help='Don\'t check the mq package') parser.add_argument('--no-db-backup', dest='skip_database_backup', action="store_true", default=False, help='Don\'t do a db backup') parser.add_argument("--user", help="Set the domogik user") parser.add_argument("--user-shell", dest="user_shell", help="Set the domogik user shell") parser.add_argument( '--advanced', dest='advanced_mode', action="store_true", default=False, help='Allow to configure all options in interactive mode') # generate dynamically all arguments for the various config files # notice that we MUST NOT have the same sections in the different files! parser.add_argument('--command-line', dest='command_line', \ action="store_true", default=False, \ help='Configure the configuration files from the command line only') add_arguments_for_config_file(parser, \ "src/domogik/examples/config/domogik.cfg.sample") add_arguments_for_config_file(parser, \ "src/domogik/xpl/hub/examples/config/xplhub.cfg.sample") args = parser.parse_args() print(args) try: # CHECK python version if sys.version_info < (2, 6): fail("Python version is to low, at least python 2.6 is needed") exit(0) # CHECK sources not in / or /root info("Check the sources location (not in /root/ or /") print(os.getcwd()) assert os.getcwd().startswith( "/root/" ) == False, "Domogik sources must not be located in the /root/ folder" # CHECK mysql or mariaDB release do_we_need_mariadb(get_mysql_or_mariadb_release(), args.command_line) # CHECK mq installed if not args.mq: info("Check that domogik-mq is installed") try: import domogikmq except ImportError: fail( "Please install Domogik MQ first! (https://github.com/domogik/domogik-mq)" ) exit(0) # Execute database fix for some 0.2/0.3 databases #info("Process some database upgrade issues with previous releases") #cmd = "sh ./src/domogik/install/db_fix_03.sh" #p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) #lines_iterator = iter(p.stdout.readline, b"") #for line in lines_iterator: # print(line) if args.dist_packages: dist_packages_install_script = '' #platform.dist() and platform.linux_distribution() #doesn't works with ubuntu/debian, both say debian. #So I not found pettiest test :( if os.system( ' bash -c \'[ "`lsb_release -si`" == "Debian" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' elif os.system( ' bash -c \'[ "`lsb_release -si`" == "Ubuntu" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' elif os.system( ' bash -c \'[ "`lsb_release -si`" == "Raspbian" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' if dist_packages_install_script == '': raise OSError( "The option --dist-packages is not implemented on this distribution. \nPlease install the packages manually.\n When packages have been installed, you can re reun the installation script without the --dist-packages option." ) if os.system(dist_packages_install_script) != 0: raise OSError("Cannot install packages correctly script '%s'" % dist_packages_install_script) # RUN setup.py if not args.setup: info("Run setup.py") if os.system('python setup.py develop') != 0: raise OSError("setup.py doesn't finish correctly") # ask for the domogik user if args.user == None or args.user == '': user = ask_user_name() else: ok("User setted to '{0}' from the command line".format(args.user)) user = args.user # create user if args.user_creation: if args.user_shell: create_user(user, args.user_shell) else: create_user(user) # Copy files copy_files(user) update_default(user) # write config file if args.command_line: info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile_from_command_line(args) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile_from_command_line(args) else: if not args.config and needupdate(): # select the correct interface intf = find_interface() # if 'lo' not int intf, add it (because domoweb by default try to catch REST on 127.0.0.1) if 'lo' not in intf: intf = "lo,{0}".format(intf) # update the config file info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile(args.advanced_mode, intf) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile(args.advanced_mode, intf) # upgrade db if not args.db: # check if alembic version is at least 0.7.4. Else raise an error from alembic import __version__ as alembic_version if version.StrictVersion(alembic_version) < version.StrictVersion( "0.7.4"): fail( "The 'alembic' version installed on this system ({0}) is not recent enough. Please install at least alembic >= 0.7.4" .format(alembic_version)) exit(0) # do db upgrade try: user_entry = pwd.getpwnam(user) except KeyError: raise KeyError( "The user %s does not exists, you MUST create it or change the DOMOGIK_USER parameter in %s. Please report this as a bug if you used install.sh." % (user, file)) # launch db_install as the domogik user #uid = user_entry.pw_uid #user_home = user_entry.pw_dir #os.setreuid(0,uid) #old_home = os.environ['HOME'] #os.environ['HOME'] = user_home #os.system('python src/domogik/install/db_install.py') #os.setreuid(0,0) #os.environ['HOME'] = old_home try: import traceback # we must activate the domogik module as setup.py is launched from install.py and just after we try # to import something from the domogik package but the module is not known without doing anything... pkg_resources.get_distribution("domogik").activate() from domogik.install.db_install import DbInstall except: print("Trace: {0}".format(traceback.format_exc())) dbi = DbInstall() if not args.no_create_database: dbi.create_db() dbi.install_or_upgrade_db(args.skip_database_backup) # change permissions to some files created as root during the installation to the domogik user os.chown("/var/log/domogik/db_api.log", user_entry.pw_uid, -1) os.chown("/var/lock/domogik/config.lock", user_entry.pw_uid, -1) if not args.test: os.system('python test_config.py') print("\n\n") except SystemExit: # a sys.exit have been called, do not raise more errors pass except: import traceback print("========= TRACEBACK =============") print(traceback.format_exc()) print("=================================") fail(sys.exc_info())
def install(): parser = argparse.ArgumentParser(description='Domogik installation.') parser.add_argument( '--dist-packages', dest='dist_packages', action="store_true", default=False, help='Try to use distribution packages instead of pip packages') parser.add_argument( '--create-database', dest='create_database', action="store_true", default=False, help= 'create and allow domogik to access to it, if it is not already created' ) parser.add_argument('--no-setup', dest='setup', action="store_true", default=False, help='Don\'t install the python packages') parser.add_argument('--no-test', dest='test', action="store_true", default=False, help='Don\'t run a config test') parser.add_argument('--no-config', dest='config', action="store_true", default=False, help='Don\'t run a config writer') parser.add_argument('--no-create-user', dest='user_creation', \ action="store_false", \ default=True, help='Don\'t create a user') parser.add_argument('--no-db-upgrade', dest='db', action="store_true", default=False, help='Don\'t do a db upgrade') parser.add_argument('--no-mq-check', dest='mq', action="store_true", default=False, help='Don\'t check the mq package') parser.add_argument('--no-db-backup', dest='skip_database_backup', action="store_true", default=False, help='Don\'t do a db backup') parser.add_argument("--user", help="Set the domogik user") parser.add_argument("--user-shell", dest="user_shell", help="Set the domogik user shell") # generate dynamically all arguments for the various config files # notice that we MUST NOT have the same sections in the different files! parser.add_argument('--command-line', dest='command_line', \ action="store_true", default=False, \ help='Configure the configuration files from the command line only') add_arguments_for_config_file(parser, \ "src/domogik/examples/config/domogik.cfg.sample") add_arguments_for_config_file(parser, \ "src/domogik/xpl/hub/examples/config/xplhub.cfg.sample") args = parser.parse_args() try: # CHECK python version if sys.version_info < (2, 6): fail("Python version is to low, at least python 2.6 is needed") exit(0) # CHECK sources not in / or /root info("Check the sources location (not in /root/ or /") print os.getcwd() assert os.getcwd().startswith( "/root/" ) == False, "Domogik sources must not be located in the /root/ folder" # CHECK mq installed if not args.mq: info("Check that domogik-mq is installed") try: import domogikmq except ImportError: fail( "Please install Domogik MQ first! (https://github.com/domogik/domogik-mq)" ) exit(0) if args.dist_packages: dist_packages_install_script = '' #platform.dist() and platform.linux_distribution() #doesn't works with ubuntu/debian, both say debian. #So I not found pettiest test :( if os.system( ' bash -c \'[ "`lsb_release -si`" == "Debian" ]\'') == 0: dist_packages_install_script = './debian_packages_install.sh' if dist_packages_install_script == '': raise OSError( "This argument is not implemented on this distribution.") if os.system(dist_packages_install_script) != 0: raise OSError("Cannot install packages correctly script '%s'" % dist_packages_install_script) # RUN setup.py if not args.setup: info("Run setup.py") if os.system('python setup.py develop') != 0: raise OSError("setup.py doesn't finish correctly") # ask for the domogik user if args.user == None or args.user == '': user = ask_user_name() else: ok("User setted to '{0}' from the command line".format(args.user)) user = args.user # create user if args.user_creation: if args.user_shell: create_user(user, args.user_shell) else: create_user(user) # Copy files copy_files(user) update_default(user) # write config file if args.command_line: info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile_from_command_line(args) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile_from_command_line(args) else: if not args.config and needupdate(): info("Update the config file : /etc/domogik/domogik.cfg") write_domogik_configfile(False) info("Update the config file : /etc/domogik/xplhub.cfg") write_xplhub_configfile(False) # upgrade db if not args.db: try: user_entry = pwd.getpwnam(user) except KeyError: raise KeyError( "The user %s does not exists, you MUST create it or change the DOMOGIK_USER parameter in %s. Please report this as a bug if you used install.sh." % (user, file)) # launch db_install as the domogik user #uid = user_entry.pw_uid #user_home = user_entry.pw_dir #os.setreuid(0,uid) #old_home = os.environ['HOME'] #os.environ['HOME'] = user_home #os.system('python src/domogik/install/db_install.py') #os.setreuid(0,0) #os.environ['HOME'] = old_home try: import traceback # we must activate the domogik module as setup.py is launched from install.py and just after we try # to import something from the domogik package but the module is not known without doing anything... pkg_resources.get_distribution("domogik").activate() from domogik.install.db_install import DbInstall except: print("Trace: {0}".format(traceback.format_exc())) dbi = DbInstall() if args.create_database: dbi.create_db() dbi.install_or_upgrade_db(args.skip_database_backup) # change permissions to some files created as root during the installation to the domogik user os.chown("/var/log/domogik/db_api.log", user_entry.pw_uid, -1) os.chown("/var/lock/domogik/config.lock", user_entry.pw_uid, -1) if not args.test: os.system('python test_config.py') print("\n\n") except: import traceback print "========= TRACEBACK =============" print traceback.format_exc() print "=================================" fail(sys.exc_info())