clevis.in 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2017 Shawn Rose
  4. #
  5. # Author: Shawn Rose <shawnandrewrose@gmail.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. PREREQ=""
  21. prereqs() {
  22. echo "$PREREQ"
  23. }
  24. case "$1" in
  25. prereqs)
  26. prereqs
  27. exit 0
  28. ;;
  29. esac
  30. [ -s /run/clevis.pid ] || exit 0
  31. pid=$(cat /run/clevis.pid)
  32. child_pids=$(ps -o pid,ppid | awk -v pid="$pid" '$2==pid { print $1 }')
  33. for kill_pid in $pid $child_pids; do
  34. kill "$kill_pid"
  35. done
  36. # Not really worried about downing extra interfaces: they will come up
  37. # during the actual boot. Might make this configurable later if needed.
  38. for iface in /sys/class/net/*; do
  39. if [ -e "$iface" ]; then
  40. iface=$(basename "$iface")
  41. ip link set dev "$iface" down
  42. ip addr flush dev "$iface"
  43. ip route flush dev "$iface"
  44. fi
  45. done