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
|
||||
set -Ee
|
||||
|
||||
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."
|
||||
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 " -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
|
||||
for var in "$@" ; do
|
||||
if [[ ${var} == "-h" ]] || [[ ${var} == "--help" ]] ; then
|
||||
show_help
|
||||
exit 0
|
||||
|
@ -75,25 +74,25 @@ do
|
|||
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
|
||||
echo "This script should not be run as root or with sudo."
|
||||
echo "To force, rerun with --allow-root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
found_exe() {
|
||||
function found_exe() {
|
||||
hash "$1" 2>/dev/null
|
||||
}
|
||||
|
||||
install_deps() {
|
||||
function install_deps() {
|
||||
echo "Installing packages..."
|
||||
if found_exe sudo; then
|
||||
if found_exe sudo ; then
|
||||
SUDO=sudo
|
||||
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 -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
|
||||
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
|
||||
|
@ -104,10 +103,10 @@ install_deps() {
|
|||
cd ..
|
||||
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
|
||||
else
|
||||
if found_exe tput; then
|
||||
if found_exe tput ; then
|
||||
green="$(tput setaf 2)"
|
||||
blue="$(tput setaf 4)"
|
||||
reset="$(tput sgr0)"
|
||||
|
@ -119,10 +118,10 @@ install_deps() {
|
|||
fi
|
||||
}
|
||||
|
||||
TOP=$(cd $(dirname $0) && pwd -L)
|
||||
TOP=$( cd $( dirname $0 ) && pwd -L )
|
||||
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${TOP}/.venv"}
|
||||
|
||||
install_venv() {
|
||||
function install_venv() {
|
||||
python3 -m venv "${VIRTUALENV_ROOT}/" --without-pip
|
||||
curl https://bootstrap.pypa.io/get-pip.py | "${VIRTUALENV_ROOT}/bin/python"
|
||||
}
|
||||
|
@ -134,31 +133,31 @@ install_deps
|
|||
git config commit.template .gitmessage
|
||||
|
||||
# Check whether to build mimic (it takes a really long time!)
|
||||
build_mimic='y'
|
||||
build_mimic="y"
|
||||
if [[ ${opt_skipmimic} == true ]] ; then
|
||||
build_mimic='n'
|
||||
build_mimic="n"
|
||||
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
|
||||
# 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
|
||||
fi
|
||||
|
||||
if ! [ "$has_mimic" == "" ] ; then
|
||||
echo "Mimic is installed. Press 'y' to rebuild mimic, any other key to skip."
|
||||
read -n1 build_mimic
|
||||
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
|
||||
echo "Mimic is installed. Press 'y' to rebuild mimic, any other key to skip."
|
||||
read -n1 build_mimic
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ]; then
|
||||
install_venv
|
||||
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ] ; then
|
||||
install_venv
|
||||
fi
|
||||
|
||||
# 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
|
||||
fi
|
||||
|
||||
if ! grep -q "$TOP" $VENV_PATH_FILE; then
|
||||
echo "Adding mycroft-core to virtualenv path"
|
||||
sed -i.tmp '1 a\
|
||||
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
|
||||
if ! pip install -r requirements.txt ; then
|
||||
echo "Warning: Failed to install all requirements. Continue? y/N"
|
||||
read -n1 continue
|
||||
if [[ "$continue" != "y" ]] ; then
|
||||
|
@ -194,25 +193,25 @@ if ! pip install -r requirements.txt; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if ! pip install -r test-requirements.txt; then
|
||||
echo "Warning test requirements wasn't installed, Note: normal operation should still work fine..."
|
||||
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}')
|
||||
SYSMEM=$( free | awk '/^Mem:/ { print $2 }' )
|
||||
MAXCORES=$(($SYSMEM / 512000))
|
||||
MINCORES=1
|
||||
CORES=$(nproc)
|
||||
CORES=$( nproc )
|
||||
|
||||
# ensure MAXCORES is > 0
|
||||
if [[ ${MAXCORES} -lt 1 ]]; then
|
||||
MAXCORES=${MINCORES}
|
||||
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}
|
||||
if ! [[ ${CORES} =~ ^[0-9]+$ ]] ; then
|
||||
CORES=${MINCORES}
|
||||
elif [[ ${MAXCORES} -lt ${CORES} ]] ; then
|
||||
CORES=${MAXCORES}
|
||||
fi
|
||||
|
||||
echo "Building with $CORES cores."
|
||||
|
@ -223,11 +222,11 @@ echo "Building with $CORES cores."
|
|||
#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}"
|
||||
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."
|
||||
echo "Skipping mimic build."
|
||||
fi
|
||||
|
||||
# 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"
|
||||
|
||||
# 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
|
||||
cd ${MIMIC_DIR}
|
||||
./autogen.sh
|
||||
|
|
|
@ -20,49 +20,47 @@ set -Ee
|
|||
#TOP="."
|
||||
|
||||
|
||||
function enable_local {
|
||||
sed -i -- 's/from pocketsphinx.pocketsphinx import Decoder/from pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
||||
function enable_local() {
|
||||
sed -i 's/from pocketsphinx.pocketsphinx import Decoder/from pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
||||
}
|
||||
|
||||
function disable_local {
|
||||
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
|
||||
|
||||
function disable_local() {
|
||||
sed -i 's/from pocketsphinx import Decoder/from pocketsphinx.pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
|
||||
}
|
||||
|
||||
if [ "$1" = "-q" ]; then
|
||||
enable_local
|
||||
install_pocketsphinx
|
||||
exit 0
|
||||
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
|
||||
enable_local
|
||||
install_pocketsphinx
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "This script will checkout, compile, and install pocketsphinx locally if the debian package python-pocketsphinx is not available"
|
||||
|
||||
PS3='Please enter your choice: '
|
||||
options=("Enable local checkout, compile and install" "Disable local checkout and exit" "Do nothing and quit")
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
select opt in "${options[@]}" ; do
|
||||
case $opt in
|
||||
"Enable local checkout, compile and install")
|
||||
echo "you chose choice 1"
|
||||
|
@ -78,7 +76,8 @@ do
|
|||
echo "you chose choice 3"
|
||||
exit 0
|
||||
;;
|
||||
*) echo invalid option;;
|
||||
*)
|
||||
echo invalid option
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
# Ensure we're in a virtualenv.
|
||||
if [ "$VIRTUAL_ENV" == "" ]
|
||||
then
|
||||
if [ "$VIRTUAL_ENV" == "" ] ; then
|
||||
echo "ERROR: not in a virtual environment."
|
||||
exit -1
|
||||
fi
|
||||
|
@ -34,8 +33,7 @@ python -c "
|
|||
try: import cairo; raise SystemExit(0)
|
||||
except ImportError: raise SystemExit(-1)"
|
||||
|
||||
if [ $? == 255 ]
|
||||
then
|
||||
if [ $? == 255 ] ; then
|
||||
echo -e "\E[1m * Installing cairo...\E[0m"
|
||||
# Fetch, build, and install py2cairo.
|
||||
( cd $CACHE
|
||||
|
@ -56,8 +54,7 @@ python -c "
|
|||
try: import gobject; raise SystemExit(0)
|
||||
except ImportError: raise SystemExit(-1)"
|
||||
|
||||
if [ $? == 255 ]
|
||||
then
|
||||
if [ $? == 255 ] ; then
|
||||
echo -e "\E[1m * Installing gobject...\E[0m"
|
||||
# Fetch, build, and install gobject.
|
||||
( cd $CACHE
|
||||
|
@ -77,8 +74,7 @@ python -c "
|
|||
try: import gtk; raise SystemExit(0)
|
||||
except ImportError: raise SystemExit(-1)" 2&> /dev/null
|
||||
|
||||
if [ $? == 255 ]
|
||||
then
|
||||
if [ $? == 255 ] ; then
|
||||
echo -e "\E[1m * Installing gtk...\E[0m"
|
||||
# Fetch, build, and install gtk.
|
||||
( cd $CACHE
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2017 Mycroft AI Inc.
|
||||
#
|
||||
|
@ -14,21 +14,21 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Verify and present the user with information about their installation of mycroft.
|
||||
# Should be run as the mycroft user.
|
||||
# Verify and present the user with information about their installation of mycroft.
|
||||
# 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
|
||||
|
||||
helpfunc() {
|
||||
echo "Usage: ${0} [FUNCTION]"
|
||||
echo " Functions include
|
||||
-v version
|
||||
function helpfunc() {
|
||||
echo "Usage: ${0} [FUNCTION]"
|
||||
echo " Functions include
|
||||
-v version
|
||||
-P python
|
||||
-p permissions
|
||||
-i internet
|
||||
-i internet
|
||||
-s system info
|
||||
-u audio
|
||||
-u audio
|
||||
-r running
|
||||
-m mimic
|
||||
-a run all checks
|
||||
|
@ -39,9 +39,9 @@ if [[ $# -eq 0 ]] ; then
|
|||
helpfunc && exit 1
|
||||
fi
|
||||
|
||||
MYCROFT_HOME=''
|
||||
MYCROFT_HOME=""
|
||||
RUN_AS_ROOT=1
|
||||
source $(locate virtualenvwrapper.sh)
|
||||
source $( locate virtualenvwrapper.sh )
|
||||
|
||||
# log stuff and things
|
||||
LOG_FILE=/tmp/my-info.$$.out
|
||||
|
@ -55,14 +55,14 @@ else
|
|||
fi
|
||||
|
||||
# it's big, it's heavy, it's wood!
|
||||
mlog() {
|
||||
local timestamp="[$(date +"%Y-%m-%d %H:%M:%S")]"
|
||||
function mlog() {
|
||||
local timestamp="[$( date +"%Y-%m-%d %H:%M:%S" )]"
|
||||
message="$*"
|
||||
echo "${timestamp} ${message}" |tee -a ${LOG_FILE}
|
||||
}
|
||||
|
||||
# Sup big perm.
|
||||
checkperms () {
|
||||
function checkperms() {
|
||||
if ! [[ -e "${1}" && -w "${1}" && -O "${1}" ]] ; then
|
||||
if ! [[ -e "${1}" ]] ; then
|
||||
# doesn't exist?
|
||||
|
@ -75,7 +75,7 @@ if ! [[ -e "${1}" && -w "${1}" && -O "${1}" ]] ; then
|
|||
# lacks write permissions
|
||||
return 3
|
||||
fi
|
||||
else
|
||||
else
|
||||
if [[ -x "${1}" ]] ; then
|
||||
# executable and awesome.
|
||||
return 10
|
||||
|
@ -88,119 +88,119 @@ echo "If you can read this, we may need glasses."
|
|||
}
|
||||
|
||||
# Check before we wreck:
|
||||
checkfiles() {
|
||||
mlog "Permission checks..."
|
||||
cat << EOF > /tmp/my-list.$$
|
||||
function checkfiles() {
|
||||
mlog "Permission checks..."
|
||||
cat << EOF > /tmp/my-list.$$
|
||||
${MYCROFT_HOME}
|
||||
${MYCROFT_HOME}/scripts/logs
|
||||
/tmp/mycroft/
|
||||
/opt/mycroft/skills
|
||||
EOF
|
||||
|
||||
if [[ ${RUN_AS_ROOT} -eq 1 ]] ; then
|
||||
while read CHECKFN; do
|
||||
checkperms "${CHECKFN}"
|
||||
case $? in
|
||||
'0') mlog " - ${CHECKFN} has viable permissions." ;;
|
||||
'1') mlog " = Error: ${CHECKFN} doesn't exist?" ;;
|
||||
'2') mlog " = Error: ${CHECKFN} not owned by ${UID}." ;;
|
||||
'3') mlog " = Error: ${CHECKFN} not writeable by ${UID}." ;;
|
||||
'10') mlog " - ${CHECKFN} is executable and has viable permissions." ;;
|
||||
*) mlog " = Error: unable to verify permissions on ${CHECKFN}." ;;
|
||||
esac
|
||||
|
||||
done < /tmp/my-list.$$
|
||||
else
|
||||
mlog " = Error: permission checks skipped while running as root."
|
||||
fi
|
||||
rm -f /tmp/my-list.$$
|
||||
if [[ ${RUN_AS_ROOT} -eq 1 ]] ; then
|
||||
while read CHECKFN ; do
|
||||
checkperms "${CHECKFN}"
|
||||
case $? in
|
||||
"0") mlog " - ${CHECKFN} has viable permissions." ;;
|
||||
"1") mlog " = Error: ${CHECKFN} doesn't exist?" ;;
|
||||
"2") mlog " = Error: ${CHECKFN} not owned by ${UID}." ;;
|
||||
"3") mlog " = Error: ${CHECKFN} not writeable by ${UID}." ;;
|
||||
"10") mlog " - ${CHECKFN} is executable and has viable permissions." ;;
|
||||
*) mlog " = Error: unable to verify permissions on ${CHECKFN}." ;;
|
||||
esac
|
||||
done < /tmp/my-list.$$
|
||||
else
|
||||
mlog " = Error: permission checks skipped while running as root."
|
||||
fi
|
||||
rm -f /tmp/my-list.$$
|
||||
}
|
||||
|
||||
# random info of potential interest
|
||||
checksysinfo () {
|
||||
mlog "System info..."
|
||||
mlog " - CPU: $(awk -F: '/model name/ {print $2;exit}' /proc/cpuinfo)"
|
||||
mlog " - $(echo "RAM Utilization:" && free -h)"
|
||||
mlog " - $(echo "Mycroft partition disk usage:" && df -h "${MYCROFT_HOME}")"
|
||||
mlog " - $(echo "OS Info:" && cat /etc/*elease*)"
|
||||
mlog " - $(echo "Kernel version:" && uname -a)"
|
||||
function checksysinfo() {
|
||||
mlog "System info..."
|
||||
mlog " - CPU: $( awk -F: '/model name/ { print $2;exit }' /proc/cpuinfo )"
|
||||
mlog " - $( echo "RAM Utilization:" && free -h )"
|
||||
mlog " - $( echo "Mycroft partition disk usage:" && df -h "${MYCROFT_HOME}" )"
|
||||
mlog " - $( echo "OS Info:" && cat /etc/*elease* )"
|
||||
mlog " - $( echo "Kernel version:" && uname -a )"
|
||||
}
|
||||
|
||||
# -v
|
||||
checkversion () {
|
||||
mlog "Mycroft version is $(grep -B3 'END_VERSION_BLOCK' ${MYCROFT_HOME}/mycroft/version/__init__.py | cut -d' ' -f3 | tr -s '\012' '\056')"
|
||||
function checkversion() {
|
||||
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?
|
||||
checkmimic () {
|
||||
mlog "Checking Mimic..."
|
||||
if hash mimic ; then
|
||||
mlog " - Mimic$(mimic --version| grep mimic)"
|
||||
mlog " - $(mimic -lv)"
|
||||
else
|
||||
mlog " = Error: Mimic binary not found. Mimic may not be installed?"
|
||||
fi
|
||||
function checkmimic() {
|
||||
mlog "Checking Mimic..."
|
||||
if hash mimic ; then
|
||||
mlog " - Mimic$( mimic --version | grep mimic )"
|
||||
mlog " - $( mimic -lv )"
|
||||
else
|
||||
mlog " = Error: Mimic binary not found. Mimic may not be installed?"
|
||||
fi
|
||||
}
|
||||
|
||||
# pythoning!
|
||||
checkPIP () {
|
||||
mlog "Python checks"
|
||||
mlog " - Verifying ${MYCROFT_HOME}/requirements.txt:"
|
||||
if workon mycroft ; then
|
||||
pip list > /tmp/mycroft-piplist.$$
|
||||
|
||||
while read reqline; do
|
||||
IFS='==' read -r -a PIPREQ <<< "$reqline"
|
||||
PIPREQVER=$(grep -i ^"${PIPREQ[0]} " /tmp/mycroft-piplist.$$ | cut -d'(' -f2| tr -d '\051')
|
||||
if [[ "${PIPREQVER}" == "${PIPREQ[2]}" ]]; then
|
||||
mlog " -- pip ${PIPREQ[0]} version ${PIPREQ[2]}"
|
||||
else
|
||||
mlog " ~~ Warn: can't find ${PIPREQ[0]} ${PIPREQ[2]} in pip. (found ${PIPREQVER})"
|
||||
fi
|
||||
done < "${MYCROFT_HOME}/requirements.txt"
|
||||
deactivate
|
||||
mlog " - PIP list can be found at /tmp/mycroft-piplist.$$ to verify any issues."
|
||||
else
|
||||
function checkPIP() {
|
||||
mlog "Python checks"
|
||||
mlog " - Verifying ${MYCROFT_HOME}/requirements.txt:"
|
||||
if workon mycroft ; then
|
||||
pip list > /tmp/mycroft-piplist.$$
|
||||
|
||||
while read reqline ; do
|
||||
IFS='==' read -r -a PIPREQ <<< "$reqline"
|
||||
PIPREQVER=$( grep -i ^"${PIPREQ[0]} " /tmp/mycroft-piplist.$$ | cut -d'(' -f2 | tr -d '\051' )
|
||||
if [[ "${PIPREQVER}" == "${PIPREQ[2]}" ]] ; then
|
||||
mlog " -- pip ${PIPREQ[0]} version ${PIPREQ[2]}"
|
||||
else
|
||||
mlog " ~~ Warn: can't find ${PIPREQ[0]} ${PIPREQ[2]} in pip. (found ${PIPREQVER})"
|
||||
fi
|
||||
done < "${MYCROFT_HOME}/requirements.txt"
|
||||
deactivate
|
||||
mlog " - PIP list can be found at /tmp/mycroft-piplist.$$ to verify any issues."
|
||||
else
|
||||
mlog " = Error: Unable to enter the mycroft virtualenv, skipping python checks."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# a series of tubes
|
||||
checktubes () {
|
||||
mlog "Internet connectivity..."
|
||||
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!";;
|
||||
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";;
|
||||
esac
|
||||
function checktubes() {
|
||||
mlog "Internet connectivity..."
|
||||
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!";;
|
||||
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";;
|
||||
esac
|
||||
}
|
||||
|
||||
# I prefer biking myself.
|
||||
checkrunning () {
|
||||
while read SCREEN_SESS ; do
|
||||
SESS_NAME=$(echo "${SCREEN_SESS}"| cut -d'(' -f1 | cut -d'.' -f2)
|
||||
SESS_ID=$(echo "${SCREEN_SESS}"| cut -d'.' -f1)
|
||||
if [[ $(ps flax| grep "$SESS_ID" | awk ' { print $4 } ' | grep -c "$SESS_ID") -eq 1 ]]; then
|
||||
mlog " - ${SESS_NAME} appears to be currently running."
|
||||
fi
|
||||
done < <(screen -list | grep mycroft)
|
||||
function checkrunning() {
|
||||
while read SCREEN_SESS ; do
|
||||
SESS_NAME=$( echo "${SCREEN_SESS}" | cut -d'(' -f1 | cut -d'.' -f2 )
|
||||
SESS_ID=$( echo "${SCREEN_SESS}" | cut -d'.' -f1 )
|
||||
if [[ $( ps flax| grep "$SESS_ID" | awk ' { print $4 } ' | grep -c "$SESS_ID" ) -eq 1 ]]; then
|
||||
mlog " - ${SESS_NAME} appears to be currently running."
|
||||
fi
|
||||
done < <(screen -list | grep mycroft)
|
||||
}
|
||||
|
||||
# He's dead, Jim.
|
||||
checkpulse () {
|
||||
mlog "Sound settings..."
|
||||
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 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:')"
|
||||
else
|
||||
mlog " = Error: Can't run pactl, skipping audio checks."
|
||||
fi
|
||||
function checkpulse() {
|
||||
mlog "Sound settings..."
|
||||
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 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:' )"
|
||||
else
|
||||
mlog " = Error: Can't run pactl, skipping audio checks."
|
||||
fi
|
||||
}
|
||||
|
||||
# ok, fine, go ahead and run this crazy thing
|
||||
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} -gt 0 ]] ; then
|
||||
mlog " - Running as ${EUID} from UID ${UID}"
|
||||
|
@ -214,11 +214,11 @@ else
|
|||
fi
|
||||
|
||||
# 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?
|
||||
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
|
||||
if [[ -f "/opt/mycroft/mycroft/__init__.py" ]] ; then
|
||||
MYCROFT_HOME="/opt/mycroft/"
|
||||
|
@ -249,4 +249,3 @@ while [[ $# -gt 0 ]] ; do
|
|||
done
|
||||
|
||||
exit 0
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2017 Mycroft AI Inc.
|
||||
#
|
||||
|
@ -16,13 +16,13 @@
|
|||
|
||||
# this script is for the Mark 1 and Picroft units
|
||||
|
||||
user=$(whoami)
|
||||
user=$( whoami )
|
||||
#Build being changed to
|
||||
change_to=${1}
|
||||
#path to mycroft-core checkout
|
||||
path=${2:-"${HOME}/mycroft-core"}
|
||||
#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"
|
||||
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
|
||||
mycroft_platform="null"
|
||||
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
|
||||
if [[ "$(hostname)" == "picroft" ]] ; then
|
||||
mycroft_platform="picroft"
|
||||
elif [[ "$(hostname)" =~ "mark_1" ]] ; then
|
||||
mycroft_platform="mycroft_mark_1"
|
||||
fi
|
||||
if [[ "$( hostname )" == "picroft" ]] ; then
|
||||
mycroft_platform="picroft"
|
||||
elif [[ "$( hostname )" =~ "mark_1" ]] ; then
|
||||
mycroft_platform="mycroft_mark_1"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
function service_ctl {
|
||||
function service_ctl() {
|
||||
service=${1}
|
||||
action=${2}
|
||||
sudo /etc/init.d/${service} ${action}
|
||||
}
|
||||
|
||||
function stop_mycroft {
|
||||
function stop_mycroft() {
|
||||
service_ctl mycroft-audio stop
|
||||
service_ctl mycroft-skills stop
|
||||
service_ctl mycroft-speech-client stop
|
||||
|
@ -57,7 +56,7 @@ function stop_mycroft {
|
|||
service_ctl mycroft-messagebus stop
|
||||
}
|
||||
|
||||
function start_mycroft {
|
||||
function start_mycroft() {
|
||||
service_ctl mycroft-messagebus start
|
||||
service_ctl mycroft-enclosure-client start
|
||||
service_ctl mycroft-audio start
|
||||
|
@ -66,7 +65,7 @@ function start_mycroft {
|
|||
service_ctl mycroft-admin-service start
|
||||
}
|
||||
|
||||
function restart_mycroft {
|
||||
function restart_mycroft() {
|
||||
service_ctl mycroft-messagebus restart
|
||||
service_ctl mycroft-audio restart
|
||||
service_ctl mycroft-skills restart
|
||||
|
@ -76,7 +75,7 @@ function restart_mycroft {
|
|||
}
|
||||
|
||||
#Changes init scripts back to the original versions
|
||||
function restore_init_scripts {
|
||||
function restore_init_scripts() {
|
||||
# stop running Mycroft services
|
||||
stop_mycroft
|
||||
|
||||
|
@ -102,9 +101,8 @@ function restore_init_scripts {
|
|||
start_mycroft
|
||||
}
|
||||
|
||||
function github_init_scripts {
|
||||
if [ ! -f /etc/init.d/mycroft-skills.original ]; then
|
||||
|
||||
function github_init_scripts() {
|
||||
if [ ! -f /etc/init.d/mycroft-skills.original ] ; then
|
||||
stop_mycroft
|
||||
|
||||
# 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'
|
||||
|
||||
# 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_.*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
|
||||
|
@ -139,10 +137,10 @@ function github_init_scripts {
|
|||
|
||||
# soft link the current user to the mycroft user's identity folder
|
||||
chown ${user}:${user} /home/mycroft/.mycroft/identity/identity2.json
|
||||
if [ ! -e ${HOME}/.mycroft ]; then
|
||||
if [ ! -e ${HOME}/.mycroft ] ; then
|
||||
mkdir ${HOME}/.mycroft
|
||||
fi
|
||||
if [ ! -e ${HOME}/.mycroft/identity ]; then
|
||||
if [ ! -e ${HOME}/.mycroft/identity ] ; then
|
||||
sudo ln -s /home/mycroft/.mycroft/identity ${HOME}/.mycroft/
|
||||
fi
|
||||
|
||||
|
@ -158,7 +156,7 @@ function github_init_scripts {
|
|||
fi
|
||||
}
|
||||
|
||||
function invoke_apt {
|
||||
function invoke_apt() {
|
||||
if [ ${mycroft_platform} == "mycroft_mark_1" ] ; then
|
||||
echo "${1}ing the mycroft-mark-1 metapackage..."
|
||||
sudo apt-get ${1} mycroft-mark-1 -y
|
||||
|
@ -172,7 +170,7 @@ function invoke_apt {
|
|||
fi
|
||||
}
|
||||
|
||||
function remove_all {
|
||||
function remove_all() {
|
||||
if [ ${mycroft_platform} == "mycroft_mark_1" ] ; then
|
||||
echo "Removing the mycroft mark-1 packages..."
|
||||
sudo apt-get remove ${mark_1_package_list} -y
|
||||
|
@ -186,7 +184,7 @@ function remove_all {
|
|||
fi
|
||||
}
|
||||
|
||||
function change_build {
|
||||
function change_build() {
|
||||
build=${1}
|
||||
sudo sh -c 'echo '"${build}"' > /etc/apt/sources.list.d/repo.mycroft.ai.list'
|
||||
sudo apt-get update
|
||||
|
@ -194,7 +192,7 @@ function change_build {
|
|||
invoke_apt install
|
||||
}
|
||||
|
||||
function stable_to_unstable_server {
|
||||
function stable_to_unstable_server() {
|
||||
identity_path=/home/mycroft/.mycroft/identity/
|
||||
conf_path=/home/mycroft/.mycroft/
|
||||
|
||||
|
@ -207,24 +205,24 @@ function stable_to_unstable_server {
|
|||
|
||||
# point to test server
|
||||
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
|
||||
else
|
||||
echo "could not find mycroft.conf, was it deleted?"
|
||||
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
|
||||
else
|
||||
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
|
||||
|
||||
# saving identity2.json to stable state
|
||||
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
|
||||
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
|
||||
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."
|
||||
|
@ -234,7 +232,7 @@ function stable_to_unstable_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
|
||||
identity_path=/home/mycroft/.mycroft/identity/
|
||||
conf_path=/home/mycroft/.mycroft/
|
||||
|
@ -242,29 +240,29 @@ function unstable_to_stable_server {
|
|||
# check if on stable (home.mycroft.ai) already
|
||||
cmp --silent ${conf_path}/mycroft.conf ${conf_path}/mycroft.conf.stable
|
||||
if [ $? -eq 0 ] ; then
|
||||
echo "Already set to use the home.mycroft.ai server"
|
||||
return
|
||||
echo "Already set to use the home.mycroft.ai server"
|
||||
return
|
||||
fi
|
||||
|
||||
# point api to production server
|
||||
echo "Changing mycroft.conf to point to production server api.mycroft.ai"
|
||||
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
|
||||
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
|
||||
else
|
||||
echo "could not find mycroft.conf, was it deleted?"
|
||||
echo "could not find mycroft.conf, was it deleted?"
|
||||
fi
|
||||
if [ -f ${conf_path}mycroft.conf.stable ]; then
|
||||
cp ${conf_path}mycroft.conf.stable ${conf_path}mycroft.conf
|
||||
if [ -f ${conf_path}mycroft.conf.stable ] ; then
|
||||
cp ${conf_path}mycroft.conf.stable ${conf_path}mycroft.conf
|
||||
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
|
||||
|
||||
# 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"
|
||||
if [ -f ${identity_path}identity2.json ]; then
|
||||
if [ -f ${identity_path}identity2.json ] ; then
|
||||
mv ${identity_path}identity2.json ${identity_path}identity2.json.unstable
|
||||
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
|
||||
else
|
||||
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!"
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [ "${change_to}" = "unstable" ]; then
|
||||
if [ "${change_to}" == "unstable" ] ; then
|
||||
# make sure user is running as sudo first
|
||||
if [ "$EUID" -ne 0 ] ; then
|
||||
echo "Please run with sudo"
|
||||
|
@ -284,18 +280,18 @@ if [ "${change_to}" = "unstable" ]; then
|
|||
fi
|
||||
|
||||
echo "Switching to unstable build..."
|
||||
if [ "${current_pkg}" = "${stable_pkg}" ]; then
|
||||
if [ "${current_pkg}" == "${stable_pkg}" ] ; then
|
||||
change_build "${unstable_pkg}"
|
||||
else
|
||||
echo "already on unstable"
|
||||
fi
|
||||
|
||||
if [ -f /etc/init.d/mycroft-skills.original ]; then
|
||||
if [ -f /etc/init.d/mycroft-skills.original ] ; then
|
||||
restore_init_scripts
|
||||
# Reboot since the audio input won't work for some reason
|
||||
sudo reboot
|
||||
fi
|
||||
elif [ "${change_to}" = "stable" ]; then
|
||||
elif [ "${change_to}" == "stable" ] ; then
|
||||
# make sure user is running as sudo first
|
||||
if [ "$EUID" -ne 0 ] ; then
|
||||
echo "Please run with sudo"
|
||||
|
@ -303,7 +299,7 @@ elif [ "${change_to}" = "stable" ]; then
|
|||
fi
|
||||
|
||||
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
|
||||
# difference in stable/unstable to package numbering schemes
|
||||
remove_all
|
||||
|
@ -313,7 +309,7 @@ elif [ "${change_to}" = "stable" ]; then
|
|||
echo "already on stable"
|
||||
fi
|
||||
|
||||
if [ -f /etc/init.d/mycroft-skills.original ]; then
|
||||
if [ -f /etc/init.d/mycroft-skills.original ] ; then
|
||||
restore_init_scripts
|
||||
sudo chmod -x /etc/cron.hourly/mycroft-core # Enable updates
|
||||
|
||||
|
@ -321,9 +317,9 @@ elif [ "${change_to}" = "stable" ]; then
|
|||
sudo reboot
|
||||
fi
|
||||
|
||||
elif [ "${change_to}" = "github" ]; then
|
||||
elif [ "${change_to}" == "github" ] ; then
|
||||
echo "Switching to github..."
|
||||
if [ ! -d ${path} ]; then
|
||||
if [ ! -d ${path} ] ; then
|
||||
mkdir --parents "${path}"
|
||||
cd "${path}"
|
||||
cd ..
|
||||
|
@ -332,13 +328,13 @@ elif [ "${change_to}" = "github" ]; then
|
|||
|
||||
sudo chmod -x /etc/cron.hourly/mycroft-core # Disable updates
|
||||
|
||||
if [ -d ${path} ]; then
|
||||
if [ -f /usr/local/bin/mimic ]; then
|
||||
if [ -d ${path} ] ; then
|
||||
if [ -f /usr/local/bin/mimic ] ; then
|
||||
echo "Mimic file exists"
|
||||
mimic_flag='-sm'
|
||||
mimic_flag="-sm"
|
||||
else
|
||||
echo "file doesn't exist"
|
||||
mimic_flag=''
|
||||
mimic_flag=""
|
||||
fi
|
||||
cd ${path}
|
||||
# Build the dev environment
|
||||
|
@ -352,14 +348,14 @@ elif [ "${change_to}" = "github" ]; then
|
|||
# For some reason precise won't trigger until after a reboot
|
||||
echo "Rebooting..."
|
||||
sudo reboot
|
||||
elif [ "${change_to}" = "home" ]; then
|
||||
elif [ "${change_to}" == "home" ] ; then
|
||||
# make sure user is running as sudo first
|
||||
if [ "$EUID" -ne 0 ] ; then
|
||||
echo "Please run with sudo"
|
||||
exit
|
||||
fi
|
||||
unstable_to_stable_server
|
||||
elif [ "${change_to}" = "home-test" ]; then
|
||||
elif [ "${change_to}" == "home-test" ] ; then
|
||||
# make sure user is running as sudo first
|
||||
if [ "$EUID" -ne 0 ] ; then
|
||||
echo "Please run with sudo"
|
||||
|
|
|
@ -14,43 +14,43 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# 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
|
||||
# exit on any error
|
||||
set -Ee
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||
while [ -h "$SOURCE" ] ; do
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
|
||||
# Determine which user is running this script
|
||||
setup_user=$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 {
|
||||
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 [ ! -d ${skills_dir} ]; then
|
||||
if [[ ${IS_TRAVIS} != true ]] ; then
|
||||
if [ ! -d ${skills_dir} ] ; then
|
||||
echo "Create /opt/mycroft/skills"
|
||||
sudo mkdir -p ${skills_dir}
|
||||
change_ownership
|
||||
fi
|
||||
|
||||
if [ ! -w ${SKILLS_DIR} ]; then
|
||||
if [ ! -w ${SKILLS_DIR} ] ; then
|
||||
change_ownership
|
||||
fi
|
||||
fi
|
||||
|
||||
# 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
|
||||
fi
|
||||
|
|
196
start-mycroft.sh
196
start-mycroft.sh
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2017 Mycroft AI Inc.
|
||||
#
|
||||
|
@ -25,61 +25,61 @@ mkdir -p $scripts_dir/logs
|
|||
VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${DIR}/.venv"}
|
||||
|
||||
function help() {
|
||||
echo "${script}: Mycroft command/service launcher"
|
||||
echo "usage: ${script} [command] [params]"
|
||||
echo
|
||||
echo "Services:"
|
||||
echo " all runs core services: bus, audio, skills, voice"
|
||||
echo " debug runs core services, then starts the CLI"
|
||||
echo
|
||||
echo "Services:"
|
||||
echo " audio the audio playback service"
|
||||
echo " bus the messagebus service"
|
||||
echo " skills the skill service"
|
||||
echo " voice voice capture service"
|
||||
echo " wifi wifi setup service"
|
||||
echo " enclosure mark_1 enclosure service"
|
||||
echo
|
||||
echo "Tools:"
|
||||
echo " cli the Command Line Interface"
|
||||
echo " unittest run mycroft-core unit tests (requires pytest)"
|
||||
echo " skillstest run the skill autotests for all skills (requires pytest)"
|
||||
echo
|
||||
echo "Utils:"
|
||||
echo " audiotest attempt simple audio validation"
|
||||
echo " audioaccuracytest more complex audio validation"
|
||||
echo " sdkdoc generate sdk documentation"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " ${script} all"
|
||||
echo " ${script} cli"
|
||||
echo " ${script} unittest"
|
||||
echo "${script}: Mycroft command/service launcher"
|
||||
echo "usage: ${script} [command] [params]"
|
||||
echo
|
||||
echo "Services:"
|
||||
echo " all runs core services: bus, audio, skills, voice"
|
||||
echo " debug runs core services, then starts the CLI"
|
||||
echo
|
||||
echo "Services:"
|
||||
echo " audio the audio playback service"
|
||||
echo " bus the messagebus service"
|
||||
echo " skills the skill service"
|
||||
echo " voice voice capture service"
|
||||
echo " wifi wifi setup service"
|
||||
echo " enclosure mark_1 enclosure service"
|
||||
echo
|
||||
echo "Tools:"
|
||||
echo " cli the Command Line Interface"
|
||||
echo " unittest run mycroft-core unit tests (requires pytest)"
|
||||
echo " skillstest run the skill autotests for all skills (requires pytest)"
|
||||
echo
|
||||
echo "Utils:"
|
||||
echo " audiotest attempt simple audio validation"
|
||||
echo " audioaccuracytest more complex audio validation"
|
||||
echo " sdkdoc generate sdk documentation"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " ${script} all"
|
||||
echo " ${script} cli"
|
||||
echo " ${script} unittest"
|
||||
|
||||
exit 1
|
||||
exit 1
|
||||
}
|
||||
|
||||
_script=""
|
||||
function name-to-script-path() {
|
||||
case ${1} in
|
||||
"bus") _script=${DIR}/mycroft/messagebus/service/main.py ;;
|
||||
"skills") _script=${DIR}/mycroft/skills/main.py ;;
|
||||
"audio") _script=${DIR}/mycroft/audio/main.py ;;
|
||||
"voice") _script=${DIR}/mycroft/client/speech/main.py ;;
|
||||
"cli") _script=${DIR}/mycroft/client/text/main.py ;;
|
||||
"wifi") _script=${DIR}/mycroft/client/wifisetup/main.py ;;
|
||||
"audioaccuracytest") _script=${DIR}/mycroft/audio-accuracy-test/audio_accuracy_test.py ;;
|
||||
"sdkdoc") _script=${DIR}/doc/generate_sdk_docs.py ;;
|
||||
"enclosure") _script=${DIR}/mycroft/client/enclosure/main.py ;;
|
||||
"bus") _script=${DIR}/mycroft/messagebus/service/main.py ;;
|
||||
"skills") _script=${DIR}/mycroft/skills/main.py ;;
|
||||
"audio") _script=${DIR}/mycroft/audio/main.py ;;
|
||||
"voice") _script=${DIR}/mycroft/client/speech/main.py ;;
|
||||
"cli") _script=${DIR}/mycroft/client/text/main.py ;;
|
||||
"wifi") _script=${DIR}/mycroft/client/wifisetup/main.py ;;
|
||||
"audioaccuracytest") _script=${DIR}/mycroft/audio-accuracy-test/audio_accuracy_test.py ;;
|
||||
"sdkdoc") _script=${DIR}/doc/generate_sdk_docs.py ;;
|
||||
"enclosure") _script=${DIR}/mycroft/client/enclosure/main.py ;;
|
||||
|
||||
*)
|
||||
echo "Error: Unknown name '${1}'"
|
||||
exit 1
|
||||
*)
|
||||
echo "Error: Unknown name '${1}'"
|
||||
exit 1
|
||||
esac
|
||||
}
|
||||
|
||||
function source-venv() {
|
||||
# Enter Python virtual environment, unless under Docker
|
||||
if [ ! -f "/.dockerenv" ]; then
|
||||
if [ ! -f "/.dockerenv" ] ; then
|
||||
source ${VIRTUALENV_ROOT}/bin/activate
|
||||
fi
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ function launch-background() {
|
|||
name-to-script-path ${1}
|
||||
|
||||
# Check if already running
|
||||
if [[ $( ps aux ) = *${_script}* ]] ; then
|
||||
if [[ $( ps aux ) == *${_script}* ]] ; then
|
||||
echo "Restarting: ${1}"
|
||||
source stop-mycroft.sh ${1}
|
||||
else
|
||||
|
@ -119,7 +119,7 @@ function launch-background() {
|
|||
fi
|
||||
|
||||
# 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 " measures. You are responsible for protecting the local port"
|
||||
echo " 8181 with a firewall as appropriate."
|
||||
|
@ -139,7 +139,7 @@ function launch-all() {
|
|||
# Determine platform type
|
||||
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
||||
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
|
||||
launch-background enclosure
|
||||
fi
|
||||
|
@ -147,9 +147,9 @@ function launch-all() {
|
|||
}
|
||||
|
||||
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."
|
||||
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"
|
||||
fi
|
||||
fi
|
||||
|
@ -162,57 +162,57 @@ _params=$@
|
|||
check-dependencies
|
||||
|
||||
case ${_opt} in
|
||||
"all")
|
||||
launch-all
|
||||
;;
|
||||
"all")
|
||||
launch-all
|
||||
;;
|
||||
|
||||
"bus")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"audio")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"skills")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"voice")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"bus")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"audio")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"skills")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"voice")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
|
||||
"debug")
|
||||
launch-all
|
||||
launch-process cli
|
||||
;;
|
||||
"debug")
|
||||
launch-all
|
||||
launch-process cli
|
||||
;;
|
||||
|
||||
"cli")
|
||||
launch-process ${_opt}
|
||||
;;
|
||||
"wifi")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"unittest")
|
||||
source-venv
|
||||
pytest test/unittests/ --cov=mycroft "$@"
|
||||
;;
|
||||
"skillstest")
|
||||
source-venv
|
||||
pytest test/integrationtests/skills/discover_tests.py "$@"
|
||||
;;
|
||||
"audiotest")
|
||||
source-venv
|
||||
python3 -m mycroft.util.audio_test "${@:1}"
|
||||
;;
|
||||
"audioaccuracytest")
|
||||
launch-process ${_opt}
|
||||
;;
|
||||
"sdkdoc")
|
||||
launch-process ${_opt}
|
||||
;;
|
||||
"enclosure")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"cli")
|
||||
launch-process ${_opt}
|
||||
;;
|
||||
"wifi")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
"unittest")
|
||||
source-venv
|
||||
pytest test/unittests/ --cov=mycroft "$@"
|
||||
;;
|
||||
"skillstest")
|
||||
source-venv
|
||||
pytest test/integrationtests/skills/discover_tests.py "$@"
|
||||
;;
|
||||
"audiotest")
|
||||
source-venv
|
||||
python3 -m mycroft.util.audio_test "${@:1}"
|
||||
;;
|
||||
"audioaccuracytest")
|
||||
launch-process ${_opt}
|
||||
;;
|
||||
"sdkdoc")
|
||||
launch-process ${_opt}
|
||||
;;
|
||||
"enclosure")
|
||||
launch-background ${_opt}
|
||||
;;
|
||||
|
||||
*)
|
||||
help
|
||||
;;
|
||||
*)
|
||||
help
|
||||
;;
|
||||
esac
|
||||
|
|
108
stop-mycroft.sh
108
stop-mycroft.sh
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2017 Mycroft AI Inc.
|
||||
#
|
||||
|
@ -23,23 +23,23 @@ SCRIPTS="$DIR/scripts"
|
|||
mkdir -p $SCRIPTS/logs
|
||||
|
||||
function help() {
|
||||
echo "${script}: Mycroft service stopper"
|
||||
echo "usage: ${script} [service]"
|
||||
echo
|
||||
echo "Service:"
|
||||
echo " all ends core services: bus, audio, skills, voice"
|
||||
echo " (none) same as \"all\""
|
||||
echo " bus stop the Mycroft messagebus service"
|
||||
echo " audio stop the audio playback service"
|
||||
echo " skills stop the skill service"
|
||||
echo " voice stop voice capture service"
|
||||
echo " enclosure stop mark_1 enclosure service"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " ${script}"
|
||||
echo " ${script} audio"
|
||||
echo "${script}: Mycroft service stopper"
|
||||
echo "usage: ${script} [service]"
|
||||
echo
|
||||
echo "Service:"
|
||||
echo " all ends core services: bus, audio, skills, voice"
|
||||
echo " (none) same as \"all\""
|
||||
echo " bus stop the Mycroft messagebus service"
|
||||
echo " audio stop the audio playback service"
|
||||
echo " skills stop the skill service"
|
||||
echo " voice stop voice capture service"
|
||||
echo " enclosure stop mark_1 enclosure service"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " ${script}"
|
||||
echo " ${script} audio"
|
||||
|
||||
exit 1
|
||||
exit 1
|
||||
}
|
||||
|
||||
function process-running() {
|
||||
|
@ -51,14 +51,12 @@ function process-running() {
|
|||
}
|
||||
|
||||
function end-process() {
|
||||
|
||||
if process-running $1 ; then
|
||||
pid=$( ps aux | grep "python3\? .*${1}/main.py" | awk '{print $2}' )
|
||||
kill -SIGINT ${pid}
|
||||
|
||||
c=1
|
||||
while [ $c -le 20 ]
|
||||
do
|
||||
while [ $c -le 20 ] ; do
|
||||
if process-running $1 ; then
|
||||
sleep 0.1
|
||||
(( c++ ))
|
||||
|
@ -76,47 +74,45 @@ function end-process() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
OPT=$1
|
||||
shift
|
||||
|
||||
case ${OPT} in
|
||||
"all")
|
||||
;&
|
||||
"")
|
||||
echo "Stopping all mycroft-core services"
|
||||
end-process service
|
||||
end-process skills
|
||||
end-process audio
|
||||
end-process speech
|
||||
"all")
|
||||
;&
|
||||
"")
|
||||
echo "Stopping all mycroft-core services"
|
||||
end-process service
|
||||
end-process skills
|
||||
end-process audio
|
||||
end-process speech
|
||||
|
||||
# determine platform type
|
||||
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
||||
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
|
||||
if [[ $mycroft_platform = 'mycroft_mark_1' ]] ; then
|
||||
# running on a Mark 1, stop enclosure service
|
||||
end-process enclosure
|
||||
# determine platform type
|
||||
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
|
||||
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
|
||||
if [[ $mycroft_platform == "mycroft_mark_1" ]] ; then
|
||||
# running on a Mark 1, stop enclosure service
|
||||
end-process enclosure
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
"bus")
|
||||
end-process service
|
||||
;;
|
||||
"audio")
|
||||
end-process audio
|
||||
;;
|
||||
"skills")
|
||||
end-process skills
|
||||
;;
|
||||
"voice")
|
||||
end-process speech
|
||||
;;
|
||||
"enclosure")
|
||||
end-process enclosure
|
||||
;;
|
||||
;;
|
||||
"bus")
|
||||
end-process service
|
||||
;;
|
||||
"audio")
|
||||
end-process audio
|
||||
;;
|
||||
"skills")
|
||||
end-process skills
|
||||
;;
|
||||
"voice")
|
||||
end-process speech
|
||||
;;
|
||||
"enclosure")
|
||||
end-process enclosure
|
||||
;;
|
||||
|
||||
|
||||
*)
|
||||
help
|
||||
;;
|
||||
*)
|
||||
help
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright 2018 Mycroft AI Inc.
|
||||
#
|
||||
|
@ -19,7 +19,7 @@
|
|||
# necessary to run unit tests or to interact directly with mycroft-core
|
||||
# via an interactive Python shell.
|
||||
|
||||
if [ "$0" = "$BASH_SOURCE" ] ; then
|
||||
if [ "$0" == "$BASH_SOURCE" ] ; then
|
||||
# Prevent running in script then exiting immediately
|
||||
echo "ERROR: Invoke with 'source venv-activate.sh' or '. venv-activate.sh'"
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue