-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFixAttributes
executable file
·74 lines (64 loc) · 1.64 KB
/
FixAttributes
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
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# FixAttributes - Fix attributes from files based on its contents
#
source ScriptFunctions
Import GoboLinux
Import Log
Import OptionParser
scriptVersion="3.2"
scriptCredits="Copyright (C) Hisham Muhammad, 2000-2003 - Released under the GNU GPL."
scriptDescription="Fix attributes from files based on its contents."
scriptUsage="[options...] files..."
scriptNotes="Default permission modes are obtained from FixAttributes.conf."
helpOnNoArguments=yes
Add_Option_Boolean "R" "recursive" "Recurses into subdirectories fixing permissions."
Add_Option_Entry "t" "true" "Sets permission <entry> if file is considered executable."
Add_Option_Entry "f" "false" "Sets permission <entry> if file is considered not executable."
Parse_Options "$@"
Parse_Conf FixAttributes.conf
function file_fix() {
Log_Verbose "$1"
if IsExecutable "$1"
then chmod $fixatChmodTrue "$1"
else chmod $fixatChmodFalse "$1"
fi
}
function rec_fixat() {
if [ -d "$1" ]
then
Log_Verbose "$1"
chmod $fixatChmodTrue "$1"
cd "$1"
Log_Verbose `pwd`
ls -A | while read i
do
rec_fixat "$i"
done
cd ..
else
file_fix "$1"
fi
}
function flat_fixat() {
if [ -d "$1" ]
then
Log_Verbose "$1"
chmod $fixatChmodTrue "$1"
else
file_fix "$1"
fi
}
[ "$fixatChmodTrue" ] || fixatChmodTrue=755
[ "$fixatChmodFalse" ] || fixatChmodFalse=644
Entry "t" && fixatChmodTrue=`Entry "t"`
Entry "f" && fixatChmodFalse=`Entry "f"`
if Boolean "recursive"
then fixatfunction=rec_fixat
else fixatfunction=flat_fixat
fi
n=$(Number_Of_Arguments)
for (( i=1 ; i<=n ; i++))
do
$fixatfunction "$(Arg $i)"
done