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.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -6,27 +6,24 @@ if [ `id -u` -ne 0 ]; then · 5 unmodified lines | |||
| 6 | exit 1 | 6 | exit 1 |
| 7 | fi | 7 | fi |
| 8 | 8 | ||
| 9 | SF=`which setfiles` | 9 | SF=`which setfiles` || { |
| 10 | if [ $? -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 1 | 12 | exit 1 |
| 14 | fi | 13 | } |
| 15 | 14 | ||
| 16 | CP=`which checkpolicy` | 15 | CP=`which checkpolicy` || { |
| 17 | if [ $? -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 1 | 18 | exit 1 |
| 21 | fi | 19 | } |
| 22 | VERS=`$CP -V | awk '{print $1}'` | 20 | VERS=`$CP -V | awk '{print $1}'` |
| 23 | 21 | ||
| 24 | ENABLED=`which selinuxenabled` | 22 | ENABLED=`which selinuxenabled` || { |
| 25 | if [ $? -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 1 | 25 | exit 1 |
| 29 | fi | 26 | } |
| 30 | 27 | ||
| 31 | if selinuxenabled; then | 28 | if selinuxenabled; then |
| 32 | echo "SELinux is already enabled" | 29 | echo "SELinux is already enabled" |