-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhackenv_applylabels
executable file
·40 lines (30 loc) · 1.04 KB
/
hackenv_applylabels
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
#!/usr/bin/env bash
set -o errexit
set -o errtrace
datahome="${XDG_DATA_HOME:-$HOME/.local/share}"
datahome="$datahome/hackenv"
shared="$(realpath "$datahome/shared")"
printf "Applying SELinux labels...\n" >&2
if ! command -v semanage &> /dev/null; then
printf "SELinux coreutils binaries could not be found.\n" >&2
if command -v yum &> /dev/null; then
printf "Try 'sudo yum -y install policycoreutils-python-utils'\nthen try again." >&2
else
printf "Exiting.\n" >&2 && exit 0
fi
fi
printf "Setting permissions for shared directory...\n" >&2
mkdir -p "$shared"
chmod 770 "$shared"
sudo semanage fcontext "$shared(/.*)?" --deleteall
sudo semanage fcontext -a -t svirt_image_t "$shared(/.*)?"
sudo restorecon -vrF "$shared"
find "$datahome" -maxdepth 1 -type f -name '*.iso' | while read -r image; do
if ! [ -f "$image" ]; then
continue
fi
printf "Setting permissions for image %s...\n" "$(basename "$image")" >&2
sudo semanage fcontext "$image" --deleteall
sudo semanage fcontext -a -t svirt_image_t "$image"
sudo restorecon -vF "$image"
done