~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to remakeallusers.py

  • Committer: dcoles
  • Date: 2008-05-26 01:44:57 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:755
Added support for an incremental rebuild of all the users jails.
It can be run by `./remakeallusers -i`

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import pwd
31
31
import conf
32
32
import common.makeuser
 
33
import optparse
 
34
import shutil
33
35
# Import modules from the website is tricky since they're in the www
34
36
# directory.
35
37
sys.path.append(os.path.join(os.getcwd(), 'www'))
36
38
 
 
39
p = optparse.OptionParser()
 
40
p.add_option('--incremental', '-i', action='store_true')
 
41
options, arguments = p.parse_args()
 
42
 
37
43
if os.getuid() != 0:
38
44
    print "Must run remakeallusers.py as root."
39
45
    sys.exit()
50
56
    print "Error: " + str(message)
51
57
    sys.exit(1)
52
58
 
 
59
# First check that our __templateuser__ directory exits, if not create it
 
60
templateuserdir = os.path.join(conf.jail_base, '__templateuser__')
 
61
stagingdir = templatedir = os.path.join(conf.jail_base, '__staging__')
 
62
if not os.path.isdir(templateuserdir):
 
63
    os.mkdir(templateuserdir)
 
64
 
 
65
# Generate manifest of files that differ between template user and staging
 
66
if options.incremental:
 
67
    print "Incremental Rebuild selected"
 
68
    manifest = common.makeuser.generate_manifest(stagingdir, templateuserdir)
 
69
    print "Generated change manifest"
 
70
    print "Adding/Updating: %s\nRemoving: %s" % manifest
 
71
else:
 
72
    # Force a full rebuild
 
73
    manifest = None
 
74
 
53
75
list.sort(key=lambda user: user.login)
54
76
for user in list:
55
77
    login = user.login
63
85
            raise Exception("User %s does not have a unixid in the database"
64
86
                % login)
65
87
        # Remake the user's jail
66
 
        common.makeuser.make_jail(login, uid)
 
88
        common.makeuser.make_jail(login, uid, manifest=manifest)
67
89
    except Exception, message:
68
90
        print "Error: " + str(message)
69
91
        continue
70
92
 
71
93
    print "Successfully recreated user %s's jail." % login
 
94
    
 
95
# Update the template user directory
 
96
print "Updating templateuser directory"
 
97
shutil.rmtree(templateuserdir)
 
98
#common.makeuser.linktree(stagingdir, templateuserdir)
 
99
common.makeuser.make_jail('__templateuser__', 0, manifest=manifest)
 
100
shutil.rmtree(os.path.join(templateuserdir, 'home'))
 
101
 
 
102
print "Done!"