summaryrefslogtreecommitdiff
path: root/nonsystemd/openrc/openrc-hook
blob: edeab050061302364d9d0995c47e993fd084fb2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -e

openrc_live() {
  if [ ! -f /run/openrc/softlevel ]; then
    echo >&2 "  Skipped: Current root is not booted."
    exit 0
  fi
}

reexec_init() {
  local init="$(pacman -Qsq ^init$)"

  if [ $init = openrc-init ]; then
    /usr/bin/openrc-shutdown -R
  elif [ $init = sysvinit ]; then
    /usr/bin/init u
  else
    echo >&2 "  WARNING: Unidentified init."
    exit 0
  fi
}

each_conf() {
  while read -r f; do
    "$@" "/$f"
  done
}

op="$1"; shift

case $op in
  sysctl)   openrc_live; each_conf /usr/bin/sysctl -q -p ;;
  binfmt)   openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
  reexec) openrc_live; reexec_init ;;
    # For use by other packages
  reload)        openrc_live; /usr/bin/rc-service "$@" reload ;;
  *) echo >&2 "  Invalid operation '$op'"; exit 1 ;;
esac

exit 0