]> git.ipfire.org Git - people/ms/network.git/blob - functions.sysctl
hostapd: Enable WMM by default.
[people/ms/network.git] / functions.sysctl
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 SYSCTL_PATH="/proc/sys"
23
24 function sysctl_key_to_path() {
25 local key="${1}"
26 assert isset key
27
28 print "${SYSCTL_PATH}/${key//.//}"
29
30 return ${EXIT_OK}
31 }
32
33 function sysctl_key_exists() {
34 local key="${1}"
35 assert isset key
36
37 local path="$(sysctl_key_to_path "${key}")"
38
39 [ -e "${path}" ] && return ${EXIT_OK}
40 return ${EXIT_ERROR}
41 }
42
43 function sysctl_get() {
44 local key="${1}"
45 assert isset key
46
47 fread "$(sysctl_key_to_path "${key}")" || return $?
48 return ${EXIT_OK}
49 }
50
51 function sysctl_set() {
52 local key="${1}"
53 assert isset key
54
55 local value="${2}"
56
57 fwrite "$(sysctl_key_to_path "${key}")" "${value}" || return $?
58 return ${EXIT_OK}
59 }
60
61 function sysctl_set_bool() {
62 local key="${1}"
63
64 local value="${2}"
65 if enabled value; then
66 value="1"
67 else
68 value="0"
69 fi
70
71 sysctl_set "${key}" "${value}"
72 }
73
74 function sysctl_set_recursively() {
75 local basekey="${1}"
76 assert isset basekey
77
78 local subkey="${2}"
79 assert isset subkey
80
81 local value="${3}"
82
83 local basepath="$(sysctl_key_to_path "${basekey}")"
84 local subpath="/${subkey//\.//}"
85
86 local path
87 for path in $(find "${basepath}" -type f); do
88 [[ ${path} =~ ${subpath}$ ]] || continue
89
90 fwrite "${path}" "${value}"
91 done
92
93 return ${EXIT_OK}
94 }