]>
Commit | Line | Data |
---|---|---|
ef953be2 | 1 | #!/bin/bash |
15a5f44d MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
ef953be2 | 5 | # Copyright (C) 2013 IPFire Network Development Team # |
15a5f44d MT |
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 | ||
ef953be2 MT |
22 | SYSCTL_PATH="/proc/sys" |
23 | ||
1c6a4e30 | 24 | sysctl_key_to_path() { |
ef953be2 MT |
25 | local key="${1}" |
26 | assert isset key | |
27 | ||
28 | print "${SYSCTL_PATH}/${key//.//}" | |
29 | ||
30 | return ${EXIT_OK} | |
31 | } | |
32 | ||
1c6a4e30 | 33 | sysctl_key_exists() { |
ef953be2 MT |
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 | ||
1c6a4e30 | 43 | sysctl_get() { |
ef953be2 MT |
44 | local key="${1}" |
45 | assert isset key | |
46 | ||
47 | fread "$(sysctl_key_to_path "${key}")" || return $? | |
48 | return ${EXIT_OK} | |
49 | } | |
50 | ||
1c6a4e30 | 51 | sysctl_set() { |
ef953be2 MT |
52 | local key="${1}" |
53 | assert isset key | |
54 | ||
55 | local value="${2}" | |
56 | ||
644d3bb8 | 57 | fappend "$(sysctl_key_to_path "${key}")" "${value}" || return $? |
ef953be2 MT |
58 | return ${EXIT_OK} |
59 | } | |
60 | ||
1c6a4e30 | 61 | sysctl_set_bool() { |
ef953be2 MT |
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 | ||
1c6a4e30 | 74 | sysctl_set_recursively() { |
ef953be2 MT |
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 | ||
644d3bb8 | 90 | fappend "${path}" "${value}" |
ef953be2 MT |
91 | done |
92 | ||
93 | return ${EXIT_OK} | |
94 | } |