2010-03-24 16:50:50 +11:00
#!/usr/bin/env python
2007-12-10 10:29:26 +01:00
#
2009-01-16 15:50:58 +01:00
# Upgrade from Samba3
# Copyright Jelmer Vernooij 2005-2007
2007-12-10 10:29:26 +01:00
#
2009-01-16 15:50:58 +01:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
2009-11-27 10:50:03 +01:00
#
2009-01-16 15:50:58 +01:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2009-11-27 10:50:03 +01:00
#
2009-01-16 15:50:58 +01:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2010-06-13 15:32:41 +02:00
import logging
2007-12-10 10:29:26 +01:00
import optparse
2007-12-25 16:36:31 -06:00
import os, sys
2008-05-11 05:45:49 +02:00
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
2007-12-16 15:50:02 +01:00
import samba
2007-12-25 16:36:31 -06:00
import samba.getopt as options
2008-05-21 23:59:34 +02:00
from samba.auth import system_session
2009-11-27 10:50:03 +01:00
from samba.upgrade import upgrade_provision
from samba.samba3 import Samba3
parser = optparse.OptionParser("upgrade_from_s3 [options] <libdir> <smbconf>")
2008-01-23 23:33:36 +01:00
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
2007-12-10 10:29:26 +01:00
parser.add_option_group(options.VersionOptions(parser))
2007-12-25 16:36:31 -06:00
credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
2007-12-10 10:29:26 +01:00
parser.add_option("--quiet", help="Be quiet")
2009-11-27 10:50:03 +01:00
parser.add_option("--blank",
help="do not add users or groups, just the structure")
parser.add_option("--targetdir", type="string", metavar="DIR",
help="Set target directory")
2007-12-10 10:29:26 +01:00
2007-12-25 16:36:31 -06:00
opts, args = parser.parse_args()
2007-12-16 15:50:02 +01:00
2010-06-13 15:32:41 +02:00
logger = logging.getLogger("upgrade")
logger.addHandler(logging.StreamHandler(sys.stdout))
if opts.quiet:
logger.setLevel(logging.WARNING)
else:
logger.setLevel(logging.INFO)
2007-12-10 10:29:26 +01:00
2007-12-25 16:36:31 -06:00
if len(args) < 1:
parser.print_usage()
sys.exit(1)
2009-11-27 10:50:03 +01:00
2010-06-13 15:32:41 +02:00
logger.info("Reading Samba3 databases and smb.conf")
2009-11-27 10:50:03 +01:00
2007-12-25 16:36:31 -06:00
libdir = args[0]
if not os.path.isdir(libdir):
print "error: %s is not a directory"
sys.exit(1)
2009-11-27 10:50:03 +01:00
2007-12-25 16:36:31 -06:00
if len(args) > 1:
smbconf = args[1]
2007-12-10 10:29:26 +01:00
else:
2007-12-25 16:36:31 -06:00
smbconf = os.path.join(libdir, "smb.conf")
2007-12-10 10:29:26 +01:00
2009-11-27 10:50:03 +01:00
samba3 = Samba3(libdir, smbconf)
2007-12-10 10:29:26 +01:00
2010-06-13 15:32:41 +02:00
logger.info("Provisioning")
2007-12-10 10:29:26 +01:00
2008-03-28 21:57:15 +11:00
lp = sambaopts.get_loadparm()
2008-12-21 23:05:35 +01:00
smbconf = lp.configfile
2008-03-28 21:57:15 +11:00
creds = credopts.get_credentials(lp)
2008-03-07 19:20:39 +11:00
2011-02-05 10:34:51 +11:00
upgrade_provision(samba3, logger, credentials=creds,
2009-11-27 10:50:03 +01:00
session_info=system_session(), smbconf=smbconf,
targetdir=opts.targetdir)