| 1 | #!/usr/bin/python
|
|---|
| 2 | #
|
|---|
| 3 | # Upgrade from Samba3
|
|---|
| 4 | # Copyright Jelmer Vernooij 2005-2007
|
|---|
| 5 | #
|
|---|
| 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.
|
|---|
| 10 | #
|
|---|
| 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.
|
|---|
| 15 | #
|
|---|
| 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/>.
|
|---|
| 18 |
|
|---|
| 19 | import getopt
|
|---|
| 20 | import optparse
|
|---|
| 21 | import os, sys
|
|---|
| 22 |
|
|---|
| 23 | # Find right directory when running from source tree
|
|---|
| 24 | sys.path.insert(0, "bin/python")
|
|---|
| 25 |
|
|---|
| 26 | import samba
|
|---|
| 27 | import samba.getopt as options
|
|---|
| 28 | from samba import param
|
|---|
| 29 | from samba.auth import system_session
|
|---|
| 30 |
|
|---|
| 31 | parser = optparse.OptionParser("upgrade [options] <libdir> <smbconf>")
|
|---|
| 32 | sambaopts = options.SambaOptions(parser)
|
|---|
| 33 | parser.add_option_group(sambaopts)
|
|---|
| 34 | parser.add_option_group(options.VersionOptions(parser))
|
|---|
| 35 | credopts = options.CredentialsOptions(parser)
|
|---|
| 36 | parser.add_option_group(credopts)
|
|---|
| 37 | parser.add_option("--setupdir", type="string", metavar="DIR",
|
|---|
| 38 | help="directory with setup files")
|
|---|
| 39 | parser.add_option("--realm", type="string", metavar="REALM", help="set realm")
|
|---|
| 40 | parser.add_option("--quiet", help="Be quiet")
|
|---|
| 41 | parser.add_option("--blank",
|
|---|
| 42 | help="do not add users or groups, just the structure")
|
|---|
| 43 | parser.add_option("--targetdir", type="string", metavar="DIR",
|
|---|
| 44 | help="Set target directory")
|
|---|
| 45 |
|
|---|
| 46 | opts, args = parser.parse_args()
|
|---|
| 47 |
|
|---|
| 48 | def message(text):
|
|---|
| 49 | """Print a message if quiet is not set."""
|
|---|
| 50 | if opts.quiet:
|
|---|
| 51 | print text
|
|---|
| 52 |
|
|---|
| 53 | if len(args) < 1:
|
|---|
| 54 | parser.print_usage()
|
|---|
| 55 | sys.exit(1)
|
|---|
| 56 | from samba.samba3 import Samba3
|
|---|
| 57 | message("Reading Samba3 databases and smb.conf\n")
|
|---|
| 58 | libdir = args[0]
|
|---|
| 59 | if not os.path.isdir(libdir):
|
|---|
| 60 | print "error: %s is not a directory"
|
|---|
| 61 | sys.exit(1)
|
|---|
| 62 | if len(args) > 1:
|
|---|
| 63 | smbconf = args[1]
|
|---|
| 64 | else:
|
|---|
| 65 | smbconf = os.path.join(libdir, "smb.conf")
|
|---|
| 66 | samba3 = Samba3(libdir, smbconf)
|
|---|
| 67 |
|
|---|
| 68 | from samba.provision import find_setup_dir
|
|---|
| 69 | from samba.upgrade import upgrade_provision
|
|---|
| 70 |
|
|---|
| 71 | message("Provisioning\n")
|
|---|
| 72 |
|
|---|
| 73 | setup_dir = opts.setupdir
|
|---|
| 74 | if setup_dir is None:
|
|---|
| 75 | setup_dir = find_setup_dir()
|
|---|
| 76 |
|
|---|
| 77 | lp = sambaopts.get_loadparm()
|
|---|
| 78 | smbconf = lp.configfile
|
|---|
| 79 | creds = credopts.get_credentials(lp)
|
|---|
| 80 |
|
|---|
| 81 | upgrade_provision(samba3, setup_dir, message, credentials=creds,
|
|---|
| 82 | session_info=system_session(), smbconf=smbconf,
|
|---|
| 83 | targetdir=opts.targetdir)
|
|---|