2
# IVLE - Informatics Virtual Learning Environment
3
# Copyright (C) 2007-2008 The University of Melbourne
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
# Program: MountAllUsers
20
# Author: William Grant
23
# Script to UnionFS-mount jails for all users on the system.
24
# Requires root to run.
36
p = optparse.OptionParser()
37
p.add_option('--verbose', '-v', action='store_true')
38
p.add_option('--unmount', '-u', action='store_true')
39
options, arguments = p.parse_args()
42
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
45
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
46
level=logging.WARNING)
49
print >> sys.stderr, "%s must be run as root" % \
50
os.path.basename(sys.argv[0])
53
store = ivle.database.get_store(ivle.config.Config())
54
users = store.find(ivle.database.User).order_by(ivle.database.User.login)
56
logging.info("mass aufs mount started")
60
# This is where we'll mount to...
61
destdir = os.path.join(ivle.conf.jail_base, login)
62
# ... and this is where we'll get the user bits.
63
srcdir = os.path.join(ivle.conf.jail_src_base, login)
66
if not options.unmount:
67
if not os.path.exists(srcdir):
68
logging.info("user %s doesn't have a jail - skipping" % login)
70
if not os.path.exists(destdir):
71
logging.debug("user %s had no mountpoint - creating" % login)
74
if os.system('/bin/mount -t aufs -o dirs=%s:%s=ro none %s'
75
% (srcdir,ivle.conf.jail_system,destdir)) == 0:
76
logging.info("mounted user %s's jail." % login)
78
logging.error("failed to mount user %s's jail!" % login)
80
os.system('/bin/umount ' + destdir)
81
logging.info("unmounted user %s's jail." % login)
82
except Exception, message:
83
logging.warning(str(message))
86
logging.info("mount completed successfully")