File: sysfsutils.init

package info (click to toggle)
sysfsutils 2.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 636 kB
  • sloc: ansic: 7,332; sh: 97; makefile: 54
file content (90 lines) | stat: -rw-r--r-- 2,481 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh

### BEGIN INIT INFO
# Provides:          sysfsconf sysfsutils
# Required-Start:    mountkernfs
# Should-Start:      udev module-init-tools cpufrequtils
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Set sysfs variables from /etc/sysfs.conf
# Description:       Similarly to /etc/init.d/procps.sh, you can configure
#                    values for sysfs variables (such as power management
#                    defaults) and /sys file permissions in /etc/sysfs.conf.
### END INIT INFO

# /etc/init.d/sysfsutils:
#
# (c) 2005 Martin Pitt <mpitt@debian.org>

set -e

CONFFILE=/etc/sysfs.conf
CONFDIR=/etc/sysfs.d

if [ ! -r "$CONFFILE" ] && [ ! -d "$CONFDIR" ]; then
  exit 0
fi

# shellcheck disable=SC1091
. /lib/lsb/init-functions

load_conffile() {
  FILE="$1"

  ( cat "$FILE"; echo ) |
    sed  's/#.*$//; /^[[:space:]]*$/d;
          s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' |
    while read -r f1 f2 f3; do
      if [ "$f1" = "mode" ] && [ -n "$f2" ] && [ -n "$f3" ]; then
        if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then
          chmod "$f3" "/sys/$f2"
        else
          log_failure_msg "unknown attribute $f2"
        fi
      elif [ "$f1" = "owner" ] && [ -n "$f2" ] && [ -n "$f3" ]; then
        if [ -f "/sys/$f2" ]; then
          chown "$f3" "/sys/$f2"
        else
          log_failure_msg "unknown attribute $f2"
        fi
      elif [ "$f1" ] && [ -n "$f2" ] && [ -z "$f3" ]; then
        for path in /sys/$f1; do
          if [ -f "$path" ]; then
            # Some fields need a terminating newline, others need the
            # terminating newline to be absent. :-(
            printf "%s" "$f2" >"$path" 2>/dev/null ||
              echo "$f2" >"$path" 2>/dev/null ||
                log_failure_msg "cannot write value for attribute $f1"
          else
            log_failure_msg "unknown attribute $f1"
          fi
        done
      else
        log_failure_msg "syntax error in $FILE: '$f1' '$f2' '$f3'"
        log_action_end_msg 1
        exit 1
      fi
    done
}

case "$1" in
start|restart|force-reload)
  log_action_begin_msg "Setting sysfs variables..."

  for file in $CONFFILE "$CONFDIR"/*.conf; do
    [ -r "$file" ] || continue
    load_conffile "$file"
  done

  log_action_end_msg 0
  ;;
status)
  ;;
stop)
  ;;
*)
  echo "Usage: /etc/init.d/sysfsutils {start|stop|force-reload|restart|status}"
  exit 1
  ;;
esac