diff --git a/src/hostinfo.py b/src/hostinfo.py index b42a260da9451731ddc080c53d518007636ba030..2ecc15331dc26132a8417d5a39f4e8b14da41513 100755 --- a/src/hostinfo.py +++ b/src/hostinfo.py @@ -7,6 +7,7 @@ import hostinfo.macosx_auto import hostinfo.mio import hostinfo.named import hostinfo.parser +import hostinfo.samba import hostinfo.yp import optparse import os @@ -145,10 +146,13 @@ def tag_sort(parent, a, b): return None if __name__ == '__main__': - optParser = VerboseOptionParser(usage="%prog [options] targets*") + optParser = VerboseOptionParser(usage="%prog [options] [hostinfo]") optParser.add_option("--host", action="store", help="The host to generate information for") + optParser.add_option("--dfs", + action="store", metavar="DIR", + help="generate DIR/*/(dfslink|autolink)") optParser.add_option("--dhcpd", action="store", metavar="DIR", help="generate DIR/dhcpd.conf file") @@ -167,6 +171,9 @@ if __name__ == '__main__': optParser.add_option("--pretty", action="store_true", default=False, help="pretty-print XML tree") + optParser.add_option("--samba", + action="store", metavar="FILE", + help="generate samba share FILE") optParser.add_option("--yp", action="store", metavar="DIR", help="generate DIR/{hosts,ethers} information") @@ -184,6 +191,11 @@ if __name__ == '__main__': raise Exception("Only one hostinfo file allowed") file = {} + symlink = {} + if options.dfs: + for (f, c) in hostinfo.samba.msdfs(tree): + symlink["%s/%s" % (options.dfs, f)] = c + if options.dhcpd: file["%s/dhcpd.conf" % options.dhcpd] = hostinfo.dhcpd.conf(tree, host) @@ -213,6 +225,9 @@ if __name__ == '__main__': for (f, c) in hostinfo.yp.generate(tree): file["%s/%s" % (options.yp, f)] = c + if options.samba: + file[options.samba] = hostinfo.samba.share(tree, host) + result = 1 for name in file.keys(): write = False @@ -231,4 +246,17 @@ if __name__ == '__main__': f.write(file[name].encode("iso8859-1")) f.close() + for name in symlink.keys(): + if os.path.lexists(name) and not os.path.islink(name): + print "'%s' esists but is not a link" + elif not os.path.lexists(name): + print "Creating '%s' -> '%s'" % (name, symlink[name]) + os.symlink(symlink[name], name) + result = 0 + elif os.readlink(name) != symlink[name]: + print "Changing '%s' -> '%s'" % (name, symlink[name]) + os.unlink(name) + os.symlink(symlink[name], name) + result = 0 + sys.exit(result) diff --git a/src/hostinfo/named.py b/src/hostinfo/named.py index 7310824867e89472167c4e8f6053be1c65363def..2f1fc5bba6b7cfc7dc4e136bda6d986f33a02194 100755 --- a/src/hostinfo/named.py +++ b/src/hostinfo/named.py @@ -30,6 +30,11 @@ def generate(tree, host): conf = "include \"/etc/rndc.key\";\n" conf += "options {\n" conf += " directory \"/etc/named\"; notify no;\n" + conf += " forward first;\n" + conf += " forwarders {\n" + conf += " 130.235.20.3;\n" + conf += " 130.235.132.90;\n" + conf += " };\n" conf += "};\n" conf += "zone \".\" {\n" conf += " type hint; file \"root.hints\"; \n" diff --git a/src/hostinfo/samba.py b/src/hostinfo/samba.py new file mode 100755 index 0000000000000000000000000000000000000000..c6be5ac1e786ba9b552c20e47550b327e6e3eaea --- /dev/null +++ b/src/hostinfo/samba.py @@ -0,0 +1,37 @@ +from hostinfo.util import fqn + +def msdfs(tree): + result = [] + result.extend(dfs(tree, 'home', '/home', 'auto.home')) + result.extend(dfs(tree, 'work', '/work', 'auto.work')) + return result + +def share(tree, host): + result = "" + for h in [h for h in tree._host_ if h.name[0] == host]: + for a in [a for a in h._automount_ if a.samba[0]]: + result += "\n".join([ + "[%s]" % a.samba[0], + " browseable = no", + " path = %s" % a.root[0], + " writable = yes", + " create mode = 0664", + " directory mode = 0775" + ]) + result += "\n\n" + return result + +def dfs(tree, dir, mount, map_name): + auto = [] + for h in tree._host_: + for a in h._automount_: + if a.map[0] == map_name: + for e in a._entry_: + if a.samba[0]: + link = "msdfs:%s/%s/%s" % (h.name[0], a.samba[0], + e.path[0]) + link = link.replace('/', '\\') + else: + link = "%s/%s" % (mount, e.key[0]) + auto.append(('%s/%s' % (dir, e.key[0]), link)) + return auto