Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created October 12, 2015 04:55
Show Gist options
  • Save gnilchee/7f3927e2cefbac42f3c1 to your computer and use it in GitHub Desktop.
Save gnilchee/7f3927e2cefbac42f3c1 to your computer and use it in GitHub Desktop.
SELinux config file update script written in Bash
#!/usr/bin/env bash
disabled() {
sed -i 's/^SELINUX=.*/SELINUX=disabled/' config && echo SUCCESS || echo FAILURE
}
permissive() {
sed -i 's/^SELINUX=.*/SELINUX=permissive/' config && echo SUCCESS || echo FAILURE
}
enforcing() {
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' config && echo SUCCESS || echo FAILURE
}
current() {
grep -E '^SELINUX=' config | awk -F "=" '{print $2}'
}
printconfig() {
cat config
}
case "$1" in
--disabled)
disabled
;;
--permissive)
permissive
;;
--enforcing)
enforcing
;;
--current)
current
;;
--print)
printconfig
;;
*)
echo "Usage: $(readlink -f $0) {--current|--print|--disabled|--permissive|--enforcing}"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment