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
6 exit 16 exit 1
7fi7fi
8 8
9SF=`which setfiles`9SF=`which setfiles` || {
10if [ $? -eq 1 ]; then
11 echo "Could not find setfiles"10 echo "Could not find setfiles"
12 echo "Do you have policycoreutils installed?"11 echo "Do you have policycoreutils installed?"
13 exit 112 exit 1
14fi13}
15 14
16CP=`which checkpolicy`15CP=`which checkpolicy` || {
17if [ $? -eq 1 ]; then
18 echo "Could not find checkpolicy"16 echo "Could not find checkpolicy"
19 echo "Do you have checkpolicy installed?"17 echo "Do you have checkpolicy installed?"
20 exit 118 exit 1
21fi19}
22VERS=`$CP -V | awk '{print $1}'`20VERS=`$CP -V | awk '{print $1}'`
23 21
24ENABLED=`which selinuxenabled`22ENABLED=`which selinuxenabled` || {
25if [ $? -eq 1 ]; then
26 echo "Could not find selinuxenabled"23 echo "Could not find selinuxenabled"
27 echo "Do you have libselinux-utils installed?"24 echo "Do you have libselinux-utils installed?"
28 exit 125 exit 1
29fi26}
30 27
31if selinuxenabled; then28if selinuxenabled; then
32 echo "SELinux is already enabled"29 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