def linux_fixup_databasedir(): ''' Under Linux move database from /var/neubot to /var/lib/neubot ''' # Explanation: /var/lib/neubot is FHS, /var/neubot isn't if os.name != 'posix': return if not sys.platform.startswith('linux'): return if os.getuid() != 0: return if not os.path.isfile('/var/neubot/database.sqlite3'): return if os.path.exists('/var/lib/neubot/database.sqlite3'): return logging.debug('database_xxx: /var/neubot -> /var/lib/neubot...') # Lazy import from neubot import utils_posix # # Here we create the new link as root, and we assume that # the caller will fix permissions afterwards. This should # happen as long as we are invoked before the database # function that checks database path. # utils_posix.mkdir_idempotent('/var/lib/neubot') os.link('/var/neubot/database.sqlite3', '/var/lib/neubot/database.sqlite3') os.unlink('/var/neubot/database.sqlite3') logging.debug('database_xxx: /var/neubot -> /var/lib/neubot... done')
def datadir_init(self, uname=None, datadir=None): ''' Initialize datadir ''' if datadir: self.datadir = datadir else: self.datadir = utils_hier.LOCALSTATEDIR logging.debug('filesys_posix: datadir: %s', self.datadir) logging.debug('filesys_posix: user name: %s', uname) if uname: self.passwd = utils_posix.getpwnam(uname) else: self.passwd = system_posix.getpwnam() # The common case logging.debug('filesys_posix: uid: %d', self.passwd.pw_uid) logging.debug('filesys_posix: gid: %d', self.passwd.pw_gid) # # Here we are assuming that /var (BSD) or /var/lib (Linux) # exists and has the correct permissions. # We are also assuming that we are running with enough privs # to be able to create a directory there on behalf of the # specified uid and gid. # logging.debug('filesys_posix: datadir init: %s', self.datadir) utils_posix.mkdir_idempotent(self.datadir, self.passwd.pw_uid, self.passwd.pw_gid)
def datadir_init(self, uname=UNAME, datadir=None): ''' Initialize datadir ''' if datadir: self.datadir = datadir elif sys.platform.startswith('linux'): self.datadir = '/var/lib/neubot' else: self.datadir = '/var/neubot' logging.debug('filesys_posix: datadir: %s', self.datadir) logging.debug('filesys_posix: user name: %s', uname) self.passwd = utils_posix.getpwnam(uname) logging.debug('filesys_posix: uid: %d', self.passwd.pw_uid) logging.debug('filesys_posix: gid: %d', self.passwd.pw_gid) # # Here we are assuming that /var (BSD) or /var/lib (Linux) # exists and has the correct permissions. # We are also assuming that we are running with enough privs # to be able to create a directory there on behalf of the # specified uid and gid. # logging.debug('filesys_posix: datadir init: %s', self.datadir) utils_posix.mkdir_idempotent(self.datadir, self.passwd.pw_uid, self.passwd.pw_gid)
def _visit(self, curpath, leaf): ''' Callback for depth_visit() ''' if not leaf: logging.debug('filesys_posix: mkdir_idempotent: %s', curpath) utils_posix.mkdir_idempotent(curpath, self.passwd.pw_uid, self.passwd.pw_gid) else: logging.debug('filesys_posix: touch_idempotent: %s', curpath) utils_posix.touch_idempotent(curpath, self.passwd.pw_uid, self.passwd.pw_gid)