blob: b618fec2d24cedcf8cd2bb63b613c1d695aa1558 [file] [log] [blame]
Jan Kundrát91d11722020-10-14 18:09:55 +02001#!/usr/bin/env bash
Václav Kubernát88324812019-06-26 17:36:29 +02002
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
Václav Kubernát654303f2020-07-31 13:16:54 +020032 ${SYSREPOCTL} -C
33 ${SYSREPOCTL} --uninstall "${MODULE}" -a || true
34 ${SYSREPOCTL} -C
35 ${SYSREPOCTL} --search-dirs "${YANG_DIR}" --install "${1}" -a
Václav Kubernát88324812019-06-26 17:36:29 +020036 JSON_DATA="${YANG_DIR}/${MODULE}.json"
37 XML_DATA="${YANG_DIR}/${MODULE}.startup.xml"
38 if [[ -f "${JSON_DATA}" ]] ;then
Václav Kubernát654303f2020-07-31 13:16:54 +020039 ${SYSREPOCFG} -d startup -f json "${MODULE}" -i "${JSON_DATA}" -a
Václav Kubernát88324812019-06-26 17:36:29 +020040 elif [[ -f "${XML_DATA}" ]]; then
Václav Kubernát654303f2020-07-31 13:16:54 +020041 ${SYSREPOCFG} -d startup -f xml "${MODULE}" -i "${XML_DATA}" -a
Václav Kubernát88324812019-06-26 17:36:29 +020042 fi
43elif [[ "${MODE}" == "uninstall" ]]; then
Václav Kubernát654303f2020-07-31 13:16:54 +020044 ${SYSREPOCTL} --uninstall "${MODULE}" -a
Václav Kubernát88324812019-06-26 17:36:29 +020045else
46 echo "Mode of operation not specified"
47 exit 1
48fi