Jan Kundrát | 91d1172 | 2020-10-14 18:09:55 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 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 |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame^] | 32 | ${SYSREPOCTL} -C |
| 33 | ${SYSREPOCTL} --uninstall "${MODULE}" -a || true |
| 34 | ${SYSREPOCTL} -C |
| 35 | ${SYSREPOCTL} --search-dirs "${YANG_DIR}" --install "${1}" -a |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 36 | JSON_DATA="${YANG_DIR}/${MODULE}.json" |
| 37 | XML_DATA="${YANG_DIR}/${MODULE}.startup.xml" |
| 38 | if [[ -f "${JSON_DATA}" ]] ;then |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame^] | 39 | ${SYSREPOCFG} -d startup -f json "${MODULE}" -i "${JSON_DATA}" -a |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 40 | elif [[ -f "${XML_DATA}" ]]; then |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame^] | 41 | ${SYSREPOCFG} -d startup -f xml "${MODULE}" -i "${XML_DATA}" -a |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 42 | fi |
| 43 | elif [[ "${MODE}" == "uninstall" ]]; then |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame^] | 44 | ${SYSREPOCTL} --uninstall "${MODULE}" -a |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 45 | else |
| 46 | echo "Mode of operation not specified" |
| 47 | exit 1 |
| 48 | fi |