def install(): """ The auto install script args : excepts : return : none """ # ########################################################################## print(DEP_TEXT, end=' ') raw_ip = input() if raw_ip != '' and raw_ip != 'yes': raise exit_('Please satisfy the above dependencies') # ########################################################################## print(INSTALL_TEXT, end=' ') if input() != 'install': raise exit_('Install aborted') print(LINE_TEXT) # ########################################################################## # check we are running as root checking('Checking install is running as root') uid = os.getuid() if uid != 0: fail() raise exit_('The installer needs to be runs as root') ok() # ########################################################################## # check we can read ./core/core_rc - if we can't, assume we are # not in the kmotion root directory checking('Checking installer is running in correct directory') if not os.path.isfile('./core/core_rc'): fail() raise exit_( 'Please \'cd\' to the kmotion root directory before running the installer' ) ok() # if we are in the root dir set kmotion_dir kmotion_dir = os.getcwd() # check for existing motion instances checking('Checking for existing \'motion\' daemon instances') check_motion(kmotion_dir) ok() checking('Killing kmotion daemons') daemon_whip.kill_daemons() ok() # select a user to run the kmotion service checking('Searching for possible users to run kmotion service') ok() print(SELECT_USER, end=' ') users_uid = [[i[0], i[2], i[3]] for i in pwd.getpwall() if i[2] >= 500 or i[2] == 0] users = [i[0] for i in users_uid if i[0] != 'root' and i[0] != 'nobody'] uid = [i[1] for i in users_uid if i[0] != 'root' and i[0] != 'nobody'] gid = [i[2] for i in users_uid if i[0] != 'root' and i[0] != 'nobody'] for user in users: print('\'%s\'' % user, end=' ') print('\n\nType \'user\' to continue :', end=' ') select = input() if select not in users: raise exit_('Invalid user selected, Install aborted') kmotion_user = select kmotion_uid = uid[users.index(select)] kmotion_gid = gid[users.index(select)] # ########################################################################## # select ramdisk type df_out = Popen(['df'], stdout=PIPE).communicate()[0].split('\n') for line in df_out: split = line.split() if len(split) < 6: continue #if False: # debug option to force 'virtual_ramdisk' if split[5] == '/dev/shm' and int(split[1]) > 30000: ramdisk_dir = '/dev/shm/kmotion_ramdisk' checking('Selected ramdisk ... /dev/shm') ok() break else: ramdisk_dir = '%s/www/virtual_ramdisk' % kmotion_dir checking('Selected virtual_ramdisk') ok() # ########################################################################## # initialise resource configurations checking('Initialise resource configurations') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.init_rcs(kmotion_dir, ramdisk_dir) except (configparser.NoSectionError, configparser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) ok() # ########################################################################## # generate kmotion vhost checking('Generating kmotion vhost') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.gen_vhost(kmotion_dir) except (configparser.NoSectionError, configparser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) # chown is needed so kmotion vhost is not locked to root allowing non root # kmotion to regenerate the vhost os.chown('%s/www/vhosts/kmotion' % kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## # modifying 'apache2.conf' checking('Adding kmotion include to \'apache2.conf\'') try: modify_apache2(kmotion_dir) except exit_ as text_: fail() raise exit_(text_) ok() # ########################################################################## checking('Apache2 restart') ok() restart_apache2() # ########################################################################## checking('Waiting for apache2 to init processes ... please wait') ok() time.sleep(5) # ########################################################################## apache2_group, apache2_gid = get_apache2_gid() checking('Searching for Apache2 group ... found \'%s\'' % apache2_group) ok() # ########################################################################## checking('Generating \'kmotion\' executable') init_core.gen_kmotion(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Generating \'kmotion_ptz\' executable') init_core.gen_kmotion_ptz(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Moving executables to \'bin\' directories') try: exe_path = move_exes(kmotion_dir) except exit_ as text_: fail() raise exit_(text_) ok() # ########################################################################## checking('Adding @reboot to crontab') modify_crontab(kmotion_user, exe_path) ok() # ########################################################################## checking('Setting named pipes permissions') init_core.set_uid_gid_named_pipes(kmotion_dir, kmotion_uid, apache2_gid) ok() # ########################################################################## checking('Setting \'servo_state\' permissions') init_core.set_uid_gid_servo_state(kmotion_dir, kmotion_uid, apache2_gid) ok() # ########################################################################## checking('Setting mutex permissions') init_core.set_uid_gid_mutex(kmotion_dir, kmotion_uid, apache2_gid) ok() # ########################################################################## # kmotion not running, no need for mutex parser = configparser.SafeConfigParser() parser.read('%s/kmotion_rc' % kmotion_dir) ldap = parser.get('LDAP', 'enabled') images_dbase_dir = parser.get('dirs', 'images_dbase_dir') port = parser.get('misc', 'port') images_dbase_limit_gb = parser.get('storage', 'images_dbase_limit_gb') # ########################################################################## checking('Removing root pyc\'s') rm_root_pycs(kmotion_dir) ok() # ########################################################################## print(FOOTER_TEXT % (port, images_dbase_dir, images_dbase_limit_gb, ldap, port, port), end=' ') print(LINE_TEXT)
# ########################################################################## checking('Waiting for apache2 to init processes ... please wait') ok() time.sleep(5) # ########################################################################## apache2_group, apache2_gid = get_apache2_gid() checking('Searching for Apache2 group ... found \'%s\'' % apache2_group) ok() # ########################################################################## checking('Generating \'kmotion\' executable') init_core.gen_kmotion(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Generating \'kmotion_ptz\' executable') init_core.gen_kmotion_ptz(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Moving executables to \'bin\' directories') try: exe_path = move_exes(kmotion_dir) except exit_, text_: fail()
def install(): """ The core install script for manual install args : excepts : return : none """ # ########################################################################## print INSTALL_TEXT, if raw_input() != "install core": raise exit_("Install aborted") print LINE_TEXT # ########################################################################## # check we are not running as root checking("Checking install is not running as root") uid = os.getuid() if uid == 0: fail() raise exit_("The installer needs to be run as a normal user") ok() # ########################################################################## # check we can read ./core/core_rc - if we can't, assume we are # not in the kmotion root directory checking("Checking installer is running in correct directory") if not os.path.isfile("./core/core_rc"): fail() raise exit_("Please 'cd' to the kmotion root directory before running the installer") ok() # if we are in the root dir set kmotion_dir kmotion_dir = os.getcwd() kmotion_uid = os.stat("%s/install_core.py" % kmotion_dir)[stat.ST_UID] kmotion_gid = os.stat("%s/install_core.py" % kmotion_dir)[stat.ST_GID] parser = ConfigParser.SafeConfigParser() parser.read("%s/core/core_rc" % kmotion_dir) ramdisk_dir = parser.get("dirs", "ramdisk_dir") # check for existing motion instances checking("Checking for existing 'motion' daemon instances") check_motion(kmotion_dir) ok() # ########################################################################## # initialise resource configurations checking("Initialise resource configurations") try: # wrapping in a try - except because parsing data from kmotion_rc init_core.init_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_("Corrupt 'kmotion_rc' : %s" % sys.exc_info()[1]) ok() # ########################################################################## # setup FIFO's checking("Generating FIFO's") # use BASH rather than os.mkfifo(), FIFO bug workaround :) fifo_func = "%s/www/fifo_func" % kmotion_dir if not os.path.exists(fifo_func): # os.mkfifo(fifo_func) call(["mkfifo", fifo_func]) fifo_settings = "%s/www/fifo_settings_wr" % kmotion_dir if not os.path.exists(fifo_settings): # os.mkfifo(fifo_settings) call(["mkfifo", fifo_settings]) fifo_ptz = "%s/www/fifo_ptz" % kmotion_dir if not os.path.exists(fifo_ptz): # os.mkfifo(fifo_ptz) call(["mkfifo", fifo_ptz]) fifo_ptz_preset = "%s/www/fifo_ptz_preset" % kmotion_dir if not os.path.exists(fifo_ptz_preset): # os.mkfifo(fifo_ptz_preset) call(["mkfifo", fifo_ptz_preset]) ok() # ########################################################################## # generate kmotion vhost checking("Generating kmotion vhost") try: # wrapping in a try - except because parsing data from kmotion_rc init_core.gen_vhost(kmotion_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_("Corrupt 'kmotion_rc' : %s" % sys.exc_info()[1]) # chown is needed so kmotion vhost is not locked to root allowing non root # kmotion to regenerate the vhost os.chown("%s/www/vhosts/kmotion" % kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking("Generating 'kmotion' executable") init_core.gen_kmotion(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking("Generating 'kmotion_ptz' executable") init_core.gen_kmotion_ptz(kmotion_dir, kmotion_uid, kmotion_gid) ok() print LINE_TEXT
def install(): """ The core install script for manual install args : excepts : return : none """ # ########################################################################## print INSTALL_TEXT, if raw_input() != 'install core': raise exit_('Install aborted') print LINE_TEXT # ########################################################################## # check we are not running as root checking('Checking install is not running as root') uid = os.getuid() if uid == 0: fail() raise exit_('The installer needs to be run as a normal user') ok() # ########################################################################## # check we can read ./core/kmotion_rc - if we can't, assume we are # not in the kmotion root directory checking('Checking installer is running in correct directory') if not os.path.isfile('./kmotion_rc'): fail() raise exit_('Please \'cd\' to the kmotion root directory before running the installer') ok() # if we are in the root dir set kmotion_dir kmotion_dir = os.getcwd() kmotion_uid = os.stat('%s/install_core.py' % kmotion_dir)[stat.ST_UID] kmotion_gid = os.stat('%s/install_core.py' % kmotion_dir)[stat.ST_GID] parser = ConfigParser.SafeConfigParser() parser.read('%s/kmotion_rc' % kmotion_dir) ramdisk_dir = parser.get('dirs', 'ramdisk_dir') # check for existing motion instances checking('Checking for existing \'motion\' daemon instances') check_motion(kmotion_dir) ok() # ########################################################################## # initialise resource configurations checking('Initialise resource configurations') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.init_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) ok() # ########################################################################## # setup FIFO's checking('Generating FIFO\'s') # use BASH rather than os.mkfifo(), FIFO bug workaround :) fifo_func = '%s/www/fifo_func' % kmotion_dir if not os.path.exists(fifo_func): # os.mkfifo(fifo_func) call(['mkfifo', fifo_func]) fifo_settings = '%s/www/fifo_settings_wr' % kmotion_dir if not os.path.exists(fifo_settings): # os.mkfifo(fifo_settings) call(['mkfifo', fifo_settings]) fifo_ptz = '%s/www/fifo_ptz' % kmotion_dir if not os.path.exists(fifo_ptz): #os.mkfifo(fifo_ptz) call(['mkfifo', fifo_ptz]) fifo_ptz_preset = '%s/www/fifo_ptz_preset' % kmotion_dir if not os.path.exists(fifo_ptz_preset): #os.mkfifo(fifo_ptz_preset) call(['mkfifo', fifo_ptz_preset]) ok() # ########################################################################## # generate kmotion vhost checking('Generating kmotion vhost') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.gen_vhost(kmotion_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) # chown is needed so kmotion vhost is not locked to root allowing non root # kmotion to regenerate the vhost os.chown('%s/www/vhosts/kmotion' % kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Generating \'kmotion\' executable') init_core.gen_kmotion(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Generating \'kmotion_ptz\' executable') init_core.gen_kmotion_ptz(kmotion_dir, kmotion_uid, kmotion_gid) ok() print LINE_TEXT
def install(): """ The core install script for manual install args : excepts : return : none """ # ########################################################################## print INSTALL_TEXT, if raw_input() != 'install core': raise exit_('Install aborted') print LINE_TEXT # ########################################################################## # check we are not running as root checking('Checking install is not running as root') uid = os.getuid() if uid == 0: fail() raise exit_('The installer needs to be run as a normal user') ok() # ########################################################################## # check we can read ./core/core_rc - if we can't, assume we are # not in the kmotion root directory checking('Checking installer is running in correct directory') if not os.path.isfile('./core/core_rc'): fail() raise exit_('Please \'cd\' to the kmotion root directory before running the installer') ok() # if we are in the root dir set kmotion_dir kmotion_dir = os.getcwd() kmotion_uid = os.stat('%s/install_core.py' % kmotion_dir)[stat.ST_UID] kmotion_gid = os.stat('%s/install_core.py' % kmotion_dir)[stat.ST_GID] parser = ConfigParser.SafeConfigParser() parser.read('%s/core/core_rc' % kmotion_dir) ramdisk_dir = parser.get('dirs', 'ramdisk_dir') # check for existing motion instances checking('Checking for existing \'motion\' daemon instances') check_motion(kmotion_dir) ok() # ########################################################################## # initialise resource configurations checking('Initialise resource configurations') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.init_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) ok() # ########################################################################## # setup FIFO's checking('Generating FIFO\'s') # use BASH rather than os.mkfifo(), FIFO bug workaround :) fifo_func = '%s/www/fifo_func' % kmotion_dir if not os.path.exists(fifo_func): # os.mkfifo(fifo_func) call(['mkfifo', fifo_func]) fifo_settings = '%s/www/fifo_settings_wr' % kmotion_dir if not os.path.exists(fifo_settings): # os.mkfifo(fifo_settings) call(['mkfifo', fifo_settings]) fifo_ptz = '%s/www/fifo_ptz' % kmotion_dir if not os.path.exists(fifo_ptz): #os.mkfifo(fifo_ptz) call(['mkfifo', fifo_ptz]) fifo_ptz_preset = '%s/www/fifo_ptz_preset' % kmotion_dir if not os.path.exists(fifo_ptz_preset): #os.mkfifo(fifo_ptz_preset) call(['mkfifo', fifo_ptz_preset]) ok() # ########################################################################## # generate kmotion vhost checking('Generating kmotion vhost') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.gen_vhost(kmotion_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) # chown is needed so kmotion vhost is not locked to root allowing non root # kmotion to regenerate the vhost os.chown('%s/www/vhosts/kmotion' % kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Generating \'kmotion\' executable') init_core.gen_kmotion(kmotion_dir, kmotion_uid, kmotion_gid) ok() # ########################################################################## checking('Generating \'kmotion_ptz\' executable') init_core.gen_kmotion_ptz(kmotion_dir, kmotion_uid, kmotion_gid) ok() print LINE_TEXT