-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatesamba.py
More file actions
45 lines (39 loc) · 1.43 KB
/
Copy pathcreatesamba.py
File metadata and controls
45 lines (39 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
#-*- coding: utf-8 -*-
# Copyright (C) 2016 Vasilis Daloukas <bdaloukas@gmail.com>
# License GNU GPL version 3 or newer <http://gnu.org/licenses/gpl.html>
import os, fileinput, getpass, shutil, sys
def update_samba( input_file, temp_file, name, dirname):
search = "[" + name + "]"
found = 0
for line in fileinput.input(input_file):
if line[0:len(search)] == search:
found = 1
if found == 0:
with open(temp_file, "w") as text_file:
for line in fileinput.input(input_file):
text_file.write( line)
text_file.write( "\n")
text_file.write( search + "\n")
text_file.write( "\tpath=" + dirname + "\n")
text_file.write( "\twriteable = yes\n")
text_file.write( "\tbrowsable = yes\n")
text_file.write( "\tguest ok = yes\n")
print "Έγινε η αλλαγή"
return 1
print "Καμία αλλαγή"
return 0
def repair_samba( name, dirname):
input_file = "/etc/samba/smb.conf"
temp_file = input_file + ".tmp"
bak_file = input_file + ".bak"
if update_samba( input_file, temp_file, name, dirname) != 0:
shutil.copyfile( input_file, bak_file)
shutil.copyfile( temp_file, input_file)
dirname = os.environ['HOME'] + "/public";
try:
os.stat(dirname)
except:
os.mkdir(dirname)
os.system( "chmod 755 " + dirname)
repair_samba( "public", dirname)