-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab2_zad1.sh
45 lines (35 loc) · 988 Bytes
/
Lab2_zad1.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
#!/bin/bash
set -eu
TARGET_DIRECTORY="${1:-lab3}"
if [ $# -eq 0 ]; then
echo "Argumenty nie były podane"
exit 1
fi
if [[ ! -d "${TARGET_DIRECTORY}" ]]; then
echo "Podany katalog nie istnineje"
exit 1
fi
for FILE_NAME in "${TARGET_DIRECTORY}"/*;
do
if [[ -f "${FILE_NAME}" ]]; then
if [[ "${FILE_NAME}" == *.bak ]]; then
chmod a-w "${FILE_NAME}"
fi
if [[ "${FILE_NAME}" == *.txt ]]; then
chmod 241 "${FILE_NAME}"
fi
if [[ "${FILE_NAME}" == *.exe ]]; then
chmod a+x "${FILE_NAME}"
chmod u+s "${FILE_NAME}" #s - flaga specjalna UID, kazdy uruchamia jak wlasciciel
fi
fi
if [[ -d "${FILE_NAME}" ]]; then
if [[ "${FILE_NAME}" == *.bak ]]; then
chmod 426 "${FILE_NAME}"
fi
if [[ "${FILE_NAME}" == *.tmp ]]; then
chmod a-w "${FILE_NAME}"
chmod u+w "${FILE_NAME}"
fi
fi
done