[type/__hosts] Fix when used without --alias

This commit is contained in:
Dennis Camera 2020-07-11 18:57:47 +02:00
parent b8752e9ee3
commit a5ae26116b

View file

@ -19,21 +19,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
set -e -u set -e
hostname=$__object_id hostname=$__object_id
state=$(cat "$__object/parameter/state") state=$(cat "${__object}/parameter/state")
marker="# __hosts/$hostname" marker="# __hosts/${hostname}"
if [ "$state" = 'absent' ] if test "${state}" != 'absent'
then then
set -- --regex "$marker" ip=$(cat "${__object}/parameter/ip")
else if test -s "${__object}/parameter/alias"
ip=$(cat "$__object/parameter/ip") then
aliases=$(while read -r a; do printf '\t%s' "$a"; done <"$__object/parameter/alias") aliases=$(while read -r a; do printf '\t%s' "$a"; done <"$__object/parameter/alias")
fi
set -- --line "$(printf '%s\t%s%s %s' \ set -- --line "$(printf '%s\t%s%s %s' \
"$ip" "$hostname" "$aliases" "$marker")" "${ip}" "${hostname}" "${aliases}" "${marker}")"
else
set -- --regex "$(echo "${marker}" | sed -e 's/\./\\./')$"
fi fi
__line "__hosts/$hostname" --file /etc/hosts --state "$state" "$@" __line "/etc/hosts:${hostname}" --file /etc/hosts --state "${state}" "$@"