#!/bin/bash

# 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.
set -eu

NAME=${1:-}
VALUE=${2:-}
# Optional comment used to describe the setting
COMMENT=${3:-"This file is managed via the TripleO sysctl image element."}

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

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

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