Alex Stancu | 29ce368 | 2019-11-02 10:38:59 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Alex Stancu | 0c00182 | 2019-11-13 15:05:10 +0200 | [diff] [blame] | 2 | ################################################################################ |
| 3 | # |
| 4 | # Copyright 2019 highstreet technologies GmbH and others |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | ################################################################################ |
Alex Stancu | 29ce368 | 2019-11-02 10:38:59 +0200 | [diff] [blame] | 18 | |
| 19 | set -eu -o pipefail |
| 20 | |
| 21 | shopt -s failglob |
| 22 | |
| 23 | : ${SYSREPOCTL:=sysrepoctl} |
| 24 | : ${SYSREPOCFG:=sysrepocfg} |
| 25 | : ${SYSREPOCTL_ROOT_PERMS:=-o root:root -p 600} |
| 26 | : ${YANG_DIR:=@CMAKE_CURRENT_SOURCE_DIR@/yang/manager} |
| 27 | : ${STARTUP_DIR:=@CMAKE_CURRENT_SOURCE_DIR@/yang/startup} |
| 28 | |
| 29 | is_yang_module_installed() { |
| 30 | module=$1 |
| 31 | |
| 32 | $SYSREPOCTL -l | grep --count "^$module [^|]*|[^|]*| Installed .*$" > /dev/null |
| 33 | } |
| 34 | |
| 35 | install_yang_module() { |
| 36 | module=$1 |
| 37 | |
| 38 | if ! is_yang_module_installed $module; then |
| 39 | echo "- Installing module $module..." |
| 40 | $SYSREPOCTL -i -g ${YANG_DIR}/$module.yang $SYSREPOCTL_ROOT_PERMS |
| 41 | else |
| 42 | echo "- Module $module already installed." |
| 43 | fi |
| 44 | } |
| 45 | |
| 46 | uninstall_yang_module() { |
| 47 | module=$1 |
| 48 | |
| 49 | if is_yang_module_installed $module; then |
| 50 | echo "- Uninstalling module $module..." |
| 51 | $SYSREPOCTL -u -m $module |
| 52 | else |
| 53 | echo "- Module $module is not installed." |
| 54 | fi |
| 55 | } |
| 56 | |
| 57 | enable_yang_module_feature() { |
| 58 | module=$1 |
| 59 | feature=$2 |
| 60 | |
| 61 | if ! $SYSREPOCTL -l | grep --count "^$module [^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|.* $feature.*$" > /dev/null; then |
| 62 | echo "- Enabling feature $feature in $module..." |
| 63 | $SYSREPOCTL -m $module -e $feature |
| 64 | else |
| 65 | echo "- Feature $feature in $module already enabled." |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | echo "- Installing network-topology-simulator..." |
| 70 | install_yang_module network-topology-simulator |
| 71 | |
| 72 | echo "- Adding startup datastore in network-topology-simulator..." |
| 73 | $SYSREPOCFG -d startup -i $YANG_DIR/network-topology-simulator.xml -f xml network-topology-simulator |