-
Notifications
You must be signed in to change notification settings - Fork 0
/
ownership_changer.sh
executable file
·75 lines (62 loc) · 1.71 KB
/
ownership_changer.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
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
75
#!/bin/bash
# Change user ownership of files
# of target dir
##########
#functions
##########
checkIfValidPaths() {
local srcPath="${1}"
echo ""
if ! [ -d "${srcPath}" ];
then
echo "${srcPath}"" is not a valid source Path!"
echo ""
return 1;
else
echo "'""${srcPath}""' is a valid path"
echo ""
return 0;
fi
}
ownership_changer() {
local targetDir="${1}"
local userName="${2}"
local userGroup="${3}"
sudo chown -Rv "${userName}":"${userGroup}" "${targetDir}"
sudo chmod -v 644 "${targetDir}"/*
}
prompt_user() {
local targetDir=$(cd ${1} && pwd)
local userName=$(id -un)
local userGroup=$(id -gn)
echo ""
echo "This script changes the permissions of all files inside the target directory to 644. "
echo "It also changes the user and group to the current user and group that ran the ownership_changer.sh script."
echo ""
echo "The following will be changed:"
echo ">>>>>>"
echo "The current working directory >>> '""${targetDir}""'"
echo "The current userName >>> '""${userName}""'"
echo "The current userGroup >>> '""${userGroup}""'"
echo ""
read -p "Is that what you want?(y or n) " resp
echo ""
case ${resp} in
[y]* ) checkIfValidPaths "${targetDir}" && ownership_changer "${targetDir}" "${userName}" "${userGroup}";;
[n]* ) echo "Now exiting..." && exit;;
*) echo "Not a valid response. Now exiting..."&& exit;;
esac
echo ""
}
############################
# Run script
############################
# Else there IS an ARGUMENT supplied
if [ $# -eq 1 ]; then
if checkIfValidPaths "${1}"; then
prompt_user "${1}"
fi
# If there IS NO initial ARGUMENT supplied
else
echo "Please enter in a valid target path location!!"
fi