OK, I've combined Chad's clean-up and then emitted that as the value, like this:
LISTVAL="$(sed -e "s/\s//g" -e "/^$key:/"'!'d \ -e "s/$key:\[//;s/]//;s/,/, /g" "$file")" RET="$key: [ ${LISTVAL} ]"
In action looks like this:
# Edge-case, single entry root@x1:~# cat /etc/cloud/cloud.cfg.d/90_dpkg.cfg # to update this file, run dpkg-reconfigure cloud-init datasource_list: [ ConfigDrive ] root@x1:~# ./test3.sh /etc/cloud/cloud.cfg.d/90_dpkg.cfg datasource_list: [ ConfigDrive ]
# Edge-case, empty root@x1:~# cat /etc/cloud/cloud.cfg.d/90_dpkg.cfg.empty # to update this file, run dpkg-reconfigure cloud-init datasource_list: [] root@x1:~# ./test3.sh /etc/cloud/cloud.cfg.d/90_dpkg.cfg.empty datasource_list: [ ]
# the bug case root@x1:~# cat /etc/cloud/cloud.cfg.d/90_dpkg.cfg.bad # to update this file, run dpkg-reconfigure cloud-init datasource_list: [ConfigDrive, None] root@x1:~# ./test3.sh /etc/cloud/cloud.cfg.d/90_dpkg.cfg.bad datasource_list: [ ConfigDrive, None ]
# the default case root@x1:~# cat /etc/cloud/cloud.cfg.d/90_dpkg.cfg.new s file, run dpkg-reconfigure cloud-init datasource_list: [ NoCloud, ConfigDrive, OpenNebula, DigitalOcean, Azure, AltCloud, OVF, MAAS, GCE, OpenStack, CloudSigma, SmartOS, Bigstep, Scaleway, AliYun, Ec2, CloudStack, Hetzner, IBMCloud, Oracle, Exoscale, None] root@x1:~# ./test3.sh /etc/cloud/cloud.cfg.d/90_dpkg.cfg.new datasource_list: [ NoCloud, ConfigDrive, OpenNebula, DigitalOcean, Azure, AltCloud, OVF, MAAS, GCE, OpenStack, CloudSigma, SmartOS, Bigstep, Scaleway, AliYun, Ec2, CloudStack, Hetzner, IBMCloud, Oracle, Exoscale, None ]
« Back to merge proposal
OK, I've combined Chad's clean-up and then emitted that as the value, like this:
LISTVAL="$(sed -e "s/\s//g" -e "/^$key:/"'!'d \ \[//;s/ ]//;s/, /, /g" "$file")"
-e "s/$key:
RET="$key: [ ${LISTVAL} ]"
In action looks like this:
# Edge-case, single entry cloud.cfg. d/90_dpkg. cfg cloud.cfg. d/90_dpkg. cfg
root@x1:~# cat /etc/cloud/
# to update this file, run dpkg-reconfigure cloud-init
datasource_list: [ ConfigDrive ]
root@x1:~# ./test3.sh /etc/cloud/
datasource_list: [ ConfigDrive ]
# Edge-case, empty cloud.cfg. d/90_dpkg. cfg.empty cloud.cfg. d/90_dpkg. cfg.empty
root@x1:~# cat /etc/cloud/
# to update this file, run dpkg-reconfigure cloud-init
datasource_list: []
root@x1:~# ./test3.sh /etc/cloud/
datasource_list: [ ]
# the bug case cloud.cfg. d/90_dpkg. cfg.bad cloud.cfg. d/90_dpkg. cfg.bad
root@x1:~# cat /etc/cloud/
# to update this file, run dpkg-reconfigure cloud-init
datasource_list: [ConfigDrive, None]
root@x1:~# ./test3.sh /etc/cloud/
datasource_list: [ ConfigDrive, None ]
# the default case cloud.cfg. d/90_dpkg. cfg.new cloud.cfg. d/90_dpkg. cfg.new
root@x1:~# cat /etc/cloud/
s file, run dpkg-reconfigure cloud-init
datasource_list: [ NoCloud, ConfigDrive, OpenNebula, DigitalOcean, Azure, AltCloud, OVF, MAAS, GCE, OpenStack, CloudSigma, SmartOS, Bigstep, Scaleway, AliYun, Ec2, CloudStack, Hetzner, IBMCloud, Oracle, Exoscale, None]
root@x1:~# ./test3.sh /etc/cloud/
datasource_list: [ NoCloud, ConfigDrive, OpenNebula, DigitalOcean, Azure, AltCloud, OVF, MAAS, GCE, OpenStack, CloudSigma, SmartOS, Bigstep, Scaleway, AliYun, Ec2, CloudStack, Hetzner, IBMCloud, Oracle, Exoscale, None ]