-
Notifications
You must be signed in to change notification settings - Fork 176
/
setup.sh
executable file
·183 lines (158 loc) · 4.51 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#/usr/bin/env bash
show_help() {
echo 'Usage: bash setup.sh [-y] [-a [<filename>]]'
echo ' -y [optional] accept default yes to interactive prompt'
echo ' Setup may require user confirmation when running without'
echo ' virtualenv or as superuser'
echo ' -a [<filename>] An annotation file name to install'
echo ' -r Uninstall annotation file'
}
OPTIND=1
# Initialize our own variables:
default_yes=0
no_db=0
ann_file=''
remove_ann_file=0
while getopts "h?yna:r" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
y) default_yes=1
;;
n) no_db=1
;;
a) ann_file=${OPTARG}
;;
r) remove_ann_file=1
ann_file=''
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
echo "Installing yang-explorer .."
echo "Checking environment .."
command -v pip >/dev/null 2>&1 || {
echo "pip not found.. please install python pip before continuing !!" >&2;
exit -1;
}
command -v virtualenv >/dev/null 2>&1 || {
NOVENV=1
echo ""
echo "WARNING: virtualenv not found !!"
echo "Without virtualenv, required python packages will be installed in system python"
echo "environment and you may require superuser permission."
echo ""
if [[ $default_yes != 1 ]]; then
printf "Do you want to continue? (y/Y) "
read response
if printf "%s\n" "$response" | grep -Eq "$(locale yesexpr)"
then
break;
else
exit -1;
fi
fi
}
if [[ $NOVENV != 1 ]]; then
echo "Creating / Activating virtualenv .."
if [ -f "v/bin/activate" ]; then
source v/bin/activate
else
python_prog=$(type -a python2.7 | head -1 | cut -d" " -f3)
echo "Using Python Program: ${python_prog}"
virtualenv --python=${python_prog} v
source v/bin/activate
fi
fi
echo "Installing dependencies .."
pip install --upgrade pip
pip install -r requirements.txt
cd ../; \
git clone https://github.com/CiscoDevNet/ydk-py.git -b yam; \
cd ydk-py; \
cd core; \
python setup.py sdist; \
pip install dist/ydk*.gz; \
cd ../ietf; \
python setup.py sdist; \
pip install dist/ydk*.gz; \
cd ../openconfig; \
python setup.py sdist; \
pip install dist/ydk*.gz; \
cd ../cisco-ios-xr; \
python setup.py sdist; \
pip install dist/ydk*.gz; \
cd ../../yang-explorer; \
echo "Installing dependencies .. done"
rc=$?
if [[ $rc != 0 ]]; then
echo "Installation failed !! aborted !!"
exit $rc
fi
echo "Setting up initial database .."
if [ -f "server/data/db.sqlite3" ]; then
echo "Database already exist .. skipping"
else
if [[ $UID == 0 ]]; then
echo ""
echo "Warning: Setting up database as root, this is not recommended."
echo "Alternatively you can re-run this script as non-root"
echo "to setup database without root privilege."
echo ""
if [[ $default_yes != 1 ]]; then
printf "Do you want to continue as root ? (n/N) "
read response
if ! printf "%s\n" "$response" | grep -Eq "$(locale yesexpr)"
then
exit 1;
fi
fi
fi
cd server
echo "Creating data directories .."
mkdir -p data/users
mkdir -p data/session
mkdir -p data/collections
mkdir -p data/annotation
if [ ! -d "data/users" ]; then
echo "Failed to create data directories !!"
echo "Setup failed !!"
exit -1
fi
echo "Creating database .."
python manage.py migrate
echo "Creating default users .."
python manage.py setupdb
cd ..
fi
if [ "$ann_file" != "" ] && [ -f $ann_file ]; then
mkdir -p server/data/annotation
cp $ann_file server/data/annotation/
echo "Annotation installed at data/annotation"
elif [[ $remove_ann_file != 0 ]]; then
rm -f server/data/annotation/*.json
echo "Annotation uninstalled from data/annotation"
fi
add_model() {
GUESTPATH=data/users/guest
DEFAULT_YANG=$GUESTPATH/yang/$1.yang
DEFAULT_CXML=$GUESTPATH/cxml/$1.xml
pyang --plugindir explorer/plugins -p $GUESTPATH/yang -f cxml $GUESTPATH/yang/*.yang $DEFAULT_YANG > $DEFAULT_CXML
}
if [ -d "server/data/users/guest/yang" ]; then
count=$(find server/data/users/guest/yang -maxdepth 1 -type f -name '*.yang' | wc -l)
if [ $count -eq 0 ] ; then
echo "Copying default models .."
cp default-models/* server/data/users/guest/yang/
cd server
add_model "ietf-interfaces@2013-12-23"
add_model "ietf-netconf-monitoring@2010-10-04"
cd ..
fi
fi
echo "Setup completed.. "
echo ""
echo "Use start.sh to start yang-explorer server"