150 lines
3.3 KiB
Bash
Executable File
150 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# fail on error , debug all lines
|
|
# set -eu -o pipefail
|
|
|
|
cecho () {
|
|
|
|
declare -A colors;
|
|
colors=(\
|
|
['black']='\E[0;47m'\
|
|
['red']='\E[0;31m'\
|
|
['green']='\E[0;32m'\
|
|
['yellow']='\E[0;33m'\
|
|
['blue']='\E[0;34m'\
|
|
['magenta']='\E[0;35m'\
|
|
['cyan']='\E[0;36m'\
|
|
['white']='\E[0;37m'\
|
|
);
|
|
|
|
local defaultMSG="No message passed.";
|
|
local defaultColor="black";
|
|
local defaultNewLine=true;
|
|
|
|
while [[ $# -gt 1 ]];
|
|
do
|
|
key="$1";
|
|
|
|
case $key in
|
|
-c|--color)
|
|
color="$2";
|
|
shift;
|
|
;;
|
|
-n|--noline)
|
|
newLine=false;
|
|
;;
|
|
*)
|
|
# unknown option
|
|
;;
|
|
esac
|
|
shift;
|
|
done
|
|
|
|
message=${1:-$defaultMSG}; # Defaults to default message.
|
|
color=${color:-$defaultColor}; # Defaults to default color, if not specified.
|
|
newLine=${newLine:-$defaultNewLine};
|
|
|
|
echo -en "${colors[$color]}";
|
|
echo -en "$message";
|
|
if [ "$newLine" = true ] ; then
|
|
echo;
|
|
fi
|
|
tput sgr0; # Reset text attributes to normal without clearing screen.
|
|
|
|
return;
|
|
}
|
|
|
|
warn () {
|
|
|
|
cecho -c 'yellow' "Warn: $@";
|
|
}
|
|
|
|
error () {
|
|
|
|
cecho -c 'red' "Erro: $@";
|
|
}
|
|
|
|
info () {
|
|
|
|
cecho -c 'green' "Info: $@";
|
|
}
|
|
|
|
################################################################################
|
|
###
|
|
############### function to disable Raspberry Pi onboard bluetooth #############
|
|
###
|
|
################################################################################
|
|
function disable-onboard-bluetooth()
|
|
{
|
|
info "Disabling onboard bluetooth"
|
|
isInFile=$(cat /etc/modprobe.d/raspi-blacklist.conf | grep -c "blacklist btbcm")
|
|
if [ $isInFile -eq 0 ]; then
|
|
sudo bash -c 'echo "blacklist btbcm" >> /etc/modprobe.d/raspi-blacklist.conf'
|
|
fi
|
|
isInFile=$(cat /etc/modprobe.d/raspi-blacklist.conf | grep -c "blacklist hci_uart")
|
|
if [ $isInFile -eq 0 ]; then
|
|
sudo bash -c 'echo "blacklist hci_uart" >> /etc/modprobe.d/raspi-blacklist.conf'
|
|
fi
|
|
}
|
|
|
|
function install-prerequisites()
|
|
{
|
|
info 'installing the must-have pre-requisites'
|
|
|
|
sudo apt-get install -y ofono
|
|
if [ $? != 0 ]; then
|
|
sudo apt-get install ./bin/ofono_1.21-1_armhf.deb -y
|
|
sudo apt-get install ./bin/libasound2-plugins_1.1.8-1_armhf.deb -y
|
|
sudo apt-get install ./bin/rtkit_0.11-6_armhf.deb -y
|
|
fi
|
|
|
|
while read -r p ; do sudo apt-get install -y $p ; done < <(cat << "EOF"
|
|
pulseaudio
|
|
pulseaudio-module-bluetooth
|
|
EOF
|
|
)
|
|
}
|
|
|
|
function remove-pkg()
|
|
{
|
|
info 'rempving bluealsa'
|
|
sudo apt-get purge bluealsa -y
|
|
}
|
|
|
|
function enable-headset-ofono()
|
|
{
|
|
info 'enable headset ofono'
|
|
sudo sed -i '/^load-module module-bluetooth-discover/ s/$/ headset=ofono/' /etc/pulse/default.pa
|
|
}
|
|
|
|
function install_python_pkg()
|
|
{
|
|
info 'installing python libraries'
|
|
pip install pexpect
|
|
pip3 install pexpect rabbitmq sox soundfile pyyaml
|
|
}
|
|
|
|
# main
|
|
|
|
sudo -n true
|
|
test $? -eq 0 || exit 1 "you should have sudo priveledge to run this script"
|
|
|
|
#
|
|
disable-onboard-bluetooth
|
|
install-prerequisites
|
|
remove-pkg
|
|
enable-headset-ofono
|
|
install_python_pkg
|
|
|
|
# Disable sleep on wifi connection
|
|
sudo iw wlan0 set power_save off
|
|
|
|
echo installing the nice-to-have pre-requisites
|
|
echo you have 5 seconds to reboot
|
|
echo or
|
|
echo hit Ctrl+C to quit
|
|
echo -e "\n"
|
|
sleep 5
|
|
|
|
sudo reboot
|