agent_gsm/setup/setup_agent_gsm.sh

109 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
# Refresh apt database
sudo apt update
# Installation directory
INSTALL_DIR=agent_gsm
# Re
GIT_SOURCE=https://git.sevana.biz/public/agent_gsm
# Install prerequisites
sudo apt install --assume-yes git mc python3 sox vim libffi-dev screen python3-pip python3-numpy dnsmasq hostapd screen
sudo pip3 install pyyaml sox pyrabbit soundfile dbus_python pexpect requests rabbitpy bottle --break-system-packages
if [ -f "$INSTALL_DIR" ]; then
rm -rf "$INSTALL_DIR"
fi
# Anonymous cloning
git clone $GIT_SOURCE $INSTALL_DIR
# Go to cloned directory
cd $INSTALL_DIR
# Update config file
BACKEND_URL=""
PHONE_NAME=""
TASK_NAME=""
# Backend URL
read -p "Please specify backend URL [https://gsm.sevana.biz] ): " BACKEND_URL
BACKEND_URL=${BACKEND_URL:-"https://gsm.sevana.biz"}
# Device name
read -p "Please specify phone name (ex: moto_1): " PHONE_NAME
# Optional task name
read -p "Please specify expected task name (if this is answerer phone): " TASK_NAME
# Get a copy of config file from redist
cp config/agent.in.yaml config/agent.yaml
# Update mc settings to ease further work
mkdir -p ~/.config/mc
cp config/mc/ini ~/.config/mc
# Replace the values - finish preparing the agent configuration file
if [[ $BACKEND_URL != "" ]]; then
sed -i "s|BACKEND|$BACKEND|" config/agent.yaml
fi
if [[ $PHONE_NAME != "" ]]; then
sed -i "s|PHONE_NAME|$PHONE_NAME|" config/agent.yaml
fi
sed -i "s|TASK_NAME|$TASK_NAME|" config/agent.yaml
ABSOLUTE_INSTALL_DIR=`realpath .`
# Update systemD unit file
# cp config/systemd/agent_gsm.in.service config/systemd/agent_gsm.service
# sed -i "s|ABSOLUTE_INSTALL_DIR|$ABSOLUTE_INSTALL_DIR|" config/systemd/agent_gsm.service
install_ap() {
# $1 is AP name
sudo cp $ABSOLUTE_INSTALL_DIR/config/ap/etc/dhcpcd.conf /etc
sudo cp $ABSOLUTE_INSTALL_DIR/config/ap/etc/dnsmasq.conf /etc
sudo mkdir -p /etc/hostapd
sudo cp $ABSOLUTE_INSTALL_DIR/config/ap/etc/hostapd.conf /etc/hostapd
sudo sed -i "s|AGENT_GSM|$1|" /etc/hostapt/hostapd.conf
sudo cp $ABSOLUTE_INSTALL_DIR/config/ap/etc/default/hostapt /etd/default
sudo systemctl enable dnsmasq
sudo systemctl enable hostapd
sudo systemctl start dnsmasq
sudo systemctl start hostapd
}
function enable_autologin() {
sudo systemctl --quiet set-default multi-user.target
sudo cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF
}
# ToDo:
# - allow autologin in console mode for 'pi' user
enable_autologin
# - add $ABSOLUTE_INSTALL_DIR/run_agent_screen.sh to ~/.bashrc
echo "$ABSOLUTE_INSTALL_DIR/run_agent_screen.sh" >> ~/.bashrc
# - install wifi AP with name $PHONE_NAME
install_ap $PHONE_NAME
echo "Now the remaining prerequisites will be installed and system will reboot."
echo "You can connect the phone via Bluetooth after the reboot."
echo "Use the connect_phone.sh to ease the connection process. This script will ask you about Bluetooth MAC address and make attempt to pair & connect the phone. "
echo "Please run $INSTALL_DIR/run_node.sh to see if everything works ok."
echo "After you can use $INSTALL_DIR/config/systemd/agent_gsm.service to enable this work with systemD."
echo ""
# Run bootstrap app
./pi_bootstrap_bt.sh