2 ######################################################################
4 ## Simple add/delete/change share command script for Samba
6 ## Copyright (C) Gerald Carter 2004.
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 3 of the License, or
11 ## (at your option) any later version.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ######################################################################
25 from SambaConfig import SambaConf
29 ## check the command line args ##
32 if len(sys.argv) == 3:
34 print "Deleting share..."
35 elif len(sys.argv) == 5:
36 print "Adding/Updating share..."
38 print "Usage: %s configfile share [path] [comments]" % sys.argv[0]
43 ## read and parse the config file ##
46 confFile = SambaConf()
48 confFile.ReadConfig( sys.argv[1] )
49 if not confFile.valid:
53 if not confFile.isService( sys.argv[2] ):
54 sys.stderr.write( "Asked to delete non-existent service! [%s]\n" % sys.argv[2] )
57 confFile.DelService( sys.argv[2] )
59 ## make the path if it doesn't exist. Bail out if that fails
60 if ( not os.path.isdir(sys.argv[3]) ):
62 os.makedirs( sys.argv[3] )
63 os.chmod( sys.argv[3], 0777 )
67 ## only add a new service -- if it already exists, then
68 ## just set the options
69 if not confFile.isService( sys.argv[2] ):
70 confFile.AddService( sys.argv[2], ['##', '## Added by modify_samba_config.py', '##'] )
71 confFile.SetServiceOption( sys.argv[2], "path", sys.argv[3] )
72 confFile.SetServiceOption( sys.argv[2], "comment", sys.argv[4] )
73 confFile.SetServiceOption( sys.argv[2], "read only", "no" )
75 ret = confFile.Flush()