83 lines
2.0 KiB
Bash
Executable File
83 lines
2.0 KiB
Bash
Executable File
#!/bin/sh -e
|
|
#
|
|
# 2020 Dennis Camera (dennis.camera@ssrq-sds-fds.ch)
|
|
#
|
|
# This file is part of cdist.
|
|
#
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# cdist is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
authusers=$(cat "${__object}/explorer/authusers")
|
|
state_should=$(cat "${__object}/parameter/state")
|
|
|
|
if test -f "${__object}/parameter/server"
|
|
then
|
|
server=$(cat "${__object}/parameter/server")
|
|
else
|
|
server=$__object_id
|
|
fi
|
|
login=$(cat "${__object}/parameter/login")
|
|
password=$(cat "${__object}/parameter/password")
|
|
|
|
case $state_should
|
|
in
|
|
(present)
|
|
conf_line=$(printf '%s|%s:%s\n' "${login}" "${server}" "${password}")
|
|
cksum_should=$(echo "${conf_line}" | cksum - | cut -d ' ' -f 1)
|
|
if echo "$authusers" | grep -qxF "${cksum_should}"
|
|
then
|
|
# correct line already present -> nothing to do
|
|
exit 0
|
|
fi
|
|
|
|
mode=1
|
|
;;
|
|
(absent)
|
|
# no logins present -> nothing to do
|
|
test -n "$authusers" || exit 0
|
|
|
|
# NOTE: password is not needed to delete
|
|
conf_line=$(printf '%s|%s:%s\n' "${login}" "${server}" "")
|
|
|
|
mode=0
|
|
;;
|
|
(*)
|
|
printf 'Invalid --state: %s' "${state_should}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
cat <<EOF
|
|
read -r CONF_LINE <<'EOL'
|
|
${conf_line}
|
|
EOL
|
|
export CONF_LINE
|
|
export mode=${mode}
|
|
EOF
|
|
|
|
cat <<'EOF'
|
|
awk -F: -v mode=$mode '
|
|
BEGIN { split(ENVIRON["CONF_LINE"], conf, ":") }
|
|
$1 == conf[1] {
|
|
if (mode && !found) {
|
|
# remove duplicates
|
|
print ENVIRON["CONF_LINE"]
|
|
found = 1
|
|
}
|
|
next
|
|
}
|
|
1' </etc/dma/auth.conf >/etc/dma/auth.conf.tmp \
|
|
&& mv /etc/dma/auth.conf.tmp /etc/dma/auth.conf
|
|
EOF
|