blob: 0cd93f31cab7c72544c55734a3c21fa09b169af9 [file] [log] [blame]
Jan Kundrát2f100fc2020-11-02 22:10:16 +01001#!/bin/bash
2
3set -ex
4
5IETF_HW_STATE=0
6YANG_ROADM=0
7YANG_COHERENT=0
8YANG_INLINE=0
9YANG_CALIBRATION=0
10
11YANG_DIR=/usr/share/cla-sysrepo/yang
12REPO=/etc/sysrepo/yang
13
14for ARG in $(cat /proc/cmdline); do
15 case "${ARG}" in
16 czechlight=*)
17 CZECHLIGHT="${ARG:11}"
18 ;;
19 esac
20done
21
22case "${CZECHLIGHT}" in
23 sdn-roadm-line)
24 YANG_ROADM=1
25 WITH_FEATURE=hw-line-9
26 IETF_HW_STATE=1
27 ;;
28 sdn-roadm-add-drop)
29 YANG_ROADM=1
30 WITH_FEATURE=hw-add-drop-20
31 IETF_HW_STATE=1
32 ;;
33 sdn-roadm-coherent-a-d)
34 IETF_HW_STATE=1
35 YANG_COHERENT=1
36 ;;
37 sdn-inline)
38 IETF_HW_STATE=1
39 YANG_INLINE=1
40 ;;
41 calibration-box)
42 YANG_CALIBRATION=1
43 ;;
44esac
45
Tomáš Peckac34a5452020-12-16 21:29:09 +010046# asks ietf-yang-library model in sysrepo for the state of a module given by $1
47# can return "implement", "import" or "" if the module is not present in the tree
48yang-module-state() {
49 sysrepocfg -f xml -X --xpath "/ietf-yang-library:modules-state/module[name='$1']/conformance-type" -d operational | sed -n 's/\s*<conformance-type>\(.*\)<\/conformance-type>/\1/p'
50}
51
52if [[ ${IETF_HW_STATE} == 1 ]]; then
53 # if old model is implemented, remove it first. This uninstall dependent ietf-hardware if imported and not implemented
54 if [[ "$(yang-module-state ietf-hardware-state)" == "implement" ]]; then
55 sysrepoctl -u ietf-hardware-state --apply
56 fi
57
58 # if new model is not implemented
59 if [[ "$(yang-module-state ietf-hardware)" != "implement" ]]; then
60 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/iana-hardware@2018-03-13.yang
61 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/ietf-hardware@2018-03-13.yang
62 sysrepoctl --change ietf-hardware --permissions 0664 --enable-feature hardware-sensor --apply
63 fi
Jan Kundrát2f100fc2020-11-02 22:10:16 +010064fi
65
66if [[ ${YANG_ROADM} == 1 && ! -f ${REPO}/czechlight-roadm-device@2019-09-30.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010067 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-roadm-device@2019-09-30.yang
Jan Kundrát2f100fc2020-11-02 22:10:16 +010068 sysrepoctl --change czechlight-roadm-device --group optics --permissions 0664 --apply
69 if [[ ${WITH_FEATURE} ]]; then
70 sysrepoctl --change czechlight-roadm-device --enable-feature ${WITH_FEATURE}
71 fi
72 sysrepocfg --datastore=startup --format=json --module=czechlight-roadm-device --import="${YANG_DIR}/${CZECHLIGHT}.json"
73fi
74
75if [[ ${YANG_COHERENT} == 1 && ! -f ${REPO}/czechlight-coherent-add-drop@2019-09-30.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010076 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-coherent-add-drop@2019-09-30.yang
Jan Kundrát2f100fc2020-11-02 22:10:16 +010077 sysrepoctl --change czechlight-coherent-add-drop --group optics --permissions 0664 --apply
78 sysrepocfg --datastore=startup --format=json --module=czechlight-coherent-add-drop --new-data="${YANG_DIR}/${CZECHLIGHT}.json"
79fi
80
81if [[ ${YANG_INLINE} == 1 && ! -f ${REPO}/czechlight-inline-amp@2019-09-30.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010082 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-inline-amp@2019-09-30.yang
Jan Kundrát2f100fc2020-11-02 22:10:16 +010083 sysrepoctl --change czechlight-inline-amp --group optics --permissions 0664 --apply
84 sysrepocfg --datastore=startup --format=json --module=czechlight-inline-amp --import="${YANG_DIR}/${CZECHLIGHT}.json"
85fi
86
87if [[ ${YANG_CALIBRATION} == 1 && ! -f ${REPO}/czechlight-calibration-device@2019-06-25.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010088 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-calibration-device@2019-06-25.yang
Jan Kundrát2f100fc2020-11-02 22:10:16 +010089 sysrepoctl --change czechlight-calibration-device --group optics --permissions 0664 --apply
90 sysrepocfg --datastore=startup --format=json --module=czechlight-calibration-device --import="${YANG_DIR}/${CZECHLIGHT}.json"
91fi
92
Tomáš Pecka01df8482021-01-13 18:04:19 +010093if [[ ! -f ${REPO}/ietf-system@2014-08-06.yang ]]; then
94 sysrepoctl --search-dirs /usr/share/velia/yang --install /usr/share/velia/yang/ietf-system@2014-08-06.yang
95 sysrepoctl --change ietf-system --permissions 0664 --apply
96fi
97
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010098if [[ ! -f ${REPO}/czechlight-lldp@2020-11-04.yang ]]; then
99 if compgen -G "${REPO}/czechlight-lldp@*.yang" >/dev/null; then
100 sysrepoctl --search-dirs /usr/share/lldp-systemd-networkd-sysrepo/yang --update /usr/share/lldp-systemd-networkd-sysrepo/yang/czechlight-lldp@2020-11-04.yang
101 else
102 sysrepoctl --search-dirs /usr/share/lldp-systemd-networkd-sysrepo/yang --install /usr/share/lldp-systemd-networkd-sysrepo/yang/czechlight-lldp@2020-11-04.yang
103 fi
Jan Kundrát2f100fc2020-11-02 22:10:16 +0100104 sysrepoctl --change czechlight-lldp --permissions 0664 --apply
105fi
106
Jan Kundrát34d2f482021-01-11 19:24:09 +0100107# If not do not copy here from startup -> running, running might be stale.
108sysrepocfg -C startup