-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetPerms.sh
32 lines (27 loc) · 1.11 KB
/
setPerms.sh
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
#!/bin/bash
date
if [[ -d "$1" ]]; then
DIR=$1
elif id username >/dev/null 2>&1; then
DIR='/home/username/scripts/'
elif id home-user >/dev/null 2>&1; then
DIR='/home/user/Documents/'
fi
if [ -z $DIR ]; then
echo "***** no directory set"
exit 1
fi
echo "***** The Directory is $DIR"
if id username >/dev/null 2>&1; then
echo "***** chown username:admn"
find $DIR ! \( -user username -group admn \) -exec ls -lah {} \; -exec chown username:admn {} \;
elif id home-user >/dev/null 2>&1; then
echo "***** chown home-user:admin"
find $DIR ! \( -user home-user -group admin \) -exec ls -lah {} \; -exec chown home-user:admin {} \;
fi
echo "***** all directories"
find $DIR -type d ! -perm u=rwx,g=rwxs -exec ls -lahd {} \; -exec chmod u+rwx,g+rwxs,o-rwx {} \;
echo "***** for .sh files"
find $DIR -type f -name "*.sh" ! -name "*.data" ! -path "*/backups/*" ! -perm u+rwx,g+rx-w,o-rw+x -exec ls -lah {} \; -exec chmod u+rwx,g+rx-w,o-rw+x {} \;
echo "***** for non .sh files"
find $DIR -type f ! -name "*.sh" ! -name "*.data" ! -path "*/backups/*" ! -perm u+rw-x,g+r-wx,o-rwx -exec ls -lah {} \; -exec chmod u+rw-x,g+r-wx,o-rwx {} \;