Skip to content

Instantly share code, notes, and snippets.

@paunin
Last active December 29, 2016 14:26
Show Gist options
  • Save paunin/a7fad57f78c7dd15a63182c224126cc8 to your computer and use it in GitHub Desktop.
Save paunin/a7fad57f78c7dd15a63182c224126cc8 to your computer and use it in GitHub Desktop.
Simple config(.conf or .ini) changer
#CONFIGS= #in format variable1:value1[,variable2:value2[,...]]
#CONFIG_FILE= #path to file
echo "
#------------------------------------------------------------------------------
# AUTOGENERATED
#------------------------------------------------------------------------------
" >> $CONFIG_FILE
echo ">>> Configuring $CONFIG_FILE"
IFS=',' read -ra CONFIG_PAIRS <<< "$CONFIGS"
for CONFIG_PAIR in "${CONFIG_PAIRS[@]}"
do
IFS=':' read -ra CONFIG <<< "$CONFIG_PAIR"
VAR="${CONFIG[0]}"
VAL="${CONFIG[1]}"
sed -e "s/\(^\ *$VAR\(.*\)$\)/#\1 # overrided in AUTOGENERATED section/g" $CONFIG_FILE > /tmp/config.tmp && mv -f /tmp/config.tmp $CONFIG_FILE
echo ">>>>>> Adding config '$VAR' with value '$VAL' "
echo "$VAR = $VAL" >> $CONFIG_FILE
done
echo ">>>>>> Result config file"
#cat $CONFIG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment