History

selinux: Chain up tool resolving errors in install_policy.sh

Subshell evaluations are not exempt from errexit, so if a command is not available, `which` will fail and exit the script as a whole. This causes the helpful error messages to not be printed if they are tacked on using a `$?` comparison. Resolve the issue by using chains of logical operators, which are not subject to the effects of errexit.

Tim Schumacher committed 1 year ago

Commit 6ae00421 parent 2c2b1e01 file · +6 −9Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/selinux/install_policy.sh+6−9
@@ -6,27 +6,24 @@ if [ `id -u` -ne 0 ]; then · 5 unmodified lines
66 exit 1
77 fi
88
9−SF=`which setfiles`
10−if [ $? -eq 1 ]; then
9+SF=`which setfiles` || {
1110 echo "Could not find setfiles"
1211 echo "Do you have policycoreutils installed?"
1312 exit 1
14−fi
13+}
1514
16−CP=`which checkpolicy`
17−if [ $? -eq 1 ]; then
15+CP=`which checkpolicy` || {
1816 echo "Could not find checkpolicy"
1917 echo "Do you have checkpolicy installed?"
2018 exit 1
21−fi
19+}
2220 VERS=`$CP -V | awk '{print $1}'`
2321
24−ENABLED=`which selinuxenabled`
25−if [ $? -eq 1 ]; then
22+ENABLED=`which selinuxenabled` || {
2623 echo "Could not find selinuxenabled"
2724 echo "Do you have libselinux-utils installed?"
2825 exit 1
29−fi
26+}
3027
3128 if selinuxenabled; then
3229 echo "SELinux is already enabled"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t