2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2015-05-12 17:12:49 +00:00
|
|
|
#
|
|
|
|
# 2015 Dominique Roux (dominique.roux4 at gmail.com)
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
2015-05-12 12:26:38 +00:00
|
|
|
#get params
|
|
|
|
section=$(cat "$__object/parameter/section")
|
|
|
|
key=$(cat "$__object/parameter/key")
|
|
|
|
value=$(cat "$__object/parameter/value")
|
2015-05-12 17:12:49 +00:00
|
|
|
file=$(cat "$__object/parameter/file" 2>/dev/null)
|
|
|
|
state=$(cat "$__object/parameter/state" 2>/dev/null)
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
#path variable default /etc/pacman.d
|
|
|
|
sec_path="/etc/pacman.d"
|
|
|
|
|
|
|
|
#allowed keys (from man pacman.conf)
|
2015-05-12 17:12:49 +00:00
|
|
|
allowed_option_keys="RootDir DBPath CacheDir GPGDir LogFile HoldPkg IgnorePkg IgnoreGroup Include Architecture XferCommand NoUpgrade NoExtract CleanMethod SigLevel LocalFileSigLevel RemoteFileSigLevel"
|
|
|
|
boolean_option_keys="UseSyslog Color UseDelta TotalDownload CheckSpace VerbosePkgLists"
|
|
|
|
allowed_repo_keys="Include Server SigLevel Usage"
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
#set global variables
|
2015-05-12 17:12:49 +00:00
|
|
|
MATCH=0
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
#function for check if array contain string
|
|
|
|
contains_element() {
|
|
|
|
|
2015-05-12 17:12:49 +00:00
|
|
|
MATCH=0
|
|
|
|
|
|
|
|
target=$1
|
2016-03-30 10:43:59 +00:00
|
|
|
shift
|
2015-05-12 12:26:38 +00:00
|
|
|
|
2016-03-30 10:43:59 +00:00
|
|
|
for key in "$@"; do
|
|
|
|
if [ "${key}" = "${target}" ]; then
|
2015-05-12 17:12:49 +00:00
|
|
|
MATCH=1
|
2015-05-12 12:26:38 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
2015-05-12 17:12:49 +00:00
|
|
|
MATCH=0
|
2015-05-12 12:26:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 06:18:33 +00:00
|
|
|
if [ "${file}" ]; then
|
2015-05-12 12:26:38 +00:00
|
|
|
__file "${sec_path}/plain_file_${file}"\
|
|
|
|
--state exists --mode 666
|
|
|
|
|
2016-03-30 10:43:59 +00:00
|
|
|
if [ "${state}" = "present" ]; then
|
2015-05-12 12:26:38 +00:00
|
|
|
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/plain_file_${file}" __key_value "${file}_${key}" \
|
|
|
|
--file "${sec_path}/plain_file_${file}" --key "${key}" --value "${value}" --delimiter ' = '
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
2016-03-30 10:43:59 +00:00
|
|
|
elif [ "${state}" = "absent" ]; then
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/plain_file_${file}" __key_value "${file}_${key}" \
|
2015-05-12 12:26:38 +00:00
|
|
|
--state absent
|
2015-05-13 11:28:48 +00:00
|
|
|
exit 0
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
else
|
2015-05-12 17:12:49 +00:00
|
|
|
echo "ERROR: Unknown state: ${state}" >&2
|
2015-05-13 11:12:25 +00:00
|
|
|
exit 0
|
2015-05-12 12:26:38 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-03-30 10:43:59 +00:00
|
|
|
if [ "${section}" = "options" ]; then
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
__file "${sec_path}/${section}"\
|
|
|
|
--state exists --mode 666 --source - << eof
|
|
|
|
[${section}]
|
|
|
|
eof
|
|
|
|
#check if key is valid
|
|
|
|
#check for boolean value
|
2015-05-12 17:12:49 +00:00
|
|
|
contains_element "${key}" "${boolean_option_keys}"
|
2015-05-12 12:26:38 +00:00
|
|
|
|
2015-05-12 17:12:49 +00:00
|
|
|
if [ "${MATCH}" -eq 1 ]; then
|
2016-03-30 10:43:59 +00:00
|
|
|
if [ "${value}" = "on" ]; then
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/${section}" __line "${key}_${value}" \
|
|
|
|
--file "${sec_path}/${section}" --line "${key}"
|
2016-03-30 10:43:59 +00:00
|
|
|
elif [ "${value}" = "off" ]; then
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/${section}" __line "${key}_${value}" \
|
|
|
|
--file "${sec_path}/${section}" --line "${key}" --state absent
|
2015-05-12 12:26:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
2015-05-12 17:12:49 +00:00
|
|
|
contains_element "${key}" "${allowed_option_keys}"
|
2015-05-12 12:26:38 +00:00
|
|
|
|
2015-05-12 17:12:49 +00:00
|
|
|
if [ "${MATCH}" -eq 1 ]; then
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/${section}" __key_value "${section}_${key}" \
|
|
|
|
--file "${sec_path}/${section}" --key "${key}" --value "${value}" --delimiter ' = '
|
2015-05-12 12:26:38 +00:00
|
|
|
else
|
2015-05-12 17:12:49 +00:00
|
|
|
echo "Key: ${key} is not valid. Have a look at man pacman.conf" >&2
|
2015-05-12 12:26:38 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
__file "${sec_path}/repo_${section}"\
|
|
|
|
--state exists --mode 666 --source - << eof
|
|
|
|
[${section}]
|
|
|
|
eof
|
2016-03-30 10:43:59 +00:00
|
|
|
if [ "${state}" = "present" ]; then
|
2015-05-12 12:26:38 +00:00
|
|
|
|
|
|
|
#check if key is valid
|
2015-05-12 17:12:49 +00:00
|
|
|
contains_element "${key}" "${allowed_repo_keys}"
|
|
|
|
if [ ${MATCH} -eq 0 ]; then
|
2015-05-12 12:26:38 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/repo_${section}" __key_value "${section}_${key}" \
|
|
|
|
--file "${sec_path}/repo_${section}" --key "${key}" --value "${value}" --delimiter ' = '
|
2015-05-12 12:26:38 +00:00
|
|
|
|
2016-03-30 10:43:59 +00:00
|
|
|
elif [ "${state}" = "absent" ]; then
|
2015-05-12 12:26:38 +00:00
|
|
|
|
2018-10-02 19:44:27 +00:00
|
|
|
require="__file/${sec_path}/repo_${section}" __key_value "${section}_${key}" \
|
2015-05-12 12:26:38 +00:00
|
|
|
--state absent
|
|
|
|
|
|
|
|
else
|
2015-05-12 17:12:49 +00:00
|
|
|
echo "ERROR: Unknown state: ${state}" >&2
|
2015-05-12 12:26:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|