-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixperms
More file actions
65 lines (49 loc) · 1.57 KB
/
Copy pathfixperms
File metadata and controls
65 lines (49 loc) · 1.57 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/env bash
################################################################################
### CHECK SCRIPT INVOCATION AND SET CONSTANTS
################################################################################
### CHECK FOR ROOT USER
if [[ $(whoami) != "root" ]]; then
echo "ERROR! Script needs root access. Please run as sudo";
exit 0;
fi;
### ENSURE THAT THE SCRIPT IS CALLED WITH PARAMETERS
if [[ $1 == "" ]]; then
echo "Usage: fixperms <username> <path>";
exit 0;
fi
### CHECK EXISTANCE OF SECOND PARAM
if [[ $2 != "" ]]; then
DIR=$2;
else
DIR=$(pwd);
fi
### CREATE VARIABLES
USER=$1;
GROUP="_www";
################################################################################
### RUN SCRIPT
################################################################################
### DOUBLE CHECK
bool="n";
echo -n "Warning: This will set permissions and owner on ${DIR} Are you sure? ";
read bool;
if [[ ${bool} == "y" || ${bool} == "Y" || ${bool} == "yes" || ${bool} == "YES" || ${bool} == "Yes" ]]; then
echo "Setting owner:group to ${USER}:${GROUP} on ${DIR}";
chown -R ${USER}:${GROUP} ${DIR};
echo "Setting permissions on ${DIR}";
while IFS= read -r N;
do
chmod -R 775 "${N}" || echo "Failed on ${N}";
done < <(find ${DIR} -type d);
while IFS= read -r N;
do
chmod 664 "${N}" || echo "Failed on ${N}";
done < <(find ${DIR} -type f);
else
exit 0;
fi
################################################################################
### FINISHED OUTPUT
################################################################################
echo "Completed.";