File: sysfsutils.init

package info (click to toggle)
sysfsutils 2.1.0+repack-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,120 kB
  • sloc: sh: 8,685; ansic: 8,035; makefile: 58
file content (82 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download | duplicates (2)
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
#! /bin/sh -e

### BEGIN INIT INFO
# Provides:          sysfsconf
# 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>

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

[ -r "$CONFFILE" -o -d "$CONFDIR" ] || exit 0

. /lib/lsb/init-functions

load_conffile() {
    FILE="$1"
    sed  's/#.*$//; /^[[:space:]]*$/d; 
	  s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' \
	  $FILE | {
	while read f1 f2 f3; do
	    if [ "$f1" = "mode" -a -n "$f2" -a -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" -a -n "$f2" -a -n "$f3" ]; then
		if [ -f "/sys/$f2" ]; then
		    chown "$f3" "/sys/$f2"
		else
		    log_failure_msg "unknown attribute $f2"
		fi
	    elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then
		if [ -f "/sys/$f1" ]; then
		    # Some fields need a terminating newline, others
		    # need the terminating newline to be absent :-(
		     echo -n "$f2" > "/sys/$f1" 2>/dev/null ||
			echo "$f2" > "/sys/$f1"
		else
		    log_failure_msg "unknown attribute $f1"
		fi
	    else
		log_failure_msg "syntax error in $CONFFILE: '$f1' '$f2' '$f3'"
		log_end_msg 1
		exit 1
	    fi
	done
    }
}

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

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

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