Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -eux -o pipefail |
| 4 | shopt -s failglob |
| 5 | |
| 6 | SYSREPOCTL="${1}" |
| 7 | shift |
| 8 | if [[ ! -x "${SYSREPOCTL}" ]]; then |
| 9 | echo "Cannot locate \$SYSREPOCTL" |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
| 13 | SYSREPOCFG="${1}" |
| 14 | shift |
| 15 | if [[ ! -x "${SYSREPOCFG}" ]]; then |
| 16 | echo "Cannot locate \$SYSREPOCFG" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | MODE="${1}" |
| 21 | shift |
| 22 | |
| 23 | if [[ ! -f "${1}" ]]; then |
| 24 | echo "No YANG file specified" |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | MODULE=$(basename --suffix .yang "${1}") |
| 29 | YANG_DIR=$(dirname "${1}") |
| 30 | |
| 31 | if [[ "${MODE}" == "install" ]]; then |
| 32 | ${SYSREPOCTL} --uninstall --module "${MODULE}" || true |
| 33 | ${SYSREPOCTL} --install --yang "${1}" |
| 34 | JSON_DATA="${YANG_DIR}/${MODULE}.json" |
| 35 | XML_DATA="${YANG_DIR}/${MODULE}.startup.xml" |
| 36 | if [[ -f "${JSON_DATA}" ]] ;then |
| 37 | ${SYSREPOCFG} -d startup -f json "${MODULE}" -i "${JSON_DATA}" |
| 38 | elif [[ -f "${XML_DATA}" ]]; then |
| 39 | ${SYSREPOCFG} -d startup -f xml "${MODULE}" -i "${XML_DATA}" |
| 40 | fi |
| 41 | elif [[ "${MODE}" == "uninstall" ]]; then |
| 42 | ${SYSREPOCTL} --uninstall --module "${MODULE}" |
| 43 | else |
| 44 | echo "Mode of operation not specified" |
| 45 | exit 1 |
| 46 | fi |