forked from MycroftAI/mycroft-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_setup.sh
More file actions
executable file
·274 lines (235 loc) · 9.31 KB
/
dev_setup.sh
File metadata and controls
executable file
·274 lines (235 loc) · 9.31 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/usr/bin/env bash
# Copyright 2017 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
######################################################
# @author sean.fitzgerald (aka clusterfudge)
#
# The purpose of this script is to create a self-
# contained development environment using
# virtualenv for python dependency sandboxing.
# This script will create a virtualenv (using the
# conventions set by virtualenv-wrapper for
# location and naming) and install the requirements
# laid out in requirements.txt, pocketsphinx, and
# pygtk into the virtualenv. Mimic will be
# installed and built from source inside the local
# checkout.
#
# The goal of this script is to create a development
# environment in user space that is fully functional.
# It is expected (and even encouraged) for a developer
# to work on multiple projects concurrently, and a
# good OSS citizen respects that and does not pollute
# a developers workspace with it's own dependencies
# (as much as possible).
# </endRant>
######################################################
# exit on any error
set -Ee
cd $(dirname $0)
TOP=$( pwd -L )
function show_help() {
echo "dev_setup.sh: Mycroft development environment setup"
echo "Usage: dev_setup.sh [options]"
echo
echo "Options:"
echo " -r, --allow-root Allow to be run as root (e.g. sudo)"
echo " -fm Force mimic build"
echo " -h, --help Show this message"
echo
echo "This will prepare your environment for running the mycroft-core"
echo "services. Normally this should be run as a normal user,"
echo "not as root/sudo."
}
opt_forcemimicbuild=false
opt_allowroot=false
for var in "$@" ; do
if [[ ${var} == "-h" ]] || [[ ${var} == "--help" ]] ; then
show_help
exit 0
fi
if [[ ${var} == "-r" ]] || [[ ${var} == "--allow-root" ]] ; then
opt_allowroot=true
fi
if [[ ${var} == "-fm" ]] ; then
opt_forcemimicbuild=true
fi
done
if [ $(id -u) -eq 0 ] && [ "${opt_allowroot}" != true ] ; then
echo "This script should not be run as root or with sudo."
echo "To force, rerun with --allow-root"
exit 1
fi
# TODO: Create a setup wizard that guides the user through some decisions
# if [ ! -f .dev_opts.json ] ; then
# E.g.:
# * Run on 'master' or on 'dev'? Most users probably want 'master'
# * Auto-update? When on, it will pull and run dev_setup automatically
# * Pull down mimic source? Most will be happy with just the package
# * Add mycroft-core/bin to the .bashrc PATH?
# from Picroft's wizard:
# echo '{"use_branch":"master", "auto_update": true}' > .dev_opts.json
# or
# echo '{"use_branch":"dev", "auto_update": false}' > .dev_opts.json
# fi
function found_exe() {
hash "$1" 2>/dev/null
}
function install_deps() {
echo "Installing packages..."
if found_exe sudo ; then
SUDO=sudo
fi
if found_exe zypper ; then
$SUDO zypper install -y git python glibc-devel linux-glibc-devel python-devel python2-virtualenv python2-gobject-devel python-virtualenvwrapper libtool libffi-devel libopenssl-devel autoconf automake bison swig glib2-devel portaudio-devel mpg123 flac curl libicu-devel pkg-config pkg-config libjpeg-devel libfann-devel python-curses
$SUDO zypper install -y -t pattern devel_C_C++
elif found_exe apt-get ; then
$SUDO apt-get install -y git python3 python3-dev python-setuptools python-gobject-2-dev libtool libffi-dev libssl-dev autoconf automake bison swig libglib2.0-dev portaudio19-dev mpg123 screen flac curl libicu-dev pkg-config automake libjpeg-dev libfann-dev build-essential jq
elif found_exe pacman; then
$SUDO pacman -S --needed --noconfirm git python2 python2-pip python2-setuptools python2-virtualenv python2-gobject python-virtualenvwrapper libtool libffi openssl autoconf bison swig glib2 portaudio mpg123 screen flac curl pkg-config icu automake libjpeg-turbo base-devel jq
pacman -Qs "^fann$" &> /dev/null || (
git clone https://aur.archlinux.org/fann.git
cd fann
makepkg -srciA --noconfirm
cd ..
rm -rf fann
)
elif found_exe dnf ; then
$SUDO dnf install -y git python3 python3-devel python3-pip python3-setuptools python3-virtualenv pygobject3-devel libtool libffi-devel openssl-devel autoconf bison swig glib2-devel portaudio-devel mpg123 mpg123-plugins-pulseaudio screen curl pkgconfig libicu-devel automake libjpeg-turbo-devel fann-devel gcc-c++ redhat-rpm-config jq
else
if found_exe tput ; then
green="$(tput setaf 2)"
blue="$(tput setaf 4)"
reset="$(tput sgr0)"
fi
echo
echo "${green}Could not find package manager"
echo "${green}Make sure to manually install:${blue} git python 2 python-setuptools python-virtualenv pygobject virtualenvwrapper libtool libffi openssl autoconf bison swig glib2.0 portaudio19 mpg123 flac curl fann g++"
echo $reset
fi
}
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${TOP}/.venv"}
function install_venv() {
python3 -m venv "${VIRTUALENV_ROOT}/" --without-pip
curl https://bootstrap.pypa.io/get-pip.py | "${VIRTUALENV_ROOT}/bin/python"
}
install_deps
# Configure to use the standard commit template for
# this repo only.
git config commit.template .gitmessage
# Check whether to build mimic (it takes a really long time!)
build_mimic="n"
if [[ ${opt_forcemimicbuild} == true ]] ; then
build_mimic="y"
else
# first, look for a build of mimic in the folder
has_mimic=""
if [[ -f ${TOP}/mimic/bin/mimic ]] ; then
has_mimic=$( ${TOP}/mimic/bin/mimic -lv | grep Voice ) || true
fi
# in not, check the system path
if [ "$has_mimic" == "" ] ; then
if [ -x "$(command -v mimic)" ] ; then
has_mimic="$( mimic -lv | grep Voice )" || true
fi
fi
if [ "$has_mimic" == "" ]; then
build_mimic="y"
fi
fi
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ] ; then
install_venv
fi
# Start the virtual environment
source "${VIRTUALENV_ROOT}/bin/activate"
cd "${TOP}"
# Force version of pip for reproducability, but there is nothing special
# about this version. Update whenever a new version is released and
# verified functional.
easy_install pip==18.0
PYTHON=$( python -c "import sys;print('python{}.{}'.format(sys.version_info[0], sys.version_info[1]))" )
# Add mycroft-core to the virtualenv path
# (This is equivalent to typing 'add2virtualenv $TOP', except
# you can't invoke that shell function from inside a script)
VENV_PATH_FILE="${VIRTUALENV_ROOT}/lib/$PYTHON/site-packages/_virtualenv_path_extensions.pth"
if [ ! -f "$VENV_PATH_FILE" ] ; then
echo "import sys; sys.__plen = len(sys.path)" > "$VENV_PATH_FILE" || return 1
echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$VENV_PATH_FILE" || return 1
fi
if ! grep -q "$TOP" $VENV_PATH_FILE ; then
echo "Adding mycroft-core to virtualenv path"
sed -i.tmp '1 a\
'"$TOP"'
' "${VENV_PATH_FILE}"
fi
# install required python modules
if ! pip install -r requirements.txt ; then
echo "Warning: Failed to install all requirements. Continue? y/N"
read -n1 continue
if [[ "$continue" != "y" ]] ; then
exit 1
fi
fi
if ! pip install -r test-requirements.txt ; then
echo "Warning test requirements wasn't installed, Note: normal operation should still work fine..."
fi
SYSMEM=$( free | awk '/^Mem:/ { print $2 }' )
MAXCORES=$(($SYSMEM / 512000))
MINCORES=1
CORES=$( nproc )
# ensure MAXCORES is > 0
if [[ ${MAXCORES} -lt 1 ]] ; then
MAXCORES=${MINCORES}
fi
# look for positive integer
if ! [[ ${CORES} =~ ^[0-9]+$ ]] ; then
CORES=${MINCORES}
elif [[ ${MAXCORES} -lt ${CORES} ]] ; then
CORES=${MAXCORES}
fi
echo "Building with $CORES cores."
#build and install pocketsphinx
#cd ${TOP}
#${TOP}/scripts/install-pocketsphinx.sh -q
#build and install mimic
cd "${TOP}"
if [[ "$build_mimic" == "y" ]] || [[ "$build_mimic" == "Y" ]] ; then
echo "WARNING: The following can take a long time to run!"
"${TOP}/scripts/install-mimic.sh" " ${CORES}"
else
echo "Skipping mimic build."
fi
# set permissions for common scripts
chmod +x start-mycroft.sh
chmod +x stop-mycroft.sh
chmod +x bin/mycroft-cli-client
chmod +x bin/mycroft-help
chmod +x bin/mycroft-mic-test
chmod +x bin/mycroft-msk
chmod +x bin/mycroft-msm
chmod +x bin/mycroft-pip
chmod +x bin/mycroft-say-to
chmod +x bin/mycroft-skill-testrunner
chmod +x bin/mycroft-speak
# create and set permissions for logging
if [[ ! -w /var/log/mycroft/ ]] ; then
# Creating and setting permissions
echo "Creating /var/log/mycroft/ directory"
if [[ ! -d /var/log/mycroft/ ]] ; then
sudo mkdir /var/log/mycroft/
fi
sudo chmod 777 /var/log/mycroft/
fi
#Store a fingerprint of setup
md5sum requirements.txt test-requirements.txt dev_setup.sh > .installed