This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemodcompile
executable file
·72 lines (55 loc) · 1.88 KB
/
semodcompile
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
#!/usr/bin/env bash
#################
### ARGUMENTS ###
#################
# Argument 1: SELinux policy file
te="${1}";
# If argument 1 was not specified, then display an error message to stdout and exit 1
[[ -z "${te}" ]] && echo "ERROR: Argument 1: Specify the SELinux policy file (<name>.te) to compile" && exit 1;
# [OPTIONAL] Argument 2: Install the compiled SELinux policy; this option is enabled by passing the '-i' flag
install_policy="$(echo ${@} | grep -F -- '-i')";
######################
### BINARIES/FILES ###
######################
# `make` binary
make='make';
# SELinux development makefile for compiling policies
makefile='/usr/share/selinux/devel/Makefile';
# `semodule` binary
semodule='semodule';
#################
### FUNCTIONS ###
#################
is_file() {
# If the specified file does not exist, then display an error to stdout and exit 1
[[ ! -f "${1}" ]] && echo "ERROR: Unable to locate the following file: ${1}" && exit 1;
};
is_exec() {
# If the specified command ($1) was not found on the system, display an error to stdout and exit 1
[[ -z $(command -v "${1}") ]] && echo "ERROR: Unable to execute the following command: ${1}" && exit 1;
};
###########
### PRE ###
###########
# Ensure the $te SELinux policy file exists
is_file "${te}";
# Define the output '.pp' compiled SELinux policy module
pp="${te%.te}.pp";
# Ensure the 'make' binary exists
is_exec "${make}";
# Ensure the SELinux Makefile exists
is_file "${makefile}";
#############
### START ###
#############
# Compile the SELinux policy file
"${make}" -f "${makefile}" "${pp}" || exit 1;
############
### POST ###
############
# If the '-i' flag was NOT passed, meaning the compiled module should not be installed, then exit without error here
[[ -z "${install_policy}" ]] && exit 0;
# Ensure the 'semodule' binary exists
is_exec "${semodule}";
# Install the compiled module
"${semodule}" -i "${pp}";