From 26b240729cc7792d5f808de9379b6d6c302f76f7 Mon Sep 17 00:00:00 2001 From: committer Date: Tue, 21 May 2024 07:00:10 -0500 Subject: [PATCH] + nifty scripts used for tux setup. might come in handy here as well. --- scripts/990_comment_add_remove.sh | 37 +++++++++++++++++++++++++++++++ scripts/990_key_value_modifier.sh | 28 +++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 scripts/990_comment_add_remove.sh create mode 100644 scripts/990_key_value_modifier.sh diff --git a/scripts/990_comment_add_remove.sh b/scripts/990_comment_add_remove.sh new file mode 100644 index 0000000..0b7afee --- /dev/null +++ b/scripts/990_comment_add_remove.sh @@ -0,0 +1,37 @@ +#!/usr/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# what: remove a comment from a single line, in a config file +# author: klevstul +# started: mar 2021 +# +# requires: n/a +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +if [ "$EUID" -eq 0 ] + then echo "error: do not run as 'root'" + exit +fi + +this_file_name=`basename "$0"` +if [ $# -ne 4 ]; then + echo "usage: '$this_file_name [{add, remove}] [COMMENT_CHARACTER] [PATTERN] [CONFIG_FILE]'" + exit 1 +fi + +operation=$1 +comment_character=$2 +pattern=$3 +config_file=$4 + +# https://stackoverflow.com/questions/24889346/how-to-uncomment-a-line-that-contains-a-specific-string-using-sed + +# add comment character (comment out) +if [ $operation == "add" ]; then + sed -i "/$pattern/s/^$comment_character*/$comment_character/g" $config_file +fi + +# remove comment character (uncomment) +if [ $operation == "remove" ]; then + sed -i "/$pattern/s/^$comment_character*//g" $config_file +fi diff --git a/scripts/990_key_value_modifier.sh b/scripts/990_key_value_modifier.sh new file mode 100644 index 0000000..e6a4a7a --- /dev/null +++ b/scripts/990_key_value_modifier.sh @@ -0,0 +1,28 @@ +#!/usr/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# what: modify single value in a config file +# author: klevstul +# started: mar 2021 +# +# requires: n/a +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +if [ "$EUID" -eq 0 ] + then echo "error: do not run as 'root'" + exit +fi + +this_file_name=`basename "$0"` +if [ $# -ne 4 ]; then + echo "usage: '$this_file_name [TARGET_KEY] [REPLACEMENT_VALUE] [KEY_VALUE_SEPARATOR] [CONFIG_FILE]'" + exit 1 +fi + +target_key=$1 +replacement_value=$2 +key_value_separator=$3 +config_file=$4 + +# https://stackoverflow.com/questions/2464760/modify-config-file-using-bash-script +sed -i "s/\($target_key*$key_value_separator*\).*/\1$replacement_value/" $config_file