File: sysctl-write-value

package info (click to toggle)
python-diskimage-builder 3.37.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,572 kB
  • sloc: sh: 7,380; python: 6,444; makefile: 37
file content (43 lines) | stat: -rwxr-xr-x 995 bytes parent folder | download | duplicates (5)
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
#!/bin/bash
#
# Copied from tripleo-image-element's sysctl element
#
# Validate and manage setting sysctl settings.
#
# The script is called with name/value pairs which are stored
# in the system default sysctl.d directory. This script performs
# no checking, just writing out the file.

if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail

NAME=${1:-}
VALUE=${2:-}
# Optional comment used to describe the setting
COMMENT=${3:-"This file was created by diskimage-builder."}

if [ -z "$NAME" -o -z "$VALUE" ]; then
    echo "Usage: sysctl-write-value <name> <value> [comment]"
    exit 1
fi

FILENAME="/etc/sysctl.d/${NAME}.conf"

if [ -f $FILENAME ]; then
    # check to make sure the settings match... otherwise fail
    if ! grep -q "^$NAME = $VALUE" $FILENAME; then
        echo "Conflicting sysctl.conf setting for $NAME == $VALUE. Found:"
        grep "^$NAME" $FILENAME
        exit 1
    fi
else

cat > $FILENAME <<EOF_CAT
# $COMMENT
$NAME = $VALUE
EOF_CAT

fi