+ nifty scripts
used for tux setup. might come in handy here as well.
This commit is contained in:
28
scripts/990_key_value_modifier.sh
Normal file
28
scripts/990_key_value_modifier.sh
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user