#!/bin/bash #set -x BASE_PACKAGES=( \ apt-utils dselect \ parted \ openssh-server \ openssh-client \ sudo \ alsa-base \ alsa-utils \ mawk \ tmux \ screen \ #openntpd \ ntp \ wpasupplicant \ wireless-tools \ elinks \ firmware-linux-free \ btrfs-tools \ zsh \ rsync \ git-core \ mlocate \ ) BASE_VALUES="["base_packages"]=${BASE_PACKAGES}" CONFIG_FILE=$2 #arr+=( ["blend_name"]="devuan-live" \ # ["blend_vers"]="2.0" \ # ["mirror"]="http://192.168.44.47:3142/pkgmaster.devuan.org/merged" \ # ["release"]="ascii" ) echo "${BASE_PACKAGES[@]}" #for VALUE in ${BASE_PACKAGES[@]}; do # printf "V: " ${VALUE} #done declare -A arr #arr+=( $1 ) arr+=( ["base_packages"]="${BASE_PACKAGES[@]}" ) for TARGET_KEY in "${!arr[@]}"; do echo "B00 " "${TARGET_KEY}" "${arr["${TARGET_KEY}"]}" "${CONFIG_FILE}" echo "B01 " "${TARGET_KEY}" "${arr["${TARGET_KEY[@]}"]}" "${CONFIG_FILE}" echo "BO2 " '${!arr[@]}' "${!arr[@]}" for VALUE in ${arr["${TARGET_KEY[@]}"]}; do echo "B04 " "${VALUE["${TARGET_KEY}"]}" done # if the key exists if grep -q "^${TARGET_KEY}=" "${CONFIG_FILE}"; then # For each of the values in the list for VALUE in ${arr["${TARGET_KEY[@]}]"}; do # Add the value under the target sed -i "s|^${TARGET_KEY}.*|${TARGET_KEY}=\"${arr[${TARGET_KEY}]}\"|" "${CONFIG_FILE}" done else # Under blend_name add the new key and add the value to it. sed -i "/^blend_name=.*/ s|.*|&\n${TARGET_KEY}=\(\n\)|" "${CONFIG_FILE}" for VALUE in ${arr["${TARGET_KEY[@]}]"}; do sed -i "/^blend_name=.*/ s|.*|&\n${TARGET_KEY}=\"${arr[${TARGET_KEY}]}\"|" "${CONFIG_FILE}" done fi done