Standardize shell scripts (#1711)
* Standardize shebangs * Standardize spaces * Standardize functions declaration * Standardize conditional constructs * Standardize double quotes * Standardize command substitution * Standardize sed commandpull/1712/head
parent
e482254172
commit
ed556b09df
125
dev_setup.sh
125
dev_setup.sh
|
@ -41,25 +41,24 @@
|
||||||
# exit on any error
|
# exit on any error
|
||||||
set -Ee
|
set -Ee
|
||||||
|
|
||||||
show_help() {
|
function show_help() {
|
||||||
echo "dev_setup.sh: Mycroft development environment setup"
|
echo "dev_setup.sh: Mycroft development environment setup"
|
||||||
echo "Usage: dev_setup.sh [options]"
|
echo "Usage: dev_setup.sh [options]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -r, --allow-root Allow to be run as root (e.g. sudo)"
|
echo " -r, --allow-root Allow to be run as root (e.g. sudo)"
|
||||||
echo " -sm Skip building mimic"
|
echo " -sm Skip building mimic"
|
||||||
echo " -h, --help Show this message"
|
echo " -h, --help Show this message"
|
||||||
echo
|
echo
|
||||||
echo "This will prepare your environment for running the mycroft-core"
|
echo "This will prepare your environment for running the mycroft-core"
|
||||||
echo "services. Normally this should be run as a normal user,"
|
echo "services. Normally this should be run as a normal user,"
|
||||||
echo "not as root/sudo."
|
echo "not as root/sudo."
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_skipmimic=false
|
opt_skipmimic=false
|
||||||
opt_allowroot=false
|
opt_allowroot=false
|
||||||
|
|
||||||
for var in "$@"
|
for var in "$@" ; do
|
||||||
do
|
|
||||||
if [[ ${var} == "-h" ]] || [[ ${var} == "--help" ]] ; then
|
if [[ ${var} == "-h" ]] || [[ ${var} == "--help" ]] ; then
|
||||||
show_help
|
show_help
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -75,25 +74,25 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $(id -u) -eq 0 ] && [ "${opt_allowroot}" != true ] ; then
|
if [ $(id -u) -eq 0 ] && [ "${opt_allowroot}" != true ] ; then
|
||||||
echo "This script should not be run as root or with sudo."
|
echo "This script should not be run as root or with sudo."
|
||||||
echo "To force, rerun with --allow-root"
|
echo "To force, rerun with --allow-root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
found_exe() {
|
function found_exe() {
|
||||||
hash "$1" 2>/dev/null
|
hash "$1" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
install_deps() {
|
function install_deps() {
|
||||||
echo "Installing packages..."
|
echo "Installing packages..."
|
||||||
if found_exe sudo; then
|
if found_exe sudo ; then
|
||||||
SUDO=sudo
|
SUDO=sudo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if found_exe zypper; then
|
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 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++
|
$SUDO zypper install -y -t pattern devel_C_C++
|
||||||
elif found_exe apt-get; then
|
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
|
$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
|
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
|
$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
|
||||||
|
@ -104,10 +103,10 @@ install_deps() {
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf fann
|
rm -rf fann
|
||||||
)
|
)
|
||||||
elif found_exe dnf; then
|
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
|
$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
|
else
|
||||||
if found_exe tput; then
|
if found_exe tput ; then
|
||||||
green="$(tput setaf 2)"
|
green="$(tput setaf 2)"
|
||||||
blue="$(tput setaf 4)"
|
blue="$(tput setaf 4)"
|
||||||
reset="$(tput sgr0)"
|
reset="$(tput sgr0)"
|
||||||
|
@ -119,10 +118,10 @@ install_deps() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
TOP=$(cd $(dirname $0) && pwd -L)
|
TOP=$( cd $( dirname $0 ) && pwd -L )
|
||||||
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${TOP}/.venv"}
|
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${TOP}/.venv"}
|
||||||
|
|
||||||
install_venv() {
|
function install_venv() {
|
||||||
python3 -m venv "${VIRTUALENV_ROOT}/" --without-pip
|
python3 -m venv "${VIRTUALENV_ROOT}/" --without-pip
|
||||||
curl https://bootstrap.pypa.io/get-pip.py | "${VIRTUALENV_ROOT}/bin/python"
|
curl https://bootstrap.pypa.io/get-pip.py | "${VIRTUALENV_ROOT}/bin/python"
|
||||||
}
|
}
|
||||||
|
@ -134,31 +133,31 @@ install_deps
|
||||||
git config commit.template .gitmessage
|
git config commit.template .gitmessage
|
||||||
|
|
||||||
# Check whether to build mimic (it takes a really long time!)
|
# Check whether to build mimic (it takes a really long time!)
|
||||||
build_mimic='y'
|
build_mimic="y"
|
||||||
if [[ ${opt_skipmimic} == true ]] ; then
|
if [[ ${opt_skipmimic} == true ]] ; then
|
||||||
build_mimic='n'
|
build_mimic="n"
|
||||||
else
|
else
|
||||||
# first, look for a build of mimic in the folder
|
# first, look for a build of mimic in the folder
|
||||||
has_mimic=""
|
has_mimic=""
|
||||||
if [[ -f ${TOP}/mimic/bin/mimic ]] ; then
|
if [[ -f ${TOP}/mimic/bin/mimic ]] ; then
|
||||||
has_mimic=$( ${TOP}/mimic/bin/mimic -lv | grep Voice ) || true
|
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
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [ "$has_mimic" == "" ] ; then
|
# in not, check the system path
|
||||||
echo "Mimic is installed. Press 'y' to rebuild mimic, any other key to skip."
|
if [ "$has_mimic" == "" ] ; then
|
||||||
read -n1 build_mimic
|
if [ -x "$(command -v mimic)" ] ; then
|
||||||
fi
|
has_mimic="$( mimic -lv | grep Voice )" || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [ "$has_mimic" == "" ] ; then
|
||||||
|
echo "Mimic is installed. Press 'y' to rebuild mimic, any other key to skip."
|
||||||
|
read -n1 build_mimic
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ]; then
|
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ] ; then
|
||||||
install_venv
|
install_venv
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the virtual environment
|
# Start the virtual environment
|
||||||
|
@ -178,15 +177,15 @@ if [ ! -f "$VENV_PATH_FILE" ] ; then
|
||||||
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
|
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
|
fi
|
||||||
|
|
||||||
if ! grep -q "$TOP" $VENV_PATH_FILE; then
|
if ! grep -q "$TOP" $VENV_PATH_FILE ; then
|
||||||
echo "Adding mycroft-core to virtualenv path"
|
echo "Adding mycroft-core to virtualenv path"
|
||||||
sed -i.tmp '1 a\
|
sed -i.tmp '1 a\
|
||||||
'"$TOP"'
|
'"$TOP"'
|
||||||
' "${VENV_PATH_FILE}"
|
' "${VENV_PATH_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install required python modules
|
# install required python modules
|
||||||
if ! pip install -r requirements.txt; then
|
if ! pip install -r requirements.txt ; then
|
||||||
echo "Warning: Failed to install all requirements. Continue? y/N"
|
echo "Warning: Failed to install all requirements. Continue? y/N"
|
||||||
read -n1 continue
|
read -n1 continue
|
||||||
if [[ "$continue" != "y" ]] ; then
|
if [[ "$continue" != "y" ]] ; then
|
||||||
|
@ -194,25 +193,25 @@ if ! pip install -r requirements.txt; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! pip install -r test-requirements.txt; then
|
if ! pip install -r test-requirements.txt ; then
|
||||||
echo "Warning test requirements wasn't installed, Note: normal operation should still work fine..."
|
echo "Warning test requirements wasn't installed, Note: normal operation should still work fine..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SYSMEM=$(free|awk '/^Mem:/{print $2}')
|
SYSMEM=$( free | awk '/^Mem:/ { print $2 }' )
|
||||||
MAXCORES=$(($SYSMEM / 512000))
|
MAXCORES=$(($SYSMEM / 512000))
|
||||||
MINCORES=1
|
MINCORES=1
|
||||||
CORES=$(nproc)
|
CORES=$( nproc )
|
||||||
|
|
||||||
# ensure MAXCORES is > 0
|
# ensure MAXCORES is > 0
|
||||||
if [[ ${MAXCORES} -lt 1 ]]; then
|
if [[ ${MAXCORES} -lt 1 ]] ; then
|
||||||
MAXCORES=${MINCORES}
|
MAXCORES=${MINCORES}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# look for positive integer
|
# look for positive integer
|
||||||
if ! [[ ${CORES} =~ ^[0-9]+$ ]]; then
|
if ! [[ ${CORES} =~ ^[0-9]+$ ]] ; then
|
||||||
CORES=${MINCORES}
|
CORES=${MINCORES}
|
||||||
elif [[ ${MAXCORES} -lt ${CORES} ]]; then
|
elif [[ ${MAXCORES} -lt ${CORES} ]] ; then
|
||||||
CORES=${MAXCORES}
|
CORES=${MAXCORES}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Building with $CORES cores."
|
echo "Building with $CORES cores."
|
||||||
|
@ -223,11 +222,11 @@ echo "Building with $CORES cores."
|
||||||
#build and install mimic
|
#build and install mimic
|
||||||
cd "${TOP}"
|
cd "${TOP}"
|
||||||
|
|
||||||
if [[ "$build_mimic" == 'y' ]] || [[ "$build_mimic" == 'Y' ]]; then
|
if [[ "$build_mimic" == "y" ]] || [[ "$build_mimic" == "Y" ]] ; then
|
||||||
echo "WARNING: The following can take a long time to run!"
|
echo "WARNING: The following can take a long time to run!"
|
||||||
"${TOP}/scripts/install-mimic.sh" " ${CORES}"
|
"${TOP}/scripts/install-mimic.sh" " ${CORES}"
|
||||||
else
|
else
|
||||||
echo "Skipping mimic build."
|
echo "Skipping mimic build."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set permissions for common scripts
|
# set permissions for common scripts
|
||||||
|
|
|
@ -26,7 +26,7 @@ pkg-config --exists icu-i18n || export CFLAGS="$CFLAGS -I/usr/include/x86_64-lin
|
||||||
pkg-config --exists icu-i18n || export LDFLAGS="$LDFLAGS -licui18n -licuuc -licudata"
|
pkg-config --exists icu-i18n || export LDFLAGS="$LDFLAGS -licui18n -licuuc -licudata"
|
||||||
|
|
||||||
# download and install mimic
|
# download and install mimic
|
||||||
if [ ! -d ${MIMIC_DIR} ]; then
|
if [ ! -d ${MIMIC_DIR} ] ; then
|
||||||
git clone --branch ${MIMIC_VERSION} https://github.com/MycroftAI/mimic.git --depth=1
|
git clone --branch ${MIMIC_VERSION} https://github.com/MycroftAI/mimic.git --depth=1
|
||||||
cd ${MIMIC_DIR}
|
cd ${MIMIC_DIR}
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
|
|
|
@ -20,49 +20,47 @@ set -Ee
|
||||||
#TOP="."
|
#TOP="."
|
||||||
|
|
||||||
|
|
||||||
function enable_local {
|
function enable_local() {
|
||||||
sed -i -- 's/from pocketsphinx.pocketsphinx import Decoder/from pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
sed -i 's/from pocketsphinx.pocketsphinx import Decoder/from pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
||||||
}
|
}
|
||||||
|
|
||||||
function disable_local {
|
function disable_local() {
|
||||||
sed -i -- 's/from pocketsphinx import Decoder/from pocketsphinx.pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
sed -i 's/from pocketsphinx import Decoder/from pocketsphinx.pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
||||||
|
|
||||||
}
|
|
||||||
function install_pocketsphinx {
|
|
||||||
# clone pocketsphinx-python at HEAD (fix to a constant version later)
|
|
||||||
if [ ! -d ${TOP}/pocketsphinx-python ]; then
|
|
||||||
# build sphinxbase and pocketsphinx if we haven't already
|
|
||||||
git clone --recursive https://github.com/cmusphinx/pocketsphinx-python
|
|
||||||
pushd ./pocketsphinx-python/sphinxbase
|
|
||||||
./autogen.sh
|
|
||||||
./configure
|
|
||||||
make -j$CORES
|
|
||||||
popd
|
|
||||||
pushd ./pocketsphinx-python/pocketsphinx
|
|
||||||
./autogen.sh
|
|
||||||
./configure
|
|
||||||
make -j$CORES
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
|
|
||||||
# build and install pocketsphinx python bindings
|
|
||||||
cd ${TOP}/pocketsphinx-python
|
|
||||||
python setup.py install
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" = "-q" ]; then
|
function install_pocketsphinx() {
|
||||||
enable_local
|
# clone pocketsphinx-python at HEAD (fix to a constant version later)
|
||||||
install_pocketsphinx
|
if [ ! -d ${TOP}/pocketsphinx-python ] ; then
|
||||||
exit 0
|
# build sphinxbase and pocketsphinx if we haven't already
|
||||||
|
git clone --recursive https://github.com/cmusphinx/pocketsphinx-python
|
||||||
|
pushd ./pocketsphinx-python/sphinxbase
|
||||||
|
./autogen.sh
|
||||||
|
./configure
|
||||||
|
make -j$CORES
|
||||||
|
popd
|
||||||
|
pushd ./pocketsphinx-python/pocketsphinx
|
||||||
|
./autogen.sh
|
||||||
|
./configure
|
||||||
|
make -j$CORES
|
||||||
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# build and install pocketsphinx python bindings
|
||||||
|
cd ${TOP}/pocketsphinx-python
|
||||||
|
python setup.py install
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "-q" ] ; then
|
||||||
|
enable_local
|
||||||
|
install_pocketsphinx
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "This script will checkout, compile, and install pocketsphinx locally if the debian package python-pocketsphinx is not available"
|
echo "This script will checkout, compile, and install pocketsphinx locally if the debian package python-pocketsphinx is not available"
|
||||||
|
|
||||||
PS3='Please enter your choice: '
|
PS3='Please enter your choice: '
|
||||||
options=("Enable local checkout, compile and install" "Disable local checkout and exit" "Do nothing and quit")
|
options=("Enable local checkout, compile and install" "Disable local checkout and exit" "Do nothing and quit")
|
||||||
select opt in "${options[@]}"
|
select opt in "${options[@]}" ; do
|
||||||
do
|
|
||||||
case $opt in
|
case $opt in
|
||||||
"Enable local checkout, compile and install")
|
"Enable local checkout, compile and install")
|
||||||
echo "you chose choice 1"
|
echo "you chose choice 1"
|
||||||
|
@ -78,7 +76,8 @@ do
|
||||||
echo "you chose choice 3"
|
echo "you chose choice 3"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*) echo invalid option;;
|
*)
|
||||||
|
echo invalid option
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Ensure we're in a virtualenv.
|
# Ensure we're in a virtualenv.
|
||||||
if [ "$VIRTUAL_ENV" == "" ]
|
if [ "$VIRTUAL_ENV" == "" ] ; then
|
||||||
then
|
|
||||||
echo "ERROR: not in a virtual environment."
|
echo "ERROR: not in a virtual environment."
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
@ -34,8 +33,7 @@ python -c "
|
||||||
try: import cairo; raise SystemExit(0)
|
try: import cairo; raise SystemExit(0)
|
||||||
except ImportError: raise SystemExit(-1)"
|
except ImportError: raise SystemExit(-1)"
|
||||||
|
|
||||||
if [ $? == 255 ]
|
if [ $? == 255 ] ; then
|
||||||
then
|
|
||||||
echo -e "\E[1m * Installing cairo...\E[0m"
|
echo -e "\E[1m * Installing cairo...\E[0m"
|
||||||
# Fetch, build, and install py2cairo.
|
# Fetch, build, and install py2cairo.
|
||||||
( cd $CACHE
|
( cd $CACHE
|
||||||
|
@ -56,8 +54,7 @@ python -c "
|
||||||
try: import gobject; raise SystemExit(0)
|
try: import gobject; raise SystemExit(0)
|
||||||
except ImportError: raise SystemExit(-1)"
|
except ImportError: raise SystemExit(-1)"
|
||||||
|
|
||||||
if [ $? == 255 ]
|
if [ $? == 255 ] ; then
|
||||||
then
|
|
||||||
echo -e "\E[1m * Installing gobject...\E[0m"
|
echo -e "\E[1m * Installing gobject...\E[0m"
|
||||||
# Fetch, build, and install gobject.
|
# Fetch, build, and install gobject.
|
||||||
( cd $CACHE
|
( cd $CACHE
|
||||||
|
@ -77,8 +74,7 @@ python -c "
|
||||||
try: import gtk; raise SystemExit(0)
|
try: import gtk; raise SystemExit(0)
|
||||||
except ImportError: raise SystemExit(-1)" 2&> /dev/null
|
except ImportError: raise SystemExit(-1)" 2&> /dev/null
|
||||||
|
|
||||||
if [ $? == 255 ]
|
if [ $? == 255 ] ; then
|
||||||
then
|
|
||||||
echo -e "\E[1m * Installing gtk...\E[0m"
|
echo -e "\E[1m * Installing gtk...\E[0m"
|
||||||
# Fetch, build, and install gtk.
|
# Fetch, build, and install gtk.
|
||||||
( cd $CACHE
|
( cd $CACHE
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2017 Mycroft AI Inc.
|
# Copyright 2017 Mycroft AI Inc.
|
||||||
#
|
#
|
||||||
|
@ -14,21 +14,21 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Verify and present the user with information about their installation of mycroft.
|
# Verify and present the user with information about their installation of mycroft.
|
||||||
# Should be run as the mycroft user.
|
# Should be run as the mycroft user.
|
||||||
#
|
#
|
||||||
# To do: functionalize and allow for parametereized calls of each.
|
# To do: functionalize and allow for parametereized calls of each.
|
||||||
# rs 2017-05-05
|
# rs 2017-05-05
|
||||||
|
|
||||||
helpfunc() {
|
function helpfunc() {
|
||||||
echo "Usage: ${0} [FUNCTION]"
|
echo "Usage: ${0} [FUNCTION]"
|
||||||
echo " Functions include
|
echo " Functions include
|
||||||
-v version
|
-v version
|
||||||
-P python
|
-P python
|
||||||
-p permissions
|
-p permissions
|
||||||
-i internet
|
-i internet
|
||||||
-s system info
|
-s system info
|
||||||
-u audio
|
-u audio
|
||||||
-r running
|
-r running
|
||||||
-m mimic
|
-m mimic
|
||||||
-a run all checks
|
-a run all checks
|
||||||
|
@ -39,9 +39,9 @@ if [[ $# -eq 0 ]] ; then
|
||||||
helpfunc && exit 1
|
helpfunc && exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MYCROFT_HOME=''
|
MYCROFT_HOME=""
|
||||||
RUN_AS_ROOT=1
|
RUN_AS_ROOT=1
|
||||||
source $(locate virtualenvwrapper.sh)
|
source $( locate virtualenvwrapper.sh )
|
||||||
|
|
||||||
# log stuff and things
|
# log stuff and things
|
||||||
LOG_FILE=/tmp/my-info.$$.out
|
LOG_FILE=/tmp/my-info.$$.out
|
||||||
|
@ -55,14 +55,14 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# it's big, it's heavy, it's wood!
|
# it's big, it's heavy, it's wood!
|
||||||
mlog() {
|
function mlog() {
|
||||||
local timestamp="[$(date +"%Y-%m-%d %H:%M:%S")]"
|
local timestamp="[$( date +"%Y-%m-%d %H:%M:%S" )]"
|
||||||
message="$*"
|
message="$*"
|
||||||
echo "${timestamp} ${message}" |tee -a ${LOG_FILE}
|
echo "${timestamp} ${message}" |tee -a ${LOG_FILE}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sup big perm.
|
# Sup big perm.
|
||||||
checkperms () {
|
function checkperms() {
|
||||||
if ! [[ -e "${1}" && -w "${1}" && -O "${1}" ]] ; then
|
if ! [[ -e "${1}" && -w "${1}" && -O "${1}" ]] ; then
|
||||||
if ! [[ -e "${1}" ]] ; then
|
if ! [[ -e "${1}" ]] ; then
|
||||||
# doesn't exist?
|
# doesn't exist?
|
||||||
|
@ -75,7 +75,7 @@ if ! [[ -e "${1}" && -w "${1}" && -O "${1}" ]] ; then
|
||||||
# lacks write permissions
|
# lacks write permissions
|
||||||
return 3
|
return 3
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ -x "${1}" ]] ; then
|
if [[ -x "${1}" ]] ; then
|
||||||
# executable and awesome.
|
# executable and awesome.
|
||||||
return 10
|
return 10
|
||||||
|
@ -88,119 +88,119 @@ echo "If you can read this, we may need glasses."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check before we wreck:
|
# Check before we wreck:
|
||||||
checkfiles() {
|
function checkfiles() {
|
||||||
mlog "Permission checks..."
|
mlog "Permission checks..."
|
||||||
cat << EOF > /tmp/my-list.$$
|
cat << EOF > /tmp/my-list.$$
|
||||||
${MYCROFT_HOME}
|
${MYCROFT_HOME}
|
||||||
${MYCROFT_HOME}/scripts/logs
|
${MYCROFT_HOME}/scripts/logs
|
||||||
/tmp/mycroft/
|
/tmp/mycroft/
|
||||||
/opt/mycroft/skills
|
/opt/mycroft/skills
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [[ ${RUN_AS_ROOT} -eq 1 ]] ; then
|
if [[ ${RUN_AS_ROOT} -eq 1 ]] ; then
|
||||||
while read CHECKFN; do
|
while read CHECKFN ; do
|
||||||
checkperms "${CHECKFN}"
|
checkperms "${CHECKFN}"
|
||||||
case $? in
|
case $? in
|
||||||
'0') mlog " - ${CHECKFN} has viable permissions." ;;
|
"0") mlog " - ${CHECKFN} has viable permissions." ;;
|
||||||
'1') mlog " = Error: ${CHECKFN} doesn't exist?" ;;
|
"1") mlog " = Error: ${CHECKFN} doesn't exist?" ;;
|
||||||
'2') mlog " = Error: ${CHECKFN} not owned by ${UID}." ;;
|
"2") mlog " = Error: ${CHECKFN} not owned by ${UID}." ;;
|
||||||
'3') mlog " = Error: ${CHECKFN} not writeable by ${UID}." ;;
|
"3") mlog " = Error: ${CHECKFN} not writeable by ${UID}." ;;
|
||||||
'10') mlog " - ${CHECKFN} is executable and has viable permissions." ;;
|
"10") mlog " - ${CHECKFN} is executable and has viable permissions." ;;
|
||||||
*) mlog " = Error: unable to verify permissions on ${CHECKFN}." ;;
|
*) mlog " = Error: unable to verify permissions on ${CHECKFN}." ;;
|
||||||
esac
|
esac
|
||||||
|
done < /tmp/my-list.$$
|
||||||
done < /tmp/my-list.$$
|
else
|
||||||
else
|
mlog " = Error: permission checks skipped while running as root."
|
||||||
mlog " = Error: permission checks skipped while running as root."
|
fi
|
||||||
fi
|
rm -f /tmp/my-list.$$
|
||||||
rm -f /tmp/my-list.$$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# random info of potential interest
|
# random info of potential interest
|
||||||
checksysinfo () {
|
function checksysinfo() {
|
||||||
mlog "System info..."
|
mlog "System info..."
|
||||||
mlog " - CPU: $(awk -F: '/model name/ {print $2;exit}' /proc/cpuinfo)"
|
mlog " - CPU: $( awk -F: '/model name/ { print $2;exit }' /proc/cpuinfo )"
|
||||||
mlog " - $(echo "RAM Utilization:" && free -h)"
|
mlog " - $( echo "RAM Utilization:" && free -h )"
|
||||||
mlog " - $(echo "Mycroft partition disk usage:" && df -h "${MYCROFT_HOME}")"
|
mlog " - $( echo "Mycroft partition disk usage:" && df -h "${MYCROFT_HOME}" )"
|
||||||
mlog " - $(echo "OS Info:" && cat /etc/*elease*)"
|
mlog " - $( echo "OS Info:" && cat /etc/*elease* )"
|
||||||
mlog " - $(echo "Kernel version:" && uname -a)"
|
mlog " - $( echo "Kernel version:" && uname -a )"
|
||||||
}
|
}
|
||||||
|
|
||||||
# -v
|
# -v
|
||||||
checkversion () {
|
function checkversion() {
|
||||||
mlog "Mycroft version is $(grep -B3 'END_VERSION_BLOCK' ${MYCROFT_HOME}/mycroft/version/__init__.py | cut -d' ' -f3 | tr -s '\012' '\056')"
|
mlog "Mycroft version is $( grep -B3 'END_VERSION_BLOCK' ${MYCROFT_HOME}/mycroft/version/__init__.py | cut -d' ' -f3 | tr -s '\012' '\056' )"
|
||||||
}
|
}
|
||||||
|
|
||||||
# do you want to do repeat?
|
# do you want to do repeat?
|
||||||
checkmimic () {
|
function checkmimic() {
|
||||||
mlog "Checking Mimic..."
|
mlog "Checking Mimic..."
|
||||||
if hash mimic ; then
|
if hash mimic ; then
|
||||||
mlog " - Mimic$(mimic --version| grep mimic)"
|
mlog " - Mimic$( mimic --version | grep mimic )"
|
||||||
mlog " - $(mimic -lv)"
|
mlog " - $( mimic -lv )"
|
||||||
else
|
else
|
||||||
mlog " = Error: Mimic binary not found. Mimic may not be installed?"
|
mlog " = Error: Mimic binary not found. Mimic may not be installed?"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# pythoning!
|
# pythoning!
|
||||||
checkPIP () {
|
function checkPIP() {
|
||||||
mlog "Python checks"
|
mlog "Python checks"
|
||||||
mlog " - Verifying ${MYCROFT_HOME}/requirements.txt:"
|
mlog " - Verifying ${MYCROFT_HOME}/requirements.txt:"
|
||||||
if workon mycroft ; then
|
if workon mycroft ; then
|
||||||
pip list > /tmp/mycroft-piplist.$$
|
pip list > /tmp/mycroft-piplist.$$
|
||||||
|
|
||||||
while read reqline; do
|
while read reqline ; do
|
||||||
IFS='==' read -r -a PIPREQ <<< "$reqline"
|
IFS='==' read -r -a PIPREQ <<< "$reqline"
|
||||||
PIPREQVER=$(grep -i ^"${PIPREQ[0]} " /tmp/mycroft-piplist.$$ | cut -d'(' -f2| tr -d '\051')
|
PIPREQVER=$( grep -i ^"${PIPREQ[0]} " /tmp/mycroft-piplist.$$ | cut -d'(' -f2 | tr -d '\051' )
|
||||||
if [[ "${PIPREQVER}" == "${PIPREQ[2]}" ]]; then
|
if [[ "${PIPREQVER}" == "${PIPREQ[2]}" ]] ; then
|
||||||
mlog " -- pip ${PIPREQ[0]} version ${PIPREQ[2]}"
|
mlog " -- pip ${PIPREQ[0]} version ${PIPREQ[2]}"
|
||||||
else
|
else
|
||||||
mlog " ~~ Warn: can't find ${PIPREQ[0]} ${PIPREQ[2]} in pip. (found ${PIPREQVER})"
|
mlog " ~~ Warn: can't find ${PIPREQ[0]} ${PIPREQ[2]} in pip. (found ${PIPREQVER})"
|
||||||
fi
|
fi
|
||||||
done < "${MYCROFT_HOME}/requirements.txt"
|
done < "${MYCROFT_HOME}/requirements.txt"
|
||||||
deactivate
|
deactivate
|
||||||
mlog " - PIP list can be found at /tmp/mycroft-piplist.$$ to verify any issues."
|
mlog " - PIP list can be found at /tmp/mycroft-piplist.$$ to verify any issues."
|
||||||
else
|
else
|
||||||
mlog " = Error: Unable to enter the mycroft virtualenv, skipping python checks."
|
mlog " = Error: Unable to enter the mycroft virtualenv, skipping python checks."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# a series of tubes
|
# a series of tubes
|
||||||
checktubes () {
|
function checktubes() {
|
||||||
mlog "Internet connectivity..."
|
mlog "Internet connectivity..."
|
||||||
case "$(curl -s --max-time 2 -I http://home.mycroft.ai/ | sed 's/^[^ ]* *\([0-9]\).*/\1/; 1q')" in
|
case "$( curl -s --max-time 2 -I http://home.mycroft.ai/ | sed 's/^[^ ]* *\([0-9]\).*/\1/; 1q' )" in
|
||||||
[23]) mlog " - HTTP connectivity to https://home.mycroft.ai worked!";;
|
[23]) mlog " - HTTP connectivity to https://home.mycroft.ai worked!";;
|
||||||
5) mlog " = Error: The web proxy won't let us through to https://home.mycroft.ai";;
|
5) mlog " = Error: The web proxy won't let us through to https://home.mycroft.ai";;
|
||||||
*) mlog " = Error: The network is down or very slow getting to https://home.mycroft.ai";;
|
*) mlog " = Error: The network is down or very slow getting to https://home.mycroft.ai";;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# I prefer biking myself.
|
# I prefer biking myself.
|
||||||
checkrunning () {
|
function checkrunning() {
|
||||||
while read SCREEN_SESS ; do
|
while read SCREEN_SESS ; do
|
||||||
SESS_NAME=$(echo "${SCREEN_SESS}"| cut -d'(' -f1 | cut -d'.' -f2)
|
SESS_NAME=$( echo "${SCREEN_SESS}" | cut -d'(' -f1 | cut -d'.' -f2 )
|
||||||
SESS_ID=$(echo "${SCREEN_SESS}"| cut -d'.' -f1)
|
SESS_ID=$( echo "${SCREEN_SESS}" | cut -d'.' -f1 )
|
||||||
if [[ $(ps flax| grep "$SESS_ID" | awk ' { print $4 } ' | grep -c "$SESS_ID") -eq 1 ]]; then
|
if [[ $( ps flax| grep "$SESS_ID" | awk ' { print $4 } ' | grep -c "$SESS_ID" ) -eq 1 ]]; then
|
||||||
mlog " - ${SESS_NAME} appears to be currently running."
|
mlog " - ${SESS_NAME} appears to be currently running."
|
||||||
fi
|
fi
|
||||||
done < <(screen -list | grep mycroft)
|
done < <(screen -list | grep mycroft)
|
||||||
}
|
}
|
||||||
|
|
||||||
# He's dead, Jim.
|
# He's dead, Jim.
|
||||||
checkpulse () {
|
function checkpulse() {
|
||||||
mlog "Sound settings..."
|
mlog "Sound settings..."
|
||||||
if hash pactl && [[ ${RUN_AS_ROOT} -eq 1 ]] ; then
|
if hash pactl && [[ ${RUN_AS_ROOT} -eq 1 ]] ; then
|
||||||
mlog " - $(echo "Pulse Audio Defaults:" && pactl info | grep "Default S[i,o]")"
|
mlog " - $( echo "Pulse Audio Defaults:" && pactl info | grep "Default S[i,o]" )"
|
||||||
mlog " - $(echo "Pulse Audio Sinks:" && pactl list sinks | grep -e ^Sink -e 'Name:' -e 'device.description' -e 'product_name' -e udev.id -e 'State:')"
|
mlog " - $( echo "Pulse Audio Sinks:" && pactl list sinks | grep -e ^Sink -e 'Name:' -e 'device.description' -e 'product_name' -e udev.id -e 'State:' )"
|
||||||
mlog " - $(echo "Pulse Audio Sources:" && pactl list sources| grep -e ^Sourc -e 'Name:' -e 'device.description' -e 'product_name' -e udev.id -e 'State:')"
|
mlog " - $( echo "Pulse Audio Sources:" && pactl list sources | grep -e ^Sourc -e 'Name:' -e 'device.description' -e 'product_name' -e udev.id -e 'State:' )"
|
||||||
else
|
else
|
||||||
mlog " = Error: Can't run pactl, skipping audio checks."
|
mlog " = Error: Can't run pactl, skipping audio checks."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ok, fine, go ahead and run this crazy thing
|
# ok, fine, go ahead and run this crazy thing
|
||||||
mlog "Starting ${0}"
|
mlog "Starting ${0}"
|
||||||
|
|
||||||
# Who am i? Check if running sudo/as root/etc.
|
# Who am i? Check if running sudo/as root/etc.
|
||||||
if [[ ${EUID} -ne ${UID} ]] ; then
|
if [[ ${EUID} -ne ${UID} ]] ; then
|
||||||
if [[ ${EUID} -gt 0 ]] ; then
|
if [[ ${EUID} -gt 0 ]] ; then
|
||||||
mlog " - Running as ${EUID} from UID ${UID}"
|
mlog " - Running as ${EUID} from UID ${UID}"
|
||||||
|
@ -214,11 +214,11 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# where are we?
|
# where are we?
|
||||||
RUNDIR=$(readlink -f "${0}"| tr -s '\057' '\012' | sed \$d | tr -s '\012' '\057')
|
RUNDIR=$( readlink -f "${0}" | tr -s '\057' '\012' | sed \$d | tr -s '\012' '\057' )
|
||||||
|
|
||||||
# Where is mycroft installed?
|
# Where is mycroft installed?
|
||||||
if [[ -f "${RUNDIR}/mycroft-service.screen" && -f "${RUNDIR}/../mycroft/__init__.py" ]] ; then
|
if [[ -f "${RUNDIR}/mycroft-service.screen" && -f "${RUNDIR}/../mycroft/__init__.py" ]] ; then
|
||||||
MYCROFT_HOME=$(cd "${RUNDIR}" && cd .. && pwd )
|
MYCROFT_HOME=$(cd "${RUNDIR}" && cd .. && pwd )
|
||||||
else
|
else
|
||||||
if [[ -f "/opt/mycroft/mycroft/__init__.py" ]] ; then
|
if [[ -f "/opt/mycroft/mycroft/__init__.py" ]] ; then
|
||||||
MYCROFT_HOME="/opt/mycroft/"
|
MYCROFT_HOME="/opt/mycroft/"
|
||||||
|
@ -249,4 +249,3 @@ while [[ $# -gt 0 ]] ; do
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2017 Mycroft AI Inc.
|
# Copyright 2017 Mycroft AI Inc.
|
||||||
#
|
#
|
||||||
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
# this script is for the Mark 1 and Picroft units
|
# this script is for the Mark 1 and Picroft units
|
||||||
|
|
||||||
user=$(whoami)
|
user=$( whoami )
|
||||||
#Build being changed to
|
#Build being changed to
|
||||||
change_to=${1}
|
change_to=${1}
|
||||||
#path to mycroft-core checkout
|
#path to mycroft-core checkout
|
||||||
path=${2:-"${HOME}/mycroft-core"}
|
path=${2:-"${HOME}/mycroft-core"}
|
||||||
#currently installed package
|
#currently installed package
|
||||||
current_pkg=$(cat /etc/apt/sources.list.d/repo.mycroft.ai.list)
|
current_pkg=$( cat /etc/apt/sources.list.d/repo.mycroft.ai.list )
|
||||||
stable_pkg="deb http://repo.mycroft.ai/repos/apt/debian debian main"
|
stable_pkg="deb http://repo.mycroft.ai/repos/apt/debian debian main"
|
||||||
unstable_pkg="deb http://repo.mycroft.ai/repos/apt/debian debian-unstable main"
|
unstable_pkg="deb http://repo.mycroft.ai/repos/apt/debian debian-unstable main"
|
||||||
|
|
||||||
|
@ -32,23 +32,22 @@ picroft_package_list="mycroft-picroft mycroft-core mycroft-wifi-setup"
|
||||||
# Determine the platform
|
# Determine the platform
|
||||||
mycroft_platform="null"
|
mycroft_platform="null"
|
||||||
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
||||||
mycroft_platform=$( jq -r '.enclosure.platform' /etc/mycroft/mycroft.conf )
|
mycroft_platform=$( jq -r '.enclosure.platform' /etc/mycroft/mycroft.conf )
|
||||||
else
|
else
|
||||||
if [[ "$(hostname)" == "picroft" ]] ; then
|
if [[ "$( hostname )" == "picroft" ]] ; then
|
||||||
mycroft_platform="picroft"
|
mycroft_platform="picroft"
|
||||||
elif [[ "$(hostname)" =~ "mark_1" ]] ; then
|
elif [[ "$( hostname )" =~ "mark_1" ]] ; then
|
||||||
mycroft_platform="mycroft_mark_1"
|
mycroft_platform="mycroft_mark_1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function service_ctl() {
|
||||||
function service_ctl {
|
|
||||||
service=${1}
|
service=${1}
|
||||||
action=${2}
|
action=${2}
|
||||||
sudo /etc/init.d/${service} ${action}
|
sudo /etc/init.d/${service} ${action}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop_mycroft {
|
function stop_mycroft() {
|
||||||
service_ctl mycroft-audio stop
|
service_ctl mycroft-audio stop
|
||||||
service_ctl mycroft-skills stop
|
service_ctl mycroft-skills stop
|
||||||
service_ctl mycroft-speech-client stop
|
service_ctl mycroft-speech-client stop
|
||||||
|
@ -57,7 +56,7 @@ function stop_mycroft {
|
||||||
service_ctl mycroft-messagebus stop
|
service_ctl mycroft-messagebus stop
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_mycroft {
|
function start_mycroft() {
|
||||||
service_ctl mycroft-messagebus start
|
service_ctl mycroft-messagebus start
|
||||||
service_ctl mycroft-enclosure-client start
|
service_ctl mycroft-enclosure-client start
|
||||||
service_ctl mycroft-audio start
|
service_ctl mycroft-audio start
|
||||||
|
@ -66,7 +65,7 @@ function start_mycroft {
|
||||||
service_ctl mycroft-admin-service start
|
service_ctl mycroft-admin-service start
|
||||||
}
|
}
|
||||||
|
|
||||||
function restart_mycroft {
|
function restart_mycroft() {
|
||||||
service_ctl mycroft-messagebus restart
|
service_ctl mycroft-messagebus restart
|
||||||
service_ctl mycroft-audio restart
|
service_ctl mycroft-audio restart
|
||||||
service_ctl mycroft-skills restart
|
service_ctl mycroft-skills restart
|
||||||
|
@ -76,7 +75,7 @@ function restart_mycroft {
|
||||||
}
|
}
|
||||||
|
|
||||||
#Changes init scripts back to the original versions
|
#Changes init scripts back to the original versions
|
||||||
function restore_init_scripts {
|
function restore_init_scripts() {
|
||||||
# stop running Mycroft services
|
# stop running Mycroft services
|
||||||
stop_mycroft
|
stop_mycroft
|
||||||
|
|
||||||
|
@ -102,9 +101,8 @@ function restore_init_scripts {
|
||||||
start_mycroft
|
start_mycroft
|
||||||
}
|
}
|
||||||
|
|
||||||
function github_init_scripts {
|
function github_init_scripts() {
|
||||||
if [ ! -f /etc/init.d/mycroft-skills.original ]; then
|
if [ ! -f /etc/init.d/mycroft-skills.original ] ; then
|
||||||
|
|
||||||
stop_mycroft
|
stop_mycroft
|
||||||
|
|
||||||
# save original scripts
|
# save original scripts
|
||||||
|
@ -116,7 +114,7 @@ function github_init_scripts {
|
||||||
sudo sh -c 'cat /etc/init.d/mycroft-admin-service > /etc/init.d/mycroft-admin-service.original'
|
sudo sh -c 'cat /etc/init.d/mycroft-admin-service > /etc/init.d/mycroft-admin-service.original'
|
||||||
|
|
||||||
# switch to point a github install and run as the current user
|
# switch to point a github install and run as the current user
|
||||||
# TODO Verify all of these
|
# TODO Verify all of these
|
||||||
sudo sed -i 's_.*SCRIPT=.*_SCRIPT="'${path}'/start-mycroft.sh audio"_g' /etc/init.d/mycroft-audio
|
sudo sed -i 's_.*SCRIPT=.*_SCRIPT="'${path}'/start-mycroft.sh audio"_g' /etc/init.d/mycroft-audio
|
||||||
sudo sed -i 's_.*RUNAS=.*_RUNAS='${user}'_g' /etc/init.d/mycroft-audio
|
sudo sed -i 's_.*RUNAS=.*_RUNAS='${user}'_g' /etc/init.d/mycroft-audio
|
||||||
sudo sed -i 's_stop() {_stop() {\nPID=$(ps ax | grep mycroft/audio/ | awk '"'NR==1{print \$1; exit}'"')\necho "${PID}" > "$PIDFILE"_g' /etc/init.d/mycroft-audio
|
sudo sed -i 's_stop() {_stop() {\nPID=$(ps ax | grep mycroft/audio/ | awk '"'NR==1{print \$1; exit}'"')\necho "${PID}" > "$PIDFILE"_g' /etc/init.d/mycroft-audio
|
||||||
|
@ -139,10 +137,10 @@ function github_init_scripts {
|
||||||
|
|
||||||
# soft link the current user to the mycroft user's identity folder
|
# soft link the current user to the mycroft user's identity folder
|
||||||
chown ${user}:${user} /home/mycroft/.mycroft/identity/identity2.json
|
chown ${user}:${user} /home/mycroft/.mycroft/identity/identity2.json
|
||||||
if [ ! -e ${HOME}/.mycroft ]; then
|
if [ ! -e ${HOME}/.mycroft ] ; then
|
||||||
mkdir ${HOME}/.mycroft
|
mkdir ${HOME}/.mycroft
|
||||||
fi
|
fi
|
||||||
if [ ! -e ${HOME}/.mycroft/identity ]; then
|
if [ ! -e ${HOME}/.mycroft/identity ] ; then
|
||||||
sudo ln -s /home/mycroft/.mycroft/identity ${HOME}/.mycroft/
|
sudo ln -s /home/mycroft/.mycroft/identity ${HOME}/.mycroft/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -158,7 +156,7 @@ function github_init_scripts {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_apt {
|
function invoke_apt() {
|
||||||
if [ ${mycroft_platform} == "mycroft_mark_1" ] ; then
|
if [ ${mycroft_platform} == "mycroft_mark_1" ] ; then
|
||||||
echo "${1}ing the mycroft-mark-1 metapackage..."
|
echo "${1}ing the mycroft-mark-1 metapackage..."
|
||||||
sudo apt-get ${1} mycroft-mark-1 -y
|
sudo apt-get ${1} mycroft-mark-1 -y
|
||||||
|
@ -172,7 +170,7 @@ function invoke_apt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_all {
|
function remove_all() {
|
||||||
if [ ${mycroft_platform} == "mycroft_mark_1" ] ; then
|
if [ ${mycroft_platform} == "mycroft_mark_1" ] ; then
|
||||||
echo "Removing the mycroft mark-1 packages..."
|
echo "Removing the mycroft mark-1 packages..."
|
||||||
sudo apt-get remove ${mark_1_package_list} -y
|
sudo apt-get remove ${mark_1_package_list} -y
|
||||||
|
@ -186,7 +184,7 @@ function remove_all {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_build {
|
function change_build() {
|
||||||
build=${1}
|
build=${1}
|
||||||
sudo sh -c 'echo '"${build}"' > /etc/apt/sources.list.d/repo.mycroft.ai.list'
|
sudo sh -c 'echo '"${build}"' > /etc/apt/sources.list.d/repo.mycroft.ai.list'
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
@ -194,7 +192,7 @@ function change_build {
|
||||||
invoke_apt install
|
invoke_apt install
|
||||||
}
|
}
|
||||||
|
|
||||||
function stable_to_unstable_server {
|
function stable_to_unstable_server() {
|
||||||
identity_path=/home/mycroft/.mycroft/identity/
|
identity_path=/home/mycroft/.mycroft/identity/
|
||||||
conf_path=/home/mycroft/.mycroft/
|
conf_path=/home/mycroft/.mycroft/
|
||||||
|
|
||||||
|
@ -207,24 +205,24 @@ function stable_to_unstable_server {
|
||||||
|
|
||||||
# point to test server
|
# point to test server
|
||||||
echo "Changing mycroft.conf to point to test server api-test.mycroft.ai"
|
echo "Changing mycroft.conf to point to test server api-test.mycroft.ai"
|
||||||
if [ -f ${conf_path}mycroft.conf ]; then
|
if [ -f ${conf_path}mycroft.conf ] ; then
|
||||||
cp ${conf_path}mycroft.conf ${conf_path}mycroft.conf.stable
|
cp ${conf_path}mycroft.conf ${conf_path}mycroft.conf.stable
|
||||||
else
|
else
|
||||||
echo "could not find mycroft.conf, was it deleted?"
|
echo "could not find mycroft.conf, was it deleted?"
|
||||||
fi
|
fi
|
||||||
if [ -f ${conf_path}mycroft.conf.unstable ]; then
|
if [ -f ${conf_path}mycroft.conf.unstable ] ; then
|
||||||
cp ${conf_path}mycroft.conf.unstable ${conf_path}mycroft.conf
|
cp ${conf_path}mycroft.conf.unstable ${conf_path}mycroft.conf
|
||||||
else
|
else
|
||||||
rm -r ${conf_path}mycroft.conf
|
rm -r ${conf_path}mycroft.conf
|
||||||
echo '{"server": {"url":"https://api-test.mycroft.ai", "version":"v1", "update":true, "metrics":false }}' $(cat ${conf_path}mycroft.conf.stable) | jq -s add > ${conf_path}mycroft.conf
|
echo '{"server": {"url":"https://api-test.mycroft.ai", "version":"v1", "update":true, "metrics":false }}' $( cat ${conf_path}mycroft.conf.stable ) | jq -s add > ${conf_path}mycroft.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# saving identity2.json to stable state
|
# saving identity2.json to stable state
|
||||||
echo "Pointing identity2.json to unstable and saving to identity2.json.stable"
|
echo "Pointing identity2.json to unstable and saving to identity2.json.stable"
|
||||||
if [ -f ${identity_path}identity2.json ]; then
|
if [ -f ${identity_path}identity2.json ] ; then
|
||||||
mv ${identity_path}identity2.json ${identity_path}identity2.json.stable
|
mv ${identity_path}identity2.json ${identity_path}identity2.json.stable
|
||||||
fi
|
fi
|
||||||
if [ -f /home/mycroft/.mycroft/identity/identity2.json.unstable ]; then
|
if [ -f /home/mycroft/.mycroft/identity/identity2.json.unstable ] ; then
|
||||||
cp ${identity_path}identity2.json.unstable ${identity_path}identity2.json
|
cp ${identity_path}identity2.json.unstable ${identity_path}identity2.json
|
||||||
else
|
else
|
||||||
echo "NOTE: This seems to be your first time switching to unstable. You will need to go to home-test.mycroft.ai to pair on unstable."
|
echo "NOTE: This seems to be your first time switching to unstable. You will need to go to home-test.mycroft.ai to pair on unstable."
|
||||||
|
@ -234,7 +232,7 @@ function stable_to_unstable_server {
|
||||||
echo "Set to use the home-test.mycroft.ai server!"
|
echo "Set to use the home-test.mycroft.ai server!"
|
||||||
}
|
}
|
||||||
|
|
||||||
function unstable_to_stable_server {
|
function unstable_to_stable_server() {
|
||||||
# switching from unstable -> stable
|
# switching from unstable -> stable
|
||||||
identity_path=/home/mycroft/.mycroft/identity/
|
identity_path=/home/mycroft/.mycroft/identity/
|
||||||
conf_path=/home/mycroft/.mycroft/
|
conf_path=/home/mycroft/.mycroft/
|
||||||
|
@ -242,29 +240,29 @@ function unstable_to_stable_server {
|
||||||
# check if on stable (home.mycroft.ai) already
|
# check if on stable (home.mycroft.ai) already
|
||||||
cmp --silent ${conf_path}/mycroft.conf ${conf_path}/mycroft.conf.stable
|
cmp --silent ${conf_path}/mycroft.conf ${conf_path}/mycroft.conf.stable
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
echo "Already set to use the home.mycroft.ai server"
|
echo "Already set to use the home.mycroft.ai server"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# point api to production server
|
# point api to production server
|
||||||
echo "Changing mycroft.conf to point to production server api.mycroft.ai"
|
echo "Changing mycroft.conf to point to production server api.mycroft.ai"
|
||||||
if [ -f ${conf_path}mycroft.conf ]; then
|
if [ -f ${conf_path}mycroft.conf ] ; then
|
||||||
echo '{"server": {"url":"https://api-test.mycroft.ai", "version":"v1", "update":true, "metrics":false }}' $(cat ${conf_path}mycroft.conf) | jq -s add > ${conf_path}mycroft.conf.unstable
|
echo '{"server": {"url":"https://api-test.mycroft.ai", "version":"v1", "update":true, "metrics":false }}' $( cat ${conf_path}mycroft.conf ) | jq -s add > ${conf_path}mycroft.conf.unstable
|
||||||
else
|
else
|
||||||
echo "could not find mycroft.conf, was it deleted?"
|
echo "could not find mycroft.conf, was it deleted?"
|
||||||
fi
|
fi
|
||||||
if [ -f ${conf_path}mycroft.conf.stable ]; then
|
if [ -f ${conf_path}mycroft.conf.stable ] ; then
|
||||||
cp ${conf_path}mycroft.conf.stable ${conf_path}mycroft.conf
|
cp ${conf_path}mycroft.conf.stable ${conf_path}mycroft.conf
|
||||||
else
|
else
|
||||||
echo "ERROR: Could not find mycroft.conf.stable, was it deleted?, an easy fix would be to copy mycroft.conf.unstable to mycroft.conf but remove the server field"
|
echo "ERROR: Could not find mycroft.conf.stable, was it deleted?, an easy fix would be to copy mycroft.conf.unstable to mycroft.conf but remove the server field"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# saving identity2.json into unstable state, then copying identity2.json.stable to identity2.json
|
# saving identity2.json into unstable state, then copying identity2.json.stable to identity2.json
|
||||||
echo "Pointing identity2.json to unstable and saving to identity2.json.unstable"
|
echo "Pointing identity2.json to unstable and saving to identity2.json.unstable"
|
||||||
if [ -f ${identity_path}identity2.json ]; then
|
if [ -f ${identity_path}identity2.json ] ; then
|
||||||
mv ${identity_path}identity2.json ${identity_path}identity2.json.unstable
|
mv ${identity_path}identity2.json ${identity_path}identity2.json.unstable
|
||||||
fi
|
fi
|
||||||
if [ -f ${identity_path}identity2.json.stable ]; then
|
if [ -f ${identity_path}identity2.json.stable ] ; then
|
||||||
cp ${identity_path}identity2.json.stable ${identity_path}identity2.json
|
cp ${identity_path}identity2.json.stable ${identity_path}identity2.json
|
||||||
else
|
else
|
||||||
echo "Can not find identity2.json.stable, was it deleted? You may need to repair at home.mycroft.ai"
|
echo "Can not find identity2.json.stable, was it deleted? You may need to repair at home.mycroft.ai"
|
||||||
|
@ -274,9 +272,7 @@ function unstable_to_stable_server {
|
||||||
echo "Set to use the home.mycroft.ai server!"
|
echo "Set to use the home.mycroft.ai server!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [ "${change_to}" == "unstable" ] ; then
|
||||||
|
|
||||||
if [ "${change_to}" = "unstable" ]; then
|
|
||||||
# make sure user is running as sudo first
|
# make sure user is running as sudo first
|
||||||
if [ "$EUID" -ne 0 ] ; then
|
if [ "$EUID" -ne 0 ] ; then
|
||||||
echo "Please run with sudo"
|
echo "Please run with sudo"
|
||||||
|
@ -284,18 +280,18 @@ if [ "${change_to}" = "unstable" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Switching to unstable build..."
|
echo "Switching to unstable build..."
|
||||||
if [ "${current_pkg}" = "${stable_pkg}" ]; then
|
if [ "${current_pkg}" == "${stable_pkg}" ] ; then
|
||||||
change_build "${unstable_pkg}"
|
change_build "${unstable_pkg}"
|
||||||
else
|
else
|
||||||
echo "already on unstable"
|
echo "already on unstable"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /etc/init.d/mycroft-skills.original ]; then
|
if [ -f /etc/init.d/mycroft-skills.original ] ; then
|
||||||
restore_init_scripts
|
restore_init_scripts
|
||||||
# Reboot since the audio input won't work for some reason
|
# Reboot since the audio input won't work for some reason
|
||||||
sudo reboot
|
sudo reboot
|
||||||
fi
|
fi
|
||||||
elif [ "${change_to}" = "stable" ]; then
|
elif [ "${change_to}" == "stable" ] ; then
|
||||||
# make sure user is running as sudo first
|
# make sure user is running as sudo first
|
||||||
if [ "$EUID" -ne 0 ] ; then
|
if [ "$EUID" -ne 0 ] ; then
|
||||||
echo "Please run with sudo"
|
echo "Please run with sudo"
|
||||||
|
@ -303,7 +299,7 @@ elif [ "${change_to}" = "stable" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Switching to stable build..."
|
echo "Switching to stable build..."
|
||||||
if [ "${current_pkg}" = "${unstable_pkg}" ]; then
|
if [ "${current_pkg}" == "${unstable_pkg}" ] ; then
|
||||||
# Need to remove the package to make sure upgrade happens due to
|
# Need to remove the package to make sure upgrade happens due to
|
||||||
# difference in stable/unstable to package numbering schemes
|
# difference in stable/unstable to package numbering schemes
|
||||||
remove_all
|
remove_all
|
||||||
|
@ -313,7 +309,7 @@ elif [ "${change_to}" = "stable" ]; then
|
||||||
echo "already on stable"
|
echo "already on stable"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /etc/init.d/mycroft-skills.original ]; then
|
if [ -f /etc/init.d/mycroft-skills.original ] ; then
|
||||||
restore_init_scripts
|
restore_init_scripts
|
||||||
sudo chmod -x /etc/cron.hourly/mycroft-core # Enable updates
|
sudo chmod -x /etc/cron.hourly/mycroft-core # Enable updates
|
||||||
|
|
||||||
|
@ -321,9 +317,9 @@ elif [ "${change_to}" = "stable" ]; then
|
||||||
sudo reboot
|
sudo reboot
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [ "${change_to}" = "github" ]; then
|
elif [ "${change_to}" == "github" ] ; then
|
||||||
echo "Switching to github..."
|
echo "Switching to github..."
|
||||||
if [ ! -d ${path} ]; then
|
if [ ! -d ${path} ] ; then
|
||||||
mkdir --parents "${path}"
|
mkdir --parents "${path}"
|
||||||
cd "${path}"
|
cd "${path}"
|
||||||
cd ..
|
cd ..
|
||||||
|
@ -332,13 +328,13 @@ elif [ "${change_to}" = "github" ]; then
|
||||||
|
|
||||||
sudo chmod -x /etc/cron.hourly/mycroft-core # Disable updates
|
sudo chmod -x /etc/cron.hourly/mycroft-core # Disable updates
|
||||||
|
|
||||||
if [ -d ${path} ]; then
|
if [ -d ${path} ] ; then
|
||||||
if [ -f /usr/local/bin/mimic ]; then
|
if [ -f /usr/local/bin/mimic ] ; then
|
||||||
echo "Mimic file exists"
|
echo "Mimic file exists"
|
||||||
mimic_flag='-sm'
|
mimic_flag="-sm"
|
||||||
else
|
else
|
||||||
echo "file doesn't exist"
|
echo "file doesn't exist"
|
||||||
mimic_flag=''
|
mimic_flag=""
|
||||||
fi
|
fi
|
||||||
cd ${path}
|
cd ${path}
|
||||||
# Build the dev environment
|
# Build the dev environment
|
||||||
|
@ -352,14 +348,14 @@ elif [ "${change_to}" = "github" ]; then
|
||||||
# For some reason precise won't trigger until after a reboot
|
# For some reason precise won't trigger until after a reboot
|
||||||
echo "Rebooting..."
|
echo "Rebooting..."
|
||||||
sudo reboot
|
sudo reboot
|
||||||
elif [ "${change_to}" = "home" ]; then
|
elif [ "${change_to}" == "home" ] ; then
|
||||||
# make sure user is running as sudo first
|
# make sure user is running as sudo first
|
||||||
if [ "$EUID" -ne 0 ] ; then
|
if [ "$EUID" -ne 0 ] ; then
|
||||||
echo "Please run with sudo"
|
echo "Please run with sudo"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
unstable_to_stable_server
|
unstable_to_stable_server
|
||||||
elif [ "${change_to}" = "home-test" ]; then
|
elif [ "${change_to}" == "home-test" ] ; then
|
||||||
# make sure user is running as sudo first
|
# make sure user is running as sudo first
|
||||||
if [ "$EUID" -ne 0 ] ; then
|
if [ "$EUID" -ne 0 ] ; then
|
||||||
echo "Please run with sudo"
|
echo "Please run with sudo"
|
||||||
|
|
|
@ -14,43 +14,43 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
mycroft_root_dir='/opt/mycroft' # Also change in configuration
|
mycroft_root_dir="/opt/mycroft" # Also change in configuration
|
||||||
skills_dir="${mycroft_root_dir}"/skills
|
skills_dir="${mycroft_root_dir}"/skills
|
||||||
# exit on any error
|
# exit on any error
|
||||||
set -Ee
|
set -Ee
|
||||||
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ]; do
|
while [ -h "$SOURCE" ] ; do
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
SOURCE="$(readlink "$SOURCE")"
|
SOURCE="$(readlink "$SOURCE")"
|
||||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||||
done
|
done
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
# Determine which user is running this script
|
# Determine which user is running this script
|
||||||
setup_user=$USER
|
setup_user=$USER
|
||||||
setup_group=$( id -gn $USER )
|
setup_group=$( id -gn $USER )
|
||||||
|
|
||||||
# change ownership of ${mycroft_root_dir} to ${setup_user } recursively
|
# change ownership of ${mycroft_root_dir} to ${setup_user } recursively
|
||||||
function change_ownership {
|
function change_ownership {
|
||||||
echo "Changing ownership of" ${mycroft_root_dir} "to user:" ${setup_user} "with group:" ${setup_group}
|
echo "Changing ownership of" ${mycroft_root_dir} "to user:" ${setup_user} "with group:" ${setup_group}
|
||||||
sudo chown -Rvf ${setup_user}:${setup_group} ${mycroft_root_dir}
|
sudo chown -Rvf ${setup_user}:${setup_group} ${mycroft_root_dir}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ ${IS_TRAVIS} != true ]]; then
|
if [[ ${IS_TRAVIS} != true ]] ; then
|
||||||
if [ ! -d ${skills_dir} ]; then
|
if [ ! -d ${skills_dir} ] ; then
|
||||||
echo "Create /opt/mycroft/skills"
|
echo "Create /opt/mycroft/skills"
|
||||||
sudo mkdir -p ${skills_dir}
|
sudo mkdir -p ${skills_dir}
|
||||||
change_ownership
|
change_ownership
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -w ${SKILLS_DIR} ]; then
|
if [ ! -w ${SKILLS_DIR} ] ; then
|
||||||
change_ownership
|
change_ownership
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# fix ownership of ${mycroft_root_dir} if it is not owned by the ${setup_user}
|
# fix ownership of ${mycroft_root_dir} if it is not owned by the ${setup_user}
|
||||||
if [[ `stat -c "%U:%G" /opt/mycroft` != "${setup_user}:${setup_user}" ]]; then
|
if [[ $( stat -c "%U:%G" /opt/mycroft ) != "${setup_user}:${setup_user}" ]] ; then
|
||||||
change_ownership
|
change_ownership
|
||||||
fi
|
fi
|
||||||
|
|
196
start-mycroft.sh
196
start-mycroft.sh
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2017 Mycroft AI Inc.
|
# Copyright 2017 Mycroft AI Inc.
|
||||||
#
|
#
|
||||||
|
@ -25,61 +25,61 @@ mkdir -p $scripts_dir/logs
|
||||||
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${DIR}/.venv"}
|
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${DIR}/.venv"}
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
echo "${script}: Mycroft command/service launcher"
|
echo "${script}: Mycroft command/service launcher"
|
||||||
echo "usage: ${script} [command] [params]"
|
echo "usage: ${script} [command] [params]"
|
||||||
echo
|
echo
|
||||||
echo "Services:"
|
echo "Services:"
|
||||||
echo " all runs core services: bus, audio, skills, voice"
|
echo " all runs core services: bus, audio, skills, voice"
|
||||||
echo " debug runs core services, then starts the CLI"
|
echo " debug runs core services, then starts the CLI"
|
||||||
echo
|
echo
|
||||||
echo "Services:"
|
echo "Services:"
|
||||||
echo " audio the audio playback service"
|
echo " audio the audio playback service"
|
||||||
echo " bus the messagebus service"
|
echo " bus the messagebus service"
|
||||||
echo " skills the skill service"
|
echo " skills the skill service"
|
||||||
echo " voice voice capture service"
|
echo " voice voice capture service"
|
||||||
echo " wifi wifi setup service"
|
echo " wifi wifi setup service"
|
||||||
echo " enclosure mark_1 enclosure service"
|
echo " enclosure mark_1 enclosure service"
|
||||||
echo
|
echo
|
||||||
echo "Tools:"
|
echo "Tools:"
|
||||||
echo " cli the Command Line Interface"
|
echo " cli the Command Line Interface"
|
||||||
echo " unittest run mycroft-core unit tests (requires pytest)"
|
echo " unittest run mycroft-core unit tests (requires pytest)"
|
||||||
echo " skillstest run the skill autotests for all skills (requires pytest)"
|
echo " skillstest run the skill autotests for all skills (requires pytest)"
|
||||||
echo
|
echo
|
||||||
echo "Utils:"
|
echo "Utils:"
|
||||||
echo " audiotest attempt simple audio validation"
|
echo " audiotest attempt simple audio validation"
|
||||||
echo " audioaccuracytest more complex audio validation"
|
echo " audioaccuracytest more complex audio validation"
|
||||||
echo " sdkdoc generate sdk documentation"
|
echo " sdkdoc generate sdk documentation"
|
||||||
echo
|
echo
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " ${script} all"
|
echo " ${script} all"
|
||||||
echo " ${script} cli"
|
echo " ${script} cli"
|
||||||
echo " ${script} unittest"
|
echo " ${script} unittest"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_script=""
|
_script=""
|
||||||
function name-to-script-path() {
|
function name-to-script-path() {
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"bus") _script=${DIR}/mycroft/messagebus/service/main.py ;;
|
"bus") _script=${DIR}/mycroft/messagebus/service/main.py ;;
|
||||||
"skills") _script=${DIR}/mycroft/skills/main.py ;;
|
"skills") _script=${DIR}/mycroft/skills/main.py ;;
|
||||||
"audio") _script=${DIR}/mycroft/audio/main.py ;;
|
"audio") _script=${DIR}/mycroft/audio/main.py ;;
|
||||||
"voice") _script=${DIR}/mycroft/client/speech/main.py ;;
|
"voice") _script=${DIR}/mycroft/client/speech/main.py ;;
|
||||||
"cli") _script=${DIR}/mycroft/client/text/main.py ;;
|
"cli") _script=${DIR}/mycroft/client/text/main.py ;;
|
||||||
"wifi") _script=${DIR}/mycroft/client/wifisetup/main.py ;;
|
"wifi") _script=${DIR}/mycroft/client/wifisetup/main.py ;;
|
||||||
"audioaccuracytest") _script=${DIR}/mycroft/audio-accuracy-test/audio_accuracy_test.py ;;
|
"audioaccuracytest") _script=${DIR}/mycroft/audio-accuracy-test/audio_accuracy_test.py ;;
|
||||||
"sdkdoc") _script=${DIR}/doc/generate_sdk_docs.py ;;
|
"sdkdoc") _script=${DIR}/doc/generate_sdk_docs.py ;;
|
||||||
"enclosure") _script=${DIR}/mycroft/client/enclosure/main.py ;;
|
"enclosure") _script=${DIR}/mycroft/client/enclosure/main.py ;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Error: Unknown name '${1}'"
|
echo "Error: Unknown name '${1}'"
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function source-venv() {
|
function source-venv() {
|
||||||
# Enter Python virtual environment, unless under Docker
|
# Enter Python virtual environment, unless under Docker
|
||||||
if [ ! -f "/.dockerenv" ]; then
|
if [ ! -f "/.dockerenv" ] ; then
|
||||||
source ${VIRTUALENV_ROOT}/bin/activate
|
source ${VIRTUALENV_ROOT}/bin/activate
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ function launch-background() {
|
||||||
name-to-script-path ${1}
|
name-to-script-path ${1}
|
||||||
|
|
||||||
# Check if already running
|
# Check if already running
|
||||||
if [[ $( ps aux ) = *${_script}* ]] ; then
|
if [[ $( ps aux ) == *${_script}* ]] ; then
|
||||||
echo "Restarting: ${1}"
|
echo "Restarting: ${1}"
|
||||||
source stop-mycroft.sh ${1}
|
source stop-mycroft.sh ${1}
|
||||||
else
|
else
|
||||||
|
@ -119,7 +119,7 @@ function launch-background() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Security warning/reminder for the user
|
# Security warning/reminder for the user
|
||||||
if [[ "${1}" = "bus" ]] ; then
|
if [[ "${1}" == "bus" ]] ; then
|
||||||
echo "CAUTION: The Mycroft bus is an open websocket with no built-in security"
|
echo "CAUTION: The Mycroft bus is an open websocket with no built-in security"
|
||||||
echo " measures. You are responsible for protecting the local port"
|
echo " measures. You are responsible for protecting the local port"
|
||||||
echo " 8181 with a firewall as appropriate."
|
echo " 8181 with a firewall as appropriate."
|
||||||
|
@ -139,7 +139,7 @@ function launch-all() {
|
||||||
# Determine platform type
|
# Determine platform type
|
||||||
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
||||||
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
|
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
|
||||||
if [[ $mycroft_platform = 'mycroft_mark_1' ]] ; then
|
if [[ $mycroft_platform = "mycroft_mark_1" ]] ; then
|
||||||
# running on a Mark 1, start enclosure service
|
# running on a Mark 1, start enclosure service
|
||||||
launch-background enclosure
|
launch-background enclosure
|
||||||
fi
|
fi
|
||||||
|
@ -147,9 +147,9 @@ function launch-all() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function check-dependencies() {
|
function check-dependencies() {
|
||||||
if [ ! -f .installed ] || ! md5sum -c &> /dev/null < .installed; then
|
if [ ! -f .installed ] || ! md5sum -c &> /dev/null < .installed ; then
|
||||||
echo "Please update dependencies by running ./dev_setup.sh again."
|
echo "Please update dependencies by running ./dev_setup.sh again."
|
||||||
if command -v notify-send >/dev/null; then
|
if command -v notify-send >/dev/null ; then
|
||||||
notify-send "Mycroft Dependencies Outdated" "Run ./dev_setup.sh again"
|
notify-send "Mycroft Dependencies Outdated" "Run ./dev_setup.sh again"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -162,57 +162,57 @@ _params=$@
|
||||||
check-dependencies
|
check-dependencies
|
||||||
|
|
||||||
case ${_opt} in
|
case ${_opt} in
|
||||||
"all")
|
"all")
|
||||||
launch-all
|
launch-all
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"bus")
|
"bus")
|
||||||
launch-background ${_opt}
|
launch-background ${_opt}
|
||||||
;;
|
;;
|
||||||
"audio")
|
"audio")
|
||||||
launch-background ${_opt}
|
launch-background ${_opt}
|
||||||
;;
|
;;
|
||||||
"skills")
|
"skills")
|
||||||
launch-background ${_opt}
|
launch-background ${_opt}
|
||||||
;;
|
;;
|
||||||
"voice")
|
"voice")
|
||||||
launch-background ${_opt}
|
launch-background ${_opt}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"debug")
|
"debug")
|
||||||
launch-all
|
launch-all
|
||||||
launch-process cli
|
launch-process cli
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"cli")
|
"cli")
|
||||||
launch-process ${_opt}
|
launch-process ${_opt}
|
||||||
;;
|
;;
|
||||||
"wifi")
|
"wifi")
|
||||||
launch-background ${_opt}
|
launch-background ${_opt}
|
||||||
;;
|
;;
|
||||||
"unittest")
|
"unittest")
|
||||||
source-venv
|
source-venv
|
||||||
pytest test/unittests/ --cov=mycroft "$@"
|
pytest test/unittests/ --cov=mycroft "$@"
|
||||||
;;
|
;;
|
||||||
"skillstest")
|
"skillstest")
|
||||||
source-venv
|
source-venv
|
||||||
pytest test/integrationtests/skills/discover_tests.py "$@"
|
pytest test/integrationtests/skills/discover_tests.py "$@"
|
||||||
;;
|
;;
|
||||||
"audiotest")
|
"audiotest")
|
||||||
source-venv
|
source-venv
|
||||||
python3 -m mycroft.util.audio_test "${@:1}"
|
python3 -m mycroft.util.audio_test "${@:1}"
|
||||||
;;
|
;;
|
||||||
"audioaccuracytest")
|
"audioaccuracytest")
|
||||||
launch-process ${_opt}
|
launch-process ${_opt}
|
||||||
;;
|
;;
|
||||||
"sdkdoc")
|
"sdkdoc")
|
||||||
launch-process ${_opt}
|
launch-process ${_opt}
|
||||||
;;
|
;;
|
||||||
"enclosure")
|
"enclosure")
|
||||||
launch-background ${_opt}
|
launch-background ${_opt}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
help
|
help
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
108
stop-mycroft.sh
108
stop-mycroft.sh
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2017 Mycroft AI Inc.
|
# Copyright 2017 Mycroft AI Inc.
|
||||||
#
|
#
|
||||||
|
@ -23,23 +23,23 @@ SCRIPTS="$DIR/scripts"
|
||||||
mkdir -p $SCRIPTS/logs
|
mkdir -p $SCRIPTS/logs
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
echo "${script}: Mycroft service stopper"
|
echo "${script}: Mycroft service stopper"
|
||||||
echo "usage: ${script} [service]"
|
echo "usage: ${script} [service]"
|
||||||
echo
|
echo
|
||||||
echo "Service:"
|
echo "Service:"
|
||||||
echo " all ends core services: bus, audio, skills, voice"
|
echo " all ends core services: bus, audio, skills, voice"
|
||||||
echo " (none) same as \"all\""
|
echo " (none) same as \"all\""
|
||||||
echo " bus stop the Mycroft messagebus service"
|
echo " bus stop the Mycroft messagebus service"
|
||||||
echo " audio stop the audio playback service"
|
echo " audio stop the audio playback service"
|
||||||
echo " skills stop the skill service"
|
echo " skills stop the skill service"
|
||||||
echo " voice stop voice capture service"
|
echo " voice stop voice capture service"
|
||||||
echo " enclosure stop mark_1 enclosure service"
|
echo " enclosure stop mark_1 enclosure service"
|
||||||
echo
|
echo
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " ${script}"
|
echo " ${script}"
|
||||||
echo " ${script} audio"
|
echo " ${script} audio"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function process-running() {
|
function process-running() {
|
||||||
|
@ -51,14 +51,12 @@ function process-running() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function end-process() {
|
function end-process() {
|
||||||
|
|
||||||
if process-running $1 ; then
|
if process-running $1 ; then
|
||||||
pid=$( ps aux | grep "python3\? .*${1}/main.py" | awk '{print $2}' )
|
pid=$( ps aux | grep "python3\? .*${1}/main.py" | awk '{print $2}' )
|
||||||
kill -SIGINT ${pid}
|
kill -SIGINT ${pid}
|
||||||
|
|
||||||
c=1
|
c=1
|
||||||
while [ $c -le 20 ]
|
while [ $c -le 20 ] ; do
|
||||||
do
|
|
||||||
if process-running $1 ; then
|
if process-running $1 ; then
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
(( c++ ))
|
(( c++ ))
|
||||||
|
@ -76,47 +74,45 @@ function end-process() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPT=$1
|
OPT=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
case ${OPT} in
|
case ${OPT} in
|
||||||
"all")
|
"all")
|
||||||
;&
|
;&
|
||||||
"")
|
"")
|
||||||
echo "Stopping all mycroft-core services"
|
echo "Stopping all mycroft-core services"
|
||||||
end-process service
|
end-process service
|
||||||
end-process skills
|
end-process skills
|
||||||
end-process audio
|
end-process audio
|
||||||
end-process speech
|
end-process speech
|
||||||
|
|
||||||
# determine platform type
|
# determine platform type
|
||||||
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
||||||
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
|
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
|
||||||
if [[ $mycroft_platform = 'mycroft_mark_1' ]] ; then
|
if [[ $mycroft_platform == "mycroft_mark_1" ]] ; then
|
||||||
# running on a Mark 1, stop enclosure service
|
# running on a Mark 1, stop enclosure service
|
||||||
end-process enclosure
|
end-process enclosure
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
;;
|
||||||
;;
|
"bus")
|
||||||
"bus")
|
end-process service
|
||||||
end-process service
|
;;
|
||||||
;;
|
"audio")
|
||||||
"audio")
|
end-process audio
|
||||||
end-process audio
|
;;
|
||||||
;;
|
"skills")
|
||||||
"skills")
|
end-process skills
|
||||||
end-process skills
|
;;
|
||||||
;;
|
"voice")
|
||||||
"voice")
|
end-process speech
|
||||||
end-process speech
|
;;
|
||||||
;;
|
"enclosure")
|
||||||
"enclosure")
|
end-process enclosure
|
||||||
end-process enclosure
|
;;
|
||||||
;;
|
|
||||||
|
|
||||||
|
*)
|
||||||
*)
|
help
|
||||||
help
|
;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# Copyright 2018 Mycroft AI Inc.
|
# Copyright 2018 Mycroft AI Inc.
|
||||||
#
|
#
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
# necessary to run unit tests or to interact directly with mycroft-core
|
# necessary to run unit tests or to interact directly with mycroft-core
|
||||||
# via an interactive Python shell.
|
# via an interactive Python shell.
|
||||||
|
|
||||||
if [ "$0" = "$BASH_SOURCE" ] ; then
|
if [ "$0" == "$BASH_SOURCE" ] ; then
|
||||||
# Prevent running in script then exiting immediately
|
# Prevent running in script then exiting immediately
|
||||||
echo "ERROR: Invoke with 'source venv-activate.sh' or '. venv-activate.sh'"
|
echo "ERROR: Invoke with 'source venv-activate.sh' or '. venv-activate.sh'"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue