blob: 4ab9cf0443baf19757bf969e0701921b32b7eff7 [file] [log] [blame]
Alex Stancu29ce3682019-11-02 10:38:59 +02001#!/bin/bash
Alex Stancu0c001822019-11-13 15:05:10 +02002################################################################################
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 Stancu29ce3682019-11-02 10:38:59 +020018
19set -eu -o pipefail
20
21shopt -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
29is_yang_module_installed() {
30 module=$1
31
32 $SYSREPOCTL -l | grep --count "^$module [^|]*|[^|]*| Installed .*$" > /dev/null
33}
34
35install_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
46uninstall_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
57enable_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
69echo "- Installing network-topology-simulator..."
70install_yang_module network-topology-simulator
71
72echo "- Adding startup datastore in network-topology-simulator..."
73$SYSREPOCFG -d startup -i $YANG_DIR/network-topology-simulator.xml -f xml network-topology-simulator