blob: f0d26fa8334a5b5b536af66add1fe8031216568c [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
Jan Kundrát811c0b02021-02-05 19:16:43 +010022INITIAL_DATA=${CZECHLIGHT%%-g2}
23
Jan Kundrát2f100fc2020-11-02 22:10:16 +010024case "${CZECHLIGHT}" in
Jan Kundrát811c0b02021-02-05 19:16:43 +010025 sdn-roadm-line*)
Jan Kundrát2f100fc2020-11-02 22:10:16 +010026 YANG_ROADM=1
27 WITH_FEATURE=hw-line-9
28 IETF_HW_STATE=1
29 ;;
Jan Kundrát811c0b02021-02-05 19:16:43 +010030 sdn-roadm-add-drop*)
Jan Kundrát2f100fc2020-11-02 22:10:16 +010031 YANG_ROADM=1
32 WITH_FEATURE=hw-add-drop-20
33 IETF_HW_STATE=1
34 ;;
Jan Kundrát811c0b02021-02-05 19:16:43 +010035 sdn-roadm-hires-add-drop*)
36 YANG_ROADM=1
37 WITH_FEATURE=hw-add-drop-20
38 IETF_HW_STATE=1
39 INITIAL_DATA=sdn-roadm-add-drop
40 ;;
41 sdn-roadm-coherent-a-d*)
Jan Kundrát2f100fc2020-11-02 22:10:16 +010042 IETF_HW_STATE=1
43 YANG_COHERENT=1
44 ;;
Jan Kundrát811c0b02021-02-05 19:16:43 +010045 sdn-inline*)
Jan Kundrát2f100fc2020-11-02 22:10:16 +010046 IETF_HW_STATE=1
47 YANG_INLINE=1
48 ;;
49 calibration-box)
50 YANG_CALIBRATION=1
51 ;;
52esac
53
Tomáš Peckac34a5452020-12-16 21:29:09 +010054# asks ietf-yang-library model in sysrepo for the state of a module given by $1
55# can return "implement", "import" or "" if the module is not present in the tree
56yang-module-state() {
57 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'
58}
59
60if [[ ${IETF_HW_STATE} == 1 ]]; then
61 # if old model is implemented, remove it first. This uninstall dependent ietf-hardware if imported and not implemented
62 if [[ "$(yang-module-state ietf-hardware-state)" == "implement" ]]; then
63 sysrepoctl -u ietf-hardware-state --apply
64 fi
65
66 # if new model is not implemented
67 if [[ "$(yang-module-state ietf-hardware)" != "implement" ]]; then
68 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/iana-hardware@2018-03-13.yang
69 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/ietf-hardware@2018-03-13.yang
70 sysrepoctl --change ietf-hardware --permissions 0664 --enable-feature hardware-sensor --apply
71 fi
Jan Kundrát2f100fc2020-11-02 22:10:16 +010072fi
73
74if [[ ${YANG_ROADM} == 1 && ! -f ${REPO}/czechlight-roadm-device@2019-09-30.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010075 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-roadm-device@2019-09-30.yang
Jan Kundrát2f100fc2020-11-02 22:10:16 +010076 sysrepoctl --change czechlight-roadm-device --group optics --permissions 0664 --apply
77 if [[ ${WITH_FEATURE} ]]; then
78 sysrepoctl --change czechlight-roadm-device --enable-feature ${WITH_FEATURE}
79 fi
Jan Kundrát811c0b02021-02-05 19:16:43 +010080 sysrepocfg --datastore=startup --format=json --module=czechlight-roadm-device --import="${YANG_DIR}/${INITIAL_DATA}.json"
Jan Kundrát2f100fc2020-11-02 22:10:16 +010081fi
82
83if [[ ${YANG_COHERENT} == 1 && ! -f ${REPO}/czechlight-coherent-add-drop@2019-09-30.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010084 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-coherent-add-drop@2019-09-30.yang
Jan Kundrát811c0b02021-02-05 19:16:43 +010085 sysrepocfg --datastore=startup --format=json --module=czechlight-coherent-add-drop --new-data="${YANG_DIR}/${INITIAL_DATA}.json"
Jan Kundrát00876bd2021-01-29 19:51:59 +010086 sysrepoctl --change czechlight-coherent-add-drop --group optics --permissions 0664 --apply
Jan Kundrát2f100fc2020-11-02 22:10:16 +010087fi
88
89if [[ ${YANG_INLINE} == 1 && ! -f ${REPO}/czechlight-inline-amp@2019-09-30.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010090 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-inline-amp@2019-09-30.yang
Jan Kundrát811c0b02021-02-05 19:16:43 +010091 sysrepocfg --datastore=startup --format=json --module=czechlight-inline-amp --import="${YANG_DIR}/${INITIAL_DATA}.json"
Jan Kundrát00876bd2021-01-29 19:51:59 +010092 sysrepoctl --change czechlight-inline-amp --group optics --permissions 0664 --apply
Jan Kundrát2f100fc2020-11-02 22:10:16 +010093fi
94
95if [[ ${YANG_CALIBRATION} == 1 && ! -f ${REPO}/czechlight-calibration-device@2019-06-25.yang ]]; then
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +010096 sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-calibration-device@2019-06-25.yang
Jan Kundrát811c0b02021-02-05 19:16:43 +010097 sysrepocfg --datastore=startup --format=json --module=czechlight-calibration-device --import="${YANG_DIR}/${INITIAL_DATA}.json"
Jan Kundrát00876bd2021-01-29 19:51:59 +010098 sysrepoctl --change czechlight-calibration-device --group optics --permissions 0664 --apply
Jan Kundrát2f100fc2020-11-02 22:10:16 +010099fi
100
Tomáš Pecka01df8482021-01-13 18:04:19 +0100101if [[ ! -f ${REPO}/ietf-system@2014-08-06.yang ]]; then
Jan Kundrát77c1cb12021-01-25 12:16:27 +0100102 sysrepoctl --search-dirs /usr/share/velia/yang --install /usr/share/velia/yang/ietf-system@2014-08-06.yang
Tomáš Pecka01df8482021-01-13 18:04:19 +0100103 sysrepoctl --change ietf-system --permissions 0664 --apply
104fi
105
Jan Kundrátcf5dd8a2020-11-05 15:59:11 +0100106if [[ ! -f ${REPO}/czechlight-lldp@2020-11-04.yang ]]; then
107 if compgen -G "${REPO}/czechlight-lldp@*.yang" >/dev/null; then
108 sysrepoctl --search-dirs /usr/share/lldp-systemd-networkd-sysrepo/yang --update /usr/share/lldp-systemd-networkd-sysrepo/yang/czechlight-lldp@2020-11-04.yang
109 else
110 sysrepoctl --search-dirs /usr/share/lldp-systemd-networkd-sysrepo/yang --install /usr/share/lldp-systemd-networkd-sysrepo/yang/czechlight-lldp@2020-11-04.yang
111 fi
Jan Kundrát2f100fc2020-11-02 22:10:16 +0100112 sysrepoctl --change czechlight-lldp --permissions 0664 --apply
113fi
114
Tomáš Pecka25aae682021-01-27 14:45:57 +0100115if [[ ! -f ${REPO}/czechlight-system@2021-01-13.yang ]]; then
116 sysrepoctl --search-dirs /usr/share/velia/yang --install /usr/share/velia/yang/czechlight-system@2021-01-13.yang
117 sysrepoctl --change czechlight-system --permissions 0664 --apply
118fi
119
Jan Kundrát34d2f482021-01-11 19:24:09 +0100120# If not do not copy here from startup -> running, running might be stale.
121sysrepocfg -C startup