blob: e9693bb7fcaa0514f19b0fbd4c9cc74d793e9b37 [file] [log] [blame]
Václav Kubernát88324812019-06-26 17:36:29 +02001#!/bin/bash
2
3set -eux -o pipefail
4shopt -s failglob
5
6SYSREPOCTL="${1}"
7shift
8if [[ ! -x "${SYSREPOCTL}" ]]; then
9 echo "Cannot locate \$SYSREPOCTL"
10 exit 1
11fi
12
13SYSREPOCFG="${1}"
14shift
15if [[ ! -x "${SYSREPOCFG}" ]]; then
16 echo "Cannot locate \$SYSREPOCFG"
17 exit 1
18fi
19
20MODE="${1}"
21shift
22
23if [[ ! -f "${1}" ]]; then
24 echo "No YANG file specified"
25 exit 1
26fi
27
28MODULE=$(basename --suffix .yang "${1}")
29YANG_DIR=$(dirname "${1}")
30
31if [[ "${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
41elif [[ "${MODE}" == "uninstall" ]]; then
42 ${SYSREPOCTL} --uninstall --module "${MODULE}"
43else
44 echo "Mode of operation not specified"
45 exit 1
46fi