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/>.
23 # Find right directory when running from source tree
24 sys
.path
.insert(0, "bin/python")
27 import samba
.getopt
as options
28 from samba
.auth
import system_session
29 from samba
.upgrade
import upgrade_from_samba3
30 from samba
.samba3
import Samba3
31 from samba
.samba3
import param
as s3param
33 def get_testparm_var(testparm
, varname
):
34 cmd
= "%s -s -l --parameter-name='%s' 2>/dev/null" % (testparm
, varname
)
35 output
= os
.popen(cmd
, 'r').readline()
38 cmd_help
= """upgrade_from_s3 [options] <configuration_file> <targetdir>
41 <configuration_file> - path to existing smb.conf
42 <targetdir> - directory in which samba4 database will be created
44 In addition, specify either samba3 database directory (with --libdir) or
45 samba3 testparm utility (with --testparm). """
47 parser
= optparse
.OptionParser(cmd_help
)
48 parser
.add_option_group(options
.VersionOptions(parser
))
49 parser
.add_option("--quiet", help="Be quiet")
50 parser
.add_option("--libdir", type="string", metavar
="DIR",
51 help="samba3 database directory")
52 parser
.add_option("--testparm", type="string", metavar
="PATH",
53 help="samba3 testparm utility")
55 opts
, args
= parser
.parse_args()
62 if not os
.path
.exists(smbconf
):
63 print("error: %s does not exist" % smbconf
)
67 if not os
.path
.isdir(targetdir
):
68 print("error: %s is not a directory" % targetdir
)
72 testparm
= opts
.testparm
74 if not libdir
and not testparm
:
75 print("error: please specify either libdir or testparm")
78 if libdir
and testparm
:
79 print("warning: both libdir and testparm specified, libdir will be ignored.")
82 logger
= logging
.getLogger("upgrade")
83 logger
.addHandler(logging
.StreamHandler(sys
.stdout
))
85 logger
.setLevel(logging
.WARNING
)
87 logger
.setLevel(logging
.INFO
)
89 s3conf
= s3param
.get_context()
90 #s3conf.load_default()
92 # Set correct default values from libdir or testparm
95 paths
["state directory"] = libdir
96 paths
["private dir"] = libdir
98 paths
["state directory"] = get_testparm_var(testparm
, "state directory")
99 paths
["private dir"] = get_testparm_var(testparm
, "private dir")
102 s3conf
.set(p
, paths
[p
])
104 # load smb.conf parameters
105 logger
.info("Reading smb.conf")
107 samba3
= Samba3(smbconf
, s3conf
)
109 logger
.info("Provisioning")
110 upgrade_from_samba3(samba3
, logger
, targetdir
, session_info
=system_session())