Standardize shell scripts (#1711)

* Standardize shebangs
* Standardize spaces
* Standardize functions declaration
* Standardize conditional constructs
* Standardize double quotes
* Standardize command substitution
* Standardize sed command
pull/1712/head
Julien Kassar 2018-08-02 15:48:47 -04:00 committed by Steve Penrod
parent e482254172
commit ed556b09df
10 changed files with 417 additions and 432 deletions

View File

@ -41,7 +41,7 @@
# exit on any error
set -Ee
show_help() {
function show_help() {
echo "dev_setup.sh: Mycroft development environment setup"
echo "Usage: dev_setup.sh [options]"
echo
@ -58,8 +58,7 @@ show_help() {
opt_skipmimic=false
opt_allowroot=false
for var in "$@"
do
for var in "$@" ; do
if [[ ${var} == "-h" ]] || [[ ${var} == "--help" ]] ; then
show_help
exit 0
@ -80,20 +79,20 @@ if [ $(id -u) -eq 0 ] && [ "${opt_allowroot}" != true ] ; then
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,9 +133,9 @@ 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=""
@ -145,8 +144,8 @@ else
fi
# in not, check the system path
if [ "$has_mimic" = "" ] ; then
if [ -x "$(command -v mimic)" ]; then
if [ "$has_mimic" == "" ] ; then
if [ -x "$(command -v mimic)" ] ; then
has_mimic="$( mimic -lv | grep Voice )" || true
fi
fi
@ -157,7 +156,7 @@ else
fi
fi
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ]; then
if [ ! -x "${VIRTUALENV_ROOT}/bin/activate" ] ; then
install_venv
fi
@ -178,7 +177,7 @@ 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
if ! grep -q "$TOP" $VENV_PATH_FILE ; then
echo "Adding mycroft-core to virtualenv path"
sed -i.tmp '1 a\
'"$TOP"'
@ -186,7 +185,7 @@ if ! grep -q "$TOP" $VENV_PATH_FILE; then
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,24 +193,24 @@ if ! pip install -r requirements.txt; then
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..."
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
if [[ ${MAXCORES} -lt 1 ]] ; then
MAXCORES=${MINCORES}
fi
# look for positive integer
if ! [[ ${CORES} =~ ^[0-9]+$ ]]; then
if ! [[ ${CORES} =~ ^[0-9]+$ ]] ; then
CORES=${MINCORES}
elif [[ ${MAXCORES} -lt ${CORES} ]]; then
elif [[ ${MAXCORES} -lt ${CORES} ]] ; then
CORES=${MAXCORES}
fi
@ -223,7 +222,7 @@ echo "Building with $CORES cores."
#build and install mimic
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!"
"${TOP}/scripts/install-mimic.sh" " ${CORES}"
else

View File

@ -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

View File

@ -20,17 +20,17 @@ 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 disable_local() {
sed -i 's/from pocketsphinx import Decoder/from pocketsphinx.pocketsphinx import Decoder/g' mycroft/client/speech/local_recognizer.py
}
function install_pocketsphinx {
function install_pocketsphinx() {
# clone pocketsphinx-python at HEAD (fix to a constant version later)
if [ ! -d ${TOP}/pocketsphinx-python ]; then
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
@ -48,10 +48,9 @@ function install_pocketsphinx {
# build and install pocketsphinx python bindings
cd ${TOP}/pocketsphinx-python
python setup.py install
}
if [ "$1" = "-q" ]; then
if [ "$1" = "-q" ] ; then
enable_local
install_pocketsphinx
exit 0
@ -61,8 +60,7 @@ echo "This script will checkout, compile, and install pocketsphinx locally if th
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

View File

@ -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

View File

@ -20,9 +20,9 @@
# To do: functionalize and allow for parametereized calls of each.
# rs 2017-05-05
helpfunc() {
echo "Usage: ${0} [FUNCTION]"
echo " Functions include
function helpfunc() {
echo "Usage: ${0} [FUNCTION]"
echo " Functions include
-v version
-P python
-p permissions
@ -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?
@ -88,70 +88,70 @@ 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
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." ;;
"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
else
mlog " = Error: permission checks skipped while running as root."
fi
rm -f /tmp/my-list.$$
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
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
fi
}
# pythoning!
checkPIP () {
mlog "Python checks"
mlog " - Verifying ${MYCROFT_HOME}/requirements.txt:"
if workon mycroft ; then
function checkPIP() {
mlog "Python checks"
mlog " - Verifying ${MYCROFT_HOME}/requirements.txt:"
if workon mycroft ; then
pip list > /tmp/mycroft-piplist.$$
while read reqline; do
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
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})"
@ -161,40 +161,40 @@ if workon mycroft ; then
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 () {
function checktubes() {
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!";;
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
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
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)
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
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
fi
}
# ok, fine, go ahead and run this crazy thing
@ -214,7 +214,7 @@ 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
@ -249,4 +249,3 @@ while [[ $# -gt 0 ]] ; do
done
exit 0

View File

@ -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"
@ -34,21 +34,20 @@ mycroft_platform="null"
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
mycroft_platform=$( jq -r '.enclosure.platform' /etc/mycroft/mycroft.conf )
else
if [[ "$(hostname)" == "picroft" ]] ; then
if [[ "$( hostname )" == "picroft" ]] ; then
mycroft_platform="picroft"
elif [[ "$(hostname)" =~ "mark_1" ]] ; then
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/
@ -248,12 +246,12 @@ function unstable_to_stable_server {
# 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?"
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
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"
@ -261,10 +259,10 @@ function unstable_to_stable_server {
# 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"

View File

@ -14,13 +14,13 @@
# 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
while [ -h "$SOURCE" ] ; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
@ -38,19 +38,19 @@ function change_ownership {
}
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

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2017 Mycroft AI Inc.
#
@ -79,7 +79,7 @@ function name-to-script-path() {
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

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2017 Mycroft AI Inc.
#
@ -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,7 +74,6 @@ function end-process() {
}
OPT=$1
shift
@ -93,7 +90,7 @@ case ${OPT} in
# 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, stop enclosure service
end-process enclosure
fi
@ -115,7 +112,6 @@ case ${OPT} in
end-process enclosure
;;
*)
help
;;

View File

@ -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