2016-05-20 14:16:01 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-10-04 06:28:44 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2016-05-24 05:47:00 +00:00
|
|
|
######################################################
|
|
|
|
# @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>
|
|
|
|
######################################################
|
|
|
|
|
2016-05-20 14:16:01 +00:00
|
|
|
# exit on any error
|
|
|
|
set -Ee
|
|
|
|
|
2017-09-26 13:13:35 +00:00
|
|
|
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 " -sm Skip building mimic"
|
|
|
|
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_skipmimic=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} == "-sm" ]] ; then
|
|
|
|
opt_skipmimic=true
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $(id -u) -eq 0 ] && [ "${opt_allowroot}" != true ] ; then
|
2016-05-24 05:47:00 +00:00
|
|
|
echo "This script should not be run as root or with sudo."
|
2017-09-26 13:13:35 +00:00
|
|
|
echo "To force, rerun with --allow-root"
|
2016-05-24 05:47:00 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-09-14 21:10:17 +00:00
|
|
|
found_exe() {
|
|
|
|
hash "$1" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
install_deps() {
|
|
|
|
echo "Installing packages..."
|
|
|
|
if found_exe sudo; then
|
|
|
|
SUDO=sudo
|
|
|
|
fi
|
2017-09-22 08:57:08 +00:00
|
|
|
|
2018-01-05 07:32:35 +00:00
|
|
|
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
|
2018-05-11 20:44:42 +00:00
|
|
|
$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
|
2017-09-14 21:10:17 +00:00
|
|
|
elif found_exe pacman; then
|
2018-04-17 07:18:14 +00:00
|
|
|
$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
|
2018-04-12 16:43:28 +00:00
|
|
|
pacman -Qs "^fann$" &> /dev/null || (
|
|
|
|
git clone https://aur.archlinux.org/fann.git
|
|
|
|
cd fann
|
|
|
|
makepkg -srciA --noconfirm
|
2018-02-03 12:56:46 +00:00
|
|
|
cd ..
|
2018-04-12 16:43:28 +00:00
|
|
|
rm -rf fann
|
2018-02-03 12:56:46 +00:00
|
|
|
)
|
2017-09-14 21:10:17 +00:00
|
|
|
elif found_exe dnf; then
|
2018-06-12 06:33:10 +00:00
|
|
|
$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
|
2017-09-14 21:10:17 +00:00
|
|
|
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"
|
2018-04-17 07:18:14 +00:00
|
|
|
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++"
|
2017-09-14 21:10:17 +00:00
|
|
|
echo $reset
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-02-08 19:49:51 +00:00
|
|
|
TOP=$(cd $(dirname $0) && pwd -L)
|
|
|
|
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${TOP}/.venv"}
|
|
|
|
|
|
|
|
install_venv() {
|
2018-04-27 14:12:17 +00:00
|
|
|
python3 -m venv "${VIRTUALENV_ROOT}/" --without-pip
|
2018-02-09 08:47:11 +00:00
|
|
|
curl https://bootstrap.pypa.io/get-pip.py | "${VIRTUALENV_ROOT}/bin/python"
|
2018-02-08 19:49:51 +00:00
|
|
|
}
|
2018-02-09 08:47:11 +00:00
|
|
|
|
|
|
|
install_deps
|
2017-09-14 22:10:15 +00:00
|
|
|
|
2017-08-02 17:22:40 +00:00
|
|
|
# Configure to use the standard commit template for
|
|
|
|
# this repo only.
|
|
|
|
git config commit.template .gitmessage
|
|
|
|
|
2017-08-03 04:37:25 +00:00
|
|
|
# Check whether to build mimic (it takes a really long time!)
|
|
|
|
build_mimic='y'
|
2017-09-26 13:13:35 +00:00
|
|
|
if [[ ${opt_skipmimic} == true ]] ; then
|
2017-07-05 19:54:05 +00:00
|
|
|
build_mimic='n'
|
2017-08-03 04:37:25 +00:00
|
|
|
else
|
|
|
|
# first, look for a build of mimic in the folder
|
|
|
|
has_mimic=""
|
|
|
|
if [[ -f ${TOP}/mimic/bin/mimic ]] ; then
|
2018-06-01 22:19:09 +00:00
|
|
|
has_mimic=$( ${TOP}/mimic/bin/mimic -lv | grep Voice ) || true
|
2017-08-03 04:37:25 +00:00
|
|
|
fi
|
2017-07-05 19:54:05 +00:00
|
|
|
|
2017-08-03 04:37:25 +00:00
|
|
|
# in not, check the system path
|
|
|
|
if [ "$has_mimic" = "" ] ; then
|
|
|
|
if [ -x "$(command -v mimic)" ]; then
|
2018-06-01 22:19:09 +00:00
|
|
|
has_mimic="$( mimic -lv | grep Voice )" || true
|
2017-08-03 04:37:25 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ "$has_mimic" == "" ] ; then
|
|
|
|
echo "Mimic is installed. Press 'y' to rebuild mimic, any other key to skip."
|
2017-07-05 19:42:19 +00:00
|
|
|
read -n1 build_mimic
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-04-27 14:14:11 +00:00
|
|
|
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ]; then
|
2018-02-08 19:49:51 +00:00
|
|
|
install_venv
|
2016-05-20 14:16:01 +00:00
|
|
|
fi
|
2018-02-08 19:49:51 +00:00
|
|
|
|
|
|
|
# Start the virtual environment
|
2017-06-13 19:50:44 +00:00
|
|
|
source "${VIRTUALENV_ROOT}/bin/activate"
|
|
|
|
cd "${TOP}"
|
2018-02-08 19:49:51 +00:00
|
|
|
|
2018-02-07 18:12:52 +00:00
|
|
|
easy_install pip==9.0.1 # force version of pip
|
2018-02-08 19:49:51 +00:00
|
|
|
|
2018-05-03 10:32:21 +00:00
|
|
|
PYTHON=$( python -c "import sys;print('python{}.{}'.format(sys.version_info[0], sys.version_info[1]))" )
|
2016-05-20 14:16:01 +00:00
|
|
|
|
2017-08-16 01:54:11 +00:00
|
|
|
# Add mycroft-core to the virtualenv path
|
2017-08-16 09:02:39 +00:00
|
|
|
# (This is equivalent to typing 'add2virtualenv $TOP', except
|
|
|
|
# you can't invoke that shell function from inside a script)
|
2018-02-07 20:16:02 +00:00
|
|
|
VENV_PATH_FILE="${VIRTUALENV_ROOT}/lib/$PYTHON/site-packages/_virtualenv_path_extensions.pth"
|
2017-08-17 06:47:28 +00:00
|
|
|
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
|
|
|
|
|
2018-03-30 03:47:30 +00:00
|
|
|
if ! grep -q "$TOP" $VENV_PATH_FILE; then
|
2017-08-16 09:02:39 +00:00
|
|
|
echo "Adding mycroft-core to virtualenv path"
|
|
|
|
sed -i.tmp '1 a\
|
|
|
|
'"$TOP"'
|
2017-08-17 06:47:28 +00:00
|
|
|
' "${VENV_PATH_FILE}"
|
2017-08-16 09:02:39 +00:00
|
|
|
fi
|
|
|
|
|
2018-02-08 19:49:51 +00:00
|
|
|
# install required python modules
|
2017-08-01 19:52:56 +00:00
|
|
|
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
|
2016-05-20 14:16:01 +00:00
|
|
|
|
2018-05-21 13:51:08 +00:00
|
|
|
if ! pip install -r test-requirements.txt; then
|
|
|
|
echo "Warning test requirements wasn't installed, Note: normal operation should still work fine..."
|
|
|
|
fi
|
|
|
|
|
2017-08-04 05:44:05 +00:00
|
|
|
SYSMEM=$(free|awk '/^Mem:/{print $2}')
|
|
|
|
MAXCORES=$(($SYSMEM / 512000))
|
2018-07-16 05:10:04 +00:00
|
|
|
MINCORES=1
|
2017-08-04 05:44:05 +00:00
|
|
|
CORES=$(nproc)
|
|
|
|
|
2018-07-16 05:10:04 +00:00
|
|
|
# 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
|
2017-08-17 08:31:48 +00:00
|
|
|
CORES=${MAXCORES}
|
2017-06-13 19:50:44 +00:00
|
|
|
fi
|
2018-07-16 05:10:04 +00:00
|
|
|
|
2017-06-13 19:50:44 +00:00
|
|
|
echo "Building with $CORES cores."
|
2016-06-20 18:34:36 +00:00
|
|
|
|
2016-07-29 19:50:38 +00:00
|
|
|
#build and install pocketsphinx
|
2016-07-29 19:58:07 +00:00
|
|
|
#cd ${TOP}
|
|
|
|
#${TOP}/scripts/install-pocketsphinx.sh -q
|
|
|
|
#build and install mimic
|
2017-06-13 19:50:44 +00:00
|
|
|
cd "${TOP}"
|
2017-07-05 19:42:19 +00:00
|
|
|
|
2017-08-03 04:37:25 +00:00
|
|
|
if [[ "$build_mimic" == 'y' ]] || [[ "$build_mimic" == 'Y' ]]; then
|
2017-07-05 19:42:19 +00:00
|
|
|
echo "WARNING: The following can take a long time to run!"
|
2017-08-04 05:44:05 +00:00
|
|
|
"${TOP}/scripts/install-mimic.sh" " ${CORES}"
|
2017-07-05 19:42:19 +00:00
|
|
|
else
|
|
|
|
echo "Skipping mimic build."
|
|
|
|
fi
|
2016-06-23 15:29:11 +00:00
|
|
|
|
2017-09-22 08:57:08 +00:00
|
|
|
# set permissions for common scripts
|
|
|
|
chmod +x start-mycroft.sh
|
|
|
|
chmod +x stop-mycroft.sh
|
|
|
|
|
2018-02-08 19:49:51 +00:00
|
|
|
#Store a fingerprint of setup
|
2018-05-22 16:37:17 +00:00
|
|
|
md5sum requirements.txt test-requirements.txt dev_setup.sh > .installed
|