summaryrefslogtreecommitdiffstats
path: root/abs/core/linhes-scripts/acl_fix_fstab.py
blob: 187cab1fa9813b85789a596cc18c9225c07cf898 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python2
import os
import sys
import subprocess as sub

def should_add_acl(mount_point,fs_map):
    acl_fs_list=["ext3","ext4"]
    rc = False
    for i in fs_map:
        if i[0] == mount_point:
            if i[1] in acl_fs_list:
                rc = True

    return rc


cmd="cp -f /etc/fstab /etc/fstab.backup.pre_acl"
os.system(cmd)
f = open('/etc/fstab', 'r')
fstab=f.readlines()
f.close()

p = sub.Popen(['/sbin/fsck','-N' ],stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
output = output.split("\n")
fs_map=[]
for i in output:
    if i.startswith("["):
	split_line=i.split()
	#find mount_p and remove the last char
	mount_p = split_line[3][:-1]
	fstype = split_line[4].split(".")[1]
	append_tuple=(mount_p,fstype)
	fs_map.append(append_tuple)



mp=['/' , '/myth', '/data']
newfstab=[]
for line in fstab:
    new_line=line
    split_line=line.split()
    try:
        if split_line[1] in mp and should_add_acl(split_line[1],fs_map):
            #print split_line[3]
            if "acl" in split_line[3]:
                pass
            else:
                print "Adding ACL"
                new_acl=split_line[3]+",acl"
                split_line[3]=new_acl
                new_line='\t'.join(split_line)
    except:
        pass
    newfstab.append(new_line)


f = open('/etc/fstab', 'w')
for i in newfstab:
    f.write(i)
    f.write("\n")

f.close()