systemd-sysv-install 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. # This script is called by "systemctl enable/disable" when the given unit is a
  3. # SysV init.d script. It needs to call the distribution's mechanism for
  4. # enabling/disabling those, such as chkconfig, update-rc.d, or similar. This
  5. # can optionally take a --root argument for enabling a SysV init script
  6. # in a chroot or similar.
  7. set -eu
  8. usage() {
  9. echo "Usage: $0 [--root=path] enable|disable|is-enabled <sysv script name>" >&2
  10. exit 1
  11. }
  12. ROOT=
  13. # parse options
  14. eval set -- "$(getopt -o r: --long root: -- "$@")"
  15. while true; do
  16. case "$1" in
  17. -r|--root)
  18. ROOT="$2"
  19. shift 2 ;;
  20. --) shift ; break ;;
  21. *) usage ;;
  22. esac
  23. done
  24. NAME="${2:-}"
  25. run() {
  26. if [ -n "$ROOT" ] && [ "$ROOT" != "/" ]; then
  27. _SKIP_SYSTEMD_NATIVE=1 chroot "$ROOT" /usr/sbin/update-rc.d "$@"
  28. else
  29. _SKIP_SYSTEMD_NATIVE=1 /usr/sbin/update-rc.d "$@"
  30. fi
  31. }
  32. [ -n "$NAME" ] || usage
  33. case "$1" in
  34. enable)
  35. # call the command to enable SysV init script $NAME here..
  36. run "$NAME" defaults
  37. run "$NAME" enable
  38. ;;
  39. disable)
  40. run "$NAME" defaults
  41. run "$NAME" disable
  42. ;;
  43. is-enabled)
  44. # exit with 0 if $NAME is enabled, non-zero if it is disabled
  45. ls "$ROOT"/etc/rc[S5].d/S??"$NAME" >/dev/null 2>&1
  46. ;;
  47. *)
  48. usage ;;
  49. esac