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)
def install(): """ The auto install script args : excepts : return : none """ # ########################################################################## print DEP_TEXT, raw_ip = raw_input() if raw_ip != '' and raw_ip != 'yes': raise exit_('Please satisfy the above dependencies') # ########################################################################## print INSTALL_TEXT, if raw_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 ./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() # 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, 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, print '\n\nType \'user\' to continue :', select = raw_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_, text_: fail() raise exit_(text_)
def upgrade(): """ Upgrades kmotion to the latest version args : excepts : return : none """ print RESET_TEXT, raw_ip = raw_input() if raw_ip != 'upgrade': raise exit_('Upgrade aborted') print LINE_TEXT # ########################################################################## # check we are running as root checking('Checking upgrade is running as root') uid = os.getuid() if uid != 0: fail() raise exit_('The upgrade must be run root') ok() # ########################################################################## # check we can read ./kmotion_rc - if we can't, assume we are # not in the kmotion root directory checking('Checking upgrade is running in correct directory') if not os.path.isfile('./kmotion_rc'): fail() raise exit_('Please \'cd\' to the kmotion directory before running the upgrade') ok() # if we are in the root dir set kmotion_dir kmotion_dir = os.getcwd() # ########################################################################## checking('Checking that kmotion is currently installed') if not os.path.isfile('%s/www/vhosts/kmotion' % kmotion_dir): fail() raise exit_('Please install kmotion first before attempting to upgrade') ok() # ########################################################################## checking('Cleaning upgrade directory') wipe_upgrade_dir() ok() # ########################################################################## checking('Checking current version') parser = mutex_kmotion_parser_rd(kmotion_dir) current_version = parser.get('version', 'string') ok() latest_version = get_latest_version(current_version) checking('Checking latest version') ok() # ########################################################################## if latest_version == 'SVN': raise exit_('Can\'t upgrade SVN version, \'svn update\' for the latest build') if latest_version != current_version: # download the latest version checking('Downloading version %s' % latest_version) ok() download_version(latest_version) # ###################################################################### checking('Saving \'ramdisk_dir\' location') ramdisk_dir = parser.get('dirs', 'ramdisk_dir') ok() # ###################################################################### # chdir to kmotion/core/upgrade for gunzip and tar os.chdir('/tmp/kmotion_upgrade') checking('Un-zipping') Popen('gunzip upgrade.tar.gz', shell=True) time.sleep(2) # else tar cannot always find file ok() checking('Un-taring') Popen('tar xf upgrade.tar', shell=True) ok() # and back to kmotion/core os.chdir('%s/core' % kmotion_dir) # ###################################################################### checking('Killing kmotion daemons') daemon_whip.kill_daemons() ok() # ###################################################################### # walk through updateing files checking('Updateing files') ok() update_all(kmotion_dir) # ###################################################################### # set 'ramdisk_dir' in kmotion_rc checking('Restoreing \'ramdisk_dir\' location') parser = mutex_kmotion_parser_rd(kmotion_dir) parser.set('dirs', 'ramdisk_dir', ramdisk_dir) mutex_kmotion_parser_wr(kmotion_dir, parser) ok() # initialise resource configurations checking('Initialise resource configurations') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.update_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) ok() # ###################################################################### # cleaning up checking('Cleaning upgrade directory') wipe_upgrade_dir() ok() # ###################################################################### checking('Restarting apache2') ok() if not restart_apache2(): checking('Restarted apache2') fail() print APACHE_UPGRADED_TEXT else: checking('Restarted apache2') ok() print UPGRADED_TEXT print LINE_TEXT else: print NOT_UPGRADED_TEXT print LINE_TEXT
def upgrade(): """ Upgrades kmotion to the latest version args : excepts : return : none """ print RESET_TEXT, raw_ip = raw_input() if raw_ip != 'upgrade': raise exit_('Upgrade aborted') print LINE_TEXT # ########################################################################## # check we are running as root checking('Checking upgrade is running as root') uid = os.getuid() if uid != 0: fail() raise exit_('The upgrade must be run root') ok() # ########################################################################## # check we can read ./core/core_rc - if we can't, assume we are # not in the kmotion root directory checking('Checking upgrade is running in correct directory') if not os.path.isfile('./core/core_rc'): fail() raise exit_( 'Please \'cd\' to the kmotion directory before running the upgrade' ) ok() # if we are in the root dir set kmotion_dir kmotion_dir = os.getcwd() # ########################################################################## checking('Checking that kmotion is currently installed') if not os.path.isfile('%s/www/vhosts/kmotion' % kmotion_dir): fail() raise exit_( 'Please install kmotion first before attempting to upgrade') ok() # ########################################################################## checking('Cleaning upgrade directory') wipe_upgrade_dir() ok() # ########################################################################## checking('Checking current version') parser = mutex_core_parser_rd(kmotion_dir) current_version = parser.get('version', 'string') ok() latest_version = get_latest_version(current_version) checking('Checking latest version') ok() # ########################################################################## if latest_version == 'SVN': raise exit_( 'Can\'t upgrade SVN version, \'svn update\' for the latest build') if latest_version != current_version: # download the latest version checking('Downloading version %s' % latest_version) ok() download_version(latest_version) # ###################################################################### checking('Saving \'ramdisk_dir\' location') ramdisk_dir = parser.get('dirs', 'ramdisk_dir') ok() # ###################################################################### # chdir to kmotion/core/upgrade for gunzip and tar os.chdir('/tmp/kmotion_upgrade') checking('Un-zipping') Popen('gunzip upgrade.tar.gz', shell=True) time.sleep(2) # else tar cannot always find file ok() checking('Un-taring') Popen('tar xf upgrade.tar', shell=True) ok() # and back to kmotion/core os.chdir('%s/core' % kmotion_dir) # ###################################################################### checking('Killing kmotion daemons') daemon_whip.kill_daemons() ok() # ###################################################################### # walk through updateing files checking('Updateing files') ok() update_all(kmotion_dir) # ###################################################################### # set 'ramdisk_dir' in core_rc checking('Restoreing \'ramdisk_dir\' location') parser = mutex_core_parser_rd(kmotion_dir) parser.set('dirs', 'ramdisk_dir', ramdisk_dir) mutex_core_parser_wr(kmotion_dir, parser) ok() # initialise resource configurations checking('Initialise resource configurations') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.update_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): fail() raise exit_('Corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) ok() # ###################################################################### # cleaning up checking('Cleaning upgrade directory') wipe_upgrade_dir() ok() # ###################################################################### checking('Restarting apache2') ok() if not restart_apache2(): checking('Restarted apache2') fail() print APACHE_UPGRADED_TEXT else: checking('Restarted apache2') ok() print UPGRADED_TEXT print LINE_TEXT else: print NOT_UPGRADED_TEXT print LINE_TEXT
def install(): """ The auto install script args : excepts : return : none """ # ########################################################################## print DEP_TEXT, raw_ip = raw_input() if raw_ip != '' and raw_ip != 'yes': raise exit_('Please satisfy the above dependencies') # ########################################################################## print INSTALL_TEXT, if raw_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, 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, print '\n\nType \'user\' to continue :', select = raw_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_, text_: fail() raise exit_(text_)