Jan Kundrát | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
| 5 | IETF_HW_STATE=0 |
| 6 | YANG_ROADM=0 |
| 7 | YANG_COHERENT=0 |
| 8 | YANG_INLINE=0 |
| 9 | YANG_CALIBRATION=0 |
| 10 | |
| 11 | YANG_DIR=/usr/share/cla-sysrepo/yang |
| 12 | REPO=/etc/sysrepo/yang |
| 13 | |
| 14 | for ARG in $(cat /proc/cmdline); do |
| 15 | case "${ARG}" in |
| 16 | czechlight=*) |
| 17 | CZECHLIGHT="${ARG:11}" |
| 18 | ;; |
| 19 | esac |
| 20 | done |
| 21 | |
| 22 | case "${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 | ;; |
| 44 | esac |
| 45 | |
Tomáš Pecka | c34a545 | 2020-12-16 21:29:09 +0100 | [diff] [blame] | 46 | # 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 |
| 48 | yang-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 | |
| 52 | if [[ ${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át | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 64 | fi |
| 65 | |
| 66 | if [[ ${YANG_ROADM} == 1 && ! -f ${REPO}/czechlight-roadm-device@2019-09-30.yang ]]; then |
Jan Kundrát | cf5dd8a | 2020-11-05 15:59:11 +0100 | [diff] [blame] | 67 | sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-roadm-device@2019-09-30.yang |
Jan Kundrát | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 68 | 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" |
| 73 | fi |
| 74 | |
| 75 | if [[ ${YANG_COHERENT} == 1 && ! -f ${REPO}/czechlight-coherent-add-drop@2019-09-30.yang ]]; then |
Jan Kundrát | cf5dd8a | 2020-11-05 15:59:11 +0100 | [diff] [blame] | 76 | sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-coherent-add-drop@2019-09-30.yang |
Jan Kundrát | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 77 | 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" |
| 79 | fi |
| 80 | |
| 81 | if [[ ${YANG_INLINE} == 1 && ! -f ${REPO}/czechlight-inline-amp@2019-09-30.yang ]]; then |
Jan Kundrát | cf5dd8a | 2020-11-05 15:59:11 +0100 | [diff] [blame] | 82 | sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-inline-amp@2019-09-30.yang |
Jan Kundrát | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 83 | 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" |
| 85 | fi |
| 86 | |
| 87 | if [[ ${YANG_CALIBRATION} == 1 && ! -f ${REPO}/czechlight-calibration-device@2019-06-25.yang ]]; then |
Jan Kundrát | cf5dd8a | 2020-11-05 15:59:11 +0100 | [diff] [blame] | 88 | sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/czechlight-calibration-device@2019-06-25.yang |
Jan Kundrát | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 89 | 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" |
| 91 | fi |
| 92 | |
Jan Kundrát | cf5dd8a | 2020-11-05 15:59:11 +0100 | [diff] [blame] | 93 | if [[ ! -f ${REPO}/czechlight-lldp@2020-11-04.yang ]]; then |
| 94 | if compgen -G "${REPO}/czechlight-lldp@*.yang" >/dev/null; then |
| 95 | sysrepoctl --search-dirs /usr/share/lldp-systemd-networkd-sysrepo/yang --update /usr/share/lldp-systemd-networkd-sysrepo/yang/czechlight-lldp@2020-11-04.yang |
| 96 | else |
| 97 | sysrepoctl --search-dirs /usr/share/lldp-systemd-networkd-sysrepo/yang --install /usr/share/lldp-systemd-networkd-sysrepo/yang/czechlight-lldp@2020-11-04.yang |
| 98 | fi |
Jan Kundrát | 2f100fc | 2020-11-02 22:10:16 +0100 | [diff] [blame] | 99 | sysrepoctl --change czechlight-lldp --permissions 0664 --apply |
| 100 | fi |
| 101 | |
Jan Kundrát | 34d2f48 | 2021-01-11 19:24:09 +0100 | [diff] [blame] | 102 | # If not do not copy here from startup -> running, running might be stale. |
| 103 | sysrepocfg -C startup |