| 1 | #!/bin/bash |
| 2 | VER=1.0 |
| 3 | # ============================================================================ |
| 4 | # |
| 5 | # Copyright (C) THALES. All rights reserved |
| 6 | # Author: Laurent Mazet |
| 7 | # Date : 15/12/2014 |
| 8 | # ============================================================================ |
| 9 | |
| 10 | ### BEGIN INIT INFO |
| 11 | # Provides: checkudevrules |
| 12 | # Required-Start: udev checkroot |
| 13 | # Required-Stop: |
| 14 | # Should-Start: |
| 15 | # Default-Start: S |
| 16 | # Default-Stop: |
| 17 | # Short-Description: Check udev rules |
| 18 | # Description: Check udev rules files (70-persistent-*.rules) and reboot if necessary |
| 19 | ### END INIT INFO |
| 20 | |
| 21 | FILES="/etc/udev/rules.d/70-persistent-{cd,net}.rules" |
| 22 | ENABLE="yes" |
| 23 | ETHx=eth0 |
| 24 | |
| 25 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 26 | |
| 27 | [ -f /etc/default/checkudevrules ] && . /etc/default/checkudevrules |
| 28 | [ "$ENABLE" = "yes" ] || exit 0 |
| 29 | |
| 30 | . /lib/lsb/init-functions |
| 31 | |
| 32 | do_check () { |
| 33 | |
| 34 | log_action_msg "Check if $ETHx exists..." |
| 35 | |
| 36 | if ip link show $ETHx >&/dev/null; then |
| 37 | log_action_msg "Continue booting" |
| 38 | else |
| 39 | log_action_msg "Erase udev rules and reboot" |
| 40 | eval rm -f $FILES |
| 41 | reboot |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | case "$1" in |
| 46 | -v) |
| 47 | echo "$(basename $0), version $VER" |
| 48 | ;; |
| 49 | start) |
| 50 | do_check |
| 51 | ;; |
| 52 | restart|reload|force-reload|stop) |
| 53 | echo "Error: argument '$1' not supported" >&2 |
| 54 | exit 3 |
| 55 | ;; |
| 56 | *) |
| 57 | echo "Usage: $0 start" >&2 |
| 58 | exit 3 |
| 59 | ;; |
| 60 | esac |
| 61 | |
| 62 | # vim:set tabstop=4 expandtab shiftwidth=4: |