s3-srvsvc: Use struct pipes_struct.
[Samba/gbeck.git] / source4 / setup / upgrade_from_s3
blobcdc59dc9eb5e768c132a5957e17128c278d18b19
1 #!/usr/bin/env python
3 # Upgrade from Samba3
4 # Copyright Jelmer Vernooij 2005-2007
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import logging
20 import optparse
21 import os, sys
23 # Find right directory when running from source tree
24 sys.path.insert(0, "bin/python")
26 import samba
27 import samba.getopt as options
28 from samba.auth import system_session
29 from samba.provision import find_setup_dir
30 from samba.upgrade import upgrade_provision
31 from samba.samba3 import Samba3
33 parser = optparse.OptionParser("upgrade_from_s3 [options] <libdir> <smbconf>")
34 sambaopts = options.SambaOptions(parser)
35 parser.add_option_group(sambaopts)
36 parser.add_option_group(options.VersionOptions(parser))
37 credopts = options.CredentialsOptions(parser)
38 parser.add_option_group(credopts)
39 parser.add_option("--setupdir", type="string", metavar="DIR",
40 help="directory with setup files")
41 parser.add_option("--quiet", help="Be quiet")
42 parser.add_option("--blank",
43 help="do not add users or groups, just the structure")
44 parser.add_option("--targetdir", type="string", metavar="DIR",
45 help="Set target directory")
47 opts, args = parser.parse_args()
50 logger = logging.getLogger("upgrade")
51 logger.addHandler(logging.StreamHandler(sys.stdout))
52 if opts.quiet:
53 logger.setLevel(logging.WARNING)
54 else:
55 logger.setLevel(logging.INFO)
57 if len(args) < 1:
58 parser.print_usage()
59 sys.exit(1)
61 logger.info("Reading Samba3 databases and smb.conf")
63 libdir = args[0]
64 if not os.path.isdir(libdir):
65 print "error: %s is not a directory"
66 sys.exit(1)
68 if len(args) > 1:
69 smbconf = args[1]
70 else:
71 smbconf = os.path.join(libdir, "smb.conf")
73 samba3 = Samba3(libdir, smbconf)
75 logger.info("Provisioning")
77 setup_dir = opts.setupdir
78 if setup_dir is None:
79 setup_dir = find_setup_dir()
81 lp = sambaopts.get_loadparm()
82 smbconf = lp.configfile
83 creds = credopts.get_credentials(lp)
85 upgrade_provision(samba3, setup_dir, logger, credentials=creds,
86 session_info=system_session(), smbconf=smbconf,
87 targetdir=opts.targetdir)