From 145103556041147f91cd52f3722202bae0b16518 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 16 Jan 2020 15:12:43 -0700 Subject: [PATCH] Don't update conkyrc directly * By using a temp file and comparing we can avoid excessive reloading of conky --- .../include_x/airootfs/etc/skel/.update_conky | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/setup/linux/include_x/airootfs/etc/skel/.update_conky b/setup/linux/include_x/airootfs/etc/skel/.update_conky index 0e45e13d..653f90eb 100755 --- a/setup/linux/include_x/airootfs/etc/skel/.update_conky +++ b/setup/linux/include_x/airootfs/etc/skel/.update_conky @@ -1,24 +1,30 @@ #!/bin/bash +# vim: sts=2 sw=2 ts=2 + +CONFIG_BASE="${HOME}/.conkyrc_base" +CONFIG_NEW="${HOME}/.conkyrc_new" +CONFIG_REAL="${HOME}/.conkyrc" IF_LIST=($(ip l \ | egrep '^[0-9]+:\s+(eth|en|wl)' \ | sed -r 's/^[0-9]+:\s+(\w+):.*/\1/' \ | sort)) -# Reset conkyrc to default -rm "${HOME}/.conkyrc" -cp "${HOME}/.conkyrc_base" "${HOME}/.conkyrc" +# Build new config from the default +rm "${CONFIG_NEW}" +cp "${CONFIG_BASE}" "${CONFIG_NEW}" -# Add interfaces to conkyrc +# Add interfaces to conkyrc_new for i in "${IF_LIST[@]}"; do if [[ "${i:0:1}" == "e" ]]; then - sed -i -r "s/#Network/Wired:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc + sed -i -r "s/#Network/Wired:\${alignr}\${addr $i}\n#Network/" "${CONFIG_NEW}" else - sed -i -r "s/#Network/Wireless:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc + sed -i -r "s/#Network/Wireless:\${alignr}\${addr $i}\n#Network/" "${CONFIG_NEW}" fi done -# Remove '#Network' line to prevent duplicating lines if this script is re-run -sed -i -r "s/#Network//" $HOME/.conkyrc - -# vim: sts=2 sw=2 ts=2 +# Replace config if there were changes +if ! diff -q "${CONFIG_NEW}" "${CONFIG_REAL}" >/dev/null 2>&1; then + rm "${CONFIG_REAL}" + cp "${CONFIG_NEW}" "${CONFIG_REAL}" +fi