Last active
December 29, 2016 14:26
-
-
Save paunin/a7fad57f78c7dd15a63182c224126cc8 to your computer and use it in GitHub Desktop.
Simple config(.conf or .ini) changer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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