3 # Sync PostgreSQL users with system users
4 # Copyright (C) 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: julia,v 1.9 2003-01-02 18:12:50 troup Exp $
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
24 # <aj> what's wrong with me!?!?!?
25 # <aj> i was just nice to some mormon doorknockers!!!
28 # <Omnic> I'm gonna have to kick your ass when you come over
29 # <Culus> aj: GET THE HELL OUT OF THE CABAL! :P
31 ################################################################################
37 ################################################################################
41 ################################################################################
43 def usage (exit_code=0):
44 print """Usage: julia [OPTION]...
45 Sync PostgreSQL's users with system users.
47 -h, --help show this help and exit
48 -n, --no-action don't do anything
49 -q, --quiet be quiet about what is being done
50 -v, --verbose explain what is being done"""
53 ################################################################################
58 Cnf = utils.get_conf()
60 Arguments = [('n', "no-action", "Julia::Options::No-Action"),
61 ('q', "quiet", "Julia::Options::Quiet"),
62 ('v', "verbose", "Julia::Options::Verbose"),
63 ('h', "help", "Julia::Options::Help")];
64 for i in [ "no-action", "quiet", "verbose", "help" ]:
65 if not Cnf.has_key("Julia::Options::%s" % (i)):
66 Cnf["Julia::Options::%s" % (i)] = "";
68 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
69 Options = Cnf.SubTree("Julia::Options")
74 utils.warn("julia takes no non-option arguments.");
77 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
78 valid_gid = int(Cnf.get("Julia::ValidGID",""));
81 for entry in pwd.getpwall():
84 if valid_gid and gid != valid_gid:
85 if Options["Verbose"]:
86 print "Skipping %s (GID %s != Valid GID %s)." % (uname, gid, valid_gid);
88 passwd_unames[uname] = "";
91 q = projectB.query("SELECT usename FROM pg_user");
95 postgres_unames[uname] = "";
97 known_postgres_unames = {};
98 for i in Cnf.get("Julia::KnownPostgres","").split(","):
100 known_postgres_unames[uname] = "";
102 keys = postgres_unames.keys()
105 if not passwd_unames.has_key(uname)and not known_postgres_unames.has_key(uname):
106 print "W: %s is in Postgres but not the passwd file or list of known Postgres users." % (uname);
108 keys = passwd_unames.keys()
111 if not postgres_unames.has_key(uname):
112 if not Options["Quiet"]:
113 print "Creating %s user in Postgres." % (uname);
114 if not Options["No-Action"]:
115 q = projectB.query('CREATE USER "%s"' % (uname));
117 #######################################################################################
119 if __name__ == '__main__':