From e264fb004f797efc540f74191a0e9630c66dd819 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sun, 25 Oct 2020 11:27:07 +0100 Subject: [PATCH] [type/__uci] Convert to immediate remote execution --- cdist/conf/type/__uci/files/functions.sh | 6 +- cdist/conf/type/__uci/gencode-local | 102 ----------------------- cdist/conf/type/__uci/gencode-remote | 8 -- 3 files changed, 2 insertions(+), 114 deletions(-) delete mode 100755 cdist/conf/type/__uci/gencode-local mode change 100644 => 100755 cdist/conf/type/__uci/gencode-remote diff --git a/cdist/conf/type/__uci/files/functions.sh b/cdist/conf/type/__uci/files/functions.sh index 4ddb82e0..277f648c 100644 --- a/cdist/conf/type/__uci/files/functions.sh +++ b/cdist/conf/type/__uci/files/functions.sh @@ -24,10 +24,8 @@ quote() { uci_cmd() { # Usage: uci_cmd [UCI ARGUMENTS]... - # Will output a shell command to be executed locally to add the given - # command to $tmpfile. - printf "printf '%%s\\\\n' %s" "$(quote "$(quote "$@")")" - printf ' >>%s\n' "$(quote "${tmpfile}")" + mkdir -p "${__object:?}/files" + printf '%s\n' "$(quote "$@")" >>"${__object:?}/files/uci_batch.txt" } uci_validate_name() { diff --git a/cdist/conf/type/__uci/gencode-local b/cdist/conf/type/__uci/gencode-local deleted file mode 100755 index b7664e85..00000000 --- a/cdist/conf/type/__uci/gencode-local +++ /dev/null @@ -1,102 +0,0 @@ -#!/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 . -# - -state_is=$(cat "${__object:?}/explorer/state") -state_should=$(cat "${__object:?}/parameter/state") - -transaction_name=$(cat "${__object:?}/parameter/transaction") - -tmpdir="${__global:?}/tmp/__uci" -# HACK -mkdir -p "${tmpdir}" - -tmpfile="${tmpdir}/${transaction_name}.txt" - -# shellcheck source=files/functions.sh -. "${__type:?}/files/functions.sh" - - -config=${__object_id:?} -uci_validate_tuple "${config}" - - -case ${state_should} -in - (present) - if in_list "${state_is}" 'present' 'rearranged' - then - # NOTE: order is ignored so rearranged is also fine. - exit 0 - fi - - # Determine type - type=$(cat "${__object:?}/parameter/type" 2>/dev/null || true) - case ${type} - in - (option|list) ;; - ('') - # Guess type by the number of values - test "$(wc -l "${__object:?}/parameter/value")" -gt 1 \ - && type=list \ - || type=option - ;; - (*) - printf 'Invalid --type: %s\n' "${type}" >&2 - exit 1 - ;; - esac - - case ${type} - in - (list) - printf 'set_list %s\n' "${config}" >>"${__messages_out:?}" - - if test "${state_is}" != 'absent' - then - uci_cmd delete "${config}" - fi - - while read -r value - do - uci_cmd add_list "${config}"="${value}" - done <"${__object:?}/parameter/value" - ;; - (option) - printf 'set %s\n' "${config}" >>"${__messages_out:?}" - - value=$(cat "${__object:?}/parameter/value") - uci_cmd set "${config}"="${value}" - ;; - esac - ;; - (absent) - if in_list "${state_is}" 'absent' - then - exit 0 - fi - - printf 'delete %s\n' "${config}" >>"${__messages_out:?}" - uci_cmd delete "${config}" - ;; - (*) - printf 'Invalid --state: %s\n' "${state_should}" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__uci/gencode-remote b/cdist/conf/type/__uci/gencode-remote old mode 100644 new mode 100755 index 348d15a1..a15f50a6 --- a/cdist/conf/type/__uci/gencode-remote +++ b/cdist/conf/type/__uci/gencode-remote @@ -91,11 +91,3 @@ in exit 1 ;; esac - -if test -s "${__object:?}/files/uci_batch.txt" -then - cat "${__type:?}/files/uci_apply.sh" - printf "uci_apply <<'EOF'\n" - cat "${__object:?}/files/uci_batch.txt" - printf '\nEOF\n' -fi