-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilesystem.bash
More file actions
36 lines (33 loc) · 854 Bytes
/
filesystem.bash
File metadata and controls
36 lines (33 loc) · 854 Bytes
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
#!/bin/bash
# @ checkFolder
# Description: Chek if folder exists (or create it)
# 1st param : Full path to folder
# 2nd param : [optional] if 'create' is used, then I create the folder if not exists
# Return : 'ERR' when something was wrong, else return 'OK'
function checkFolder {
local folder="${1}"
local create="${2}"
if [[ "${create}" == 'create' ]]; then
mkdir -p "${folder}" &>/dev/null
fi
if [[ ! -d "${folder}" ]]; then
echo 'ERR'
else
echo 'OK'
fi
}
# @ getOwner
# Description: Returns user:group owner of a file or folder
# 1st param : Full path to file/folder
function getOwner {
local object="${1}"
local usr=$(stat -c '%U' ${object})
local grp=$(stat -c '%G' ${object})
if [ -z "${usr}" ]; then
echo 'ERR'
elif [ -z "${grp}" ]; then
echo 'ERR'
else
echo "${usr}:${grp}"
fi
}