Refactor folder structure.
[sim/o1-interface.git] / ntsimulator / deploy / nts-manager / model-install.sh.in
1 #!/bin/bash
2
3 set -eu -o pipefail
4
5 shopt -s failglob
6
7 : ${SYSREPOCTL:=sysrepoctl}
8 : ${SYSREPOCFG:=sysrepocfg}
9 : ${SYSREPOCTL_ROOT_PERMS:=-o root:root -p 600}
10 : ${YANG_DIR:=@CMAKE_CURRENT_SOURCE_DIR@/yang/nts-manager}
11
12 is_yang_module_installed() {
13     module=$1
14
15     $SYSREPOCTL -l | grep --count "^$module [^|]*|[^|]*| Installed .*$" > /dev/null
16 }
17
18 install_yang_module() {
19     module=$1
20
21     if ! is_yang_module_installed $module; then
22         echo "- Installing module $module..."
23         $SYSREPOCTL -i -g ${YANG_DIR}/$module.yang $SYSREPOCTL_ROOT_PERMS
24     else
25         echo "- Module $module already installed."
26     fi
27 }
28
29 uninstall_yang_module() {
30     module=$1
31
32     if is_yang_module_installed $module; then
33         echo "- Uninstalling module $module..."
34         $SYSREPOCTL -u -m $module
35     else
36         echo "- Module $module is not installed."
37     fi
38 }
39
40 enable_yang_module_feature() {
41     module=$1
42     feature=$2
43
44     if ! $SYSREPOCTL -l | grep --count "^$module [^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|.* $feature.*$" > /dev/null; then
45         echo "- Enabling feature $feature in $module..."
46         $SYSREPOCTL -m $module -e $feature
47     else
48         echo "- Feature $feature in $module already enabled."
49     fi
50 }
51
52 echo "- Installing network-topology-simulator..."
53 install_yang_module network-topology-simulator
54
55 echo "- Adding startup datastore in network-topology-simulator..."
56 $SYSREPOCFG -d startup -i $YANG_DIR/network-topology-simulator.xml -f xml network-topology-simulator