2019-01-12 14:13:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2019-01-12 17:02:34 +00:00
|
|
|
# Installation script for plugable-matrix-bot
|
2019-01-12 14:13:21 +00:00
|
|
|
#
|
|
|
|
# @author Dennis Potter <dennis@dennispotter.eu>
|
|
|
|
# @copyright 2019, Dennis Potter
|
|
|
|
# @license GNU General Public License (version 3)
|
|
|
|
#
|
2019-01-12 17:02:34 +00:00
|
|
|
# plugable-matrix-bot
|
2019-01-12 14:13:21 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##################################################################################
|
|
|
|
|
|
|
|
# This script does the following:
|
|
|
|
# - create virtualenv
|
|
|
|
# - install requirements of main bot
|
2019-01-14 22:47:38 +00:00
|
|
|
# - create initial config.hjson
|
2019-01-12 14:13:21 +00:00
|
|
|
# - (optional) create systemd service
|
|
|
|
|
|
|
|
if [[ $1 == help ]]; then
|
|
|
|
echo "Help:"
|
2019-01-14 22:47:38 +00:00
|
|
|
echo "install.sh : Creates a virtualenv, an initial config.hjson, and installs"
|
2019-01-12 14:13:21 +00:00
|
|
|
echo " all required packages"
|
|
|
|
echo "install.sh service: Runs ./install and additionally adds a systemd service."
|
|
|
|
echo " This command will ask you for root credentials!"
|
|
|
|
echo "install.sh help : Prints this message."
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Define directory of chatbot
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
|
|
|
|
# Check if user is superuser
|
|
|
|
if [[ "$EUID" -eq 0 ]]; then
|
|
|
|
echo "ERR: Please do not run this script as super user!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# Create function to check availability of software
|
|
|
|
#################################################################
|
|
|
|
function availability {
|
|
|
|
if [[ ! $(command -v $1) ]]; then
|
|
|
|
echo "ERR: '$1' is not available but required. Please install it!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-02-02 12:31:17 +00:00
|
|
|
#################################################################
|
|
|
|
# Initiliaze submodules
|
|
|
|
#################################################################
|
|
|
|
git submodule update --init
|
|
|
|
|
2019-01-12 14:13:21 +00:00
|
|
|
#################################################################
|
|
|
|
# Create virtualenv
|
|
|
|
#################################################################
|
|
|
|
# Check whether virtualenv is present
|
|
|
|
availability virtualenv
|
|
|
|
|
|
|
|
# Create virtualenv
|
|
|
|
virtualenv $DIR
|
|
|
|
|
|
|
|
# Enter virtualenv
|
|
|
|
source $DIR/bin/activate
|
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# Install requirements
|
|
|
|
#################################################################
|
|
|
|
# Check whether pip3 is present
|
|
|
|
availability pip3
|
|
|
|
|
|
|
|
# Install requirements
|
|
|
|
pip3 install -r requirements.txt
|
|
|
|
|
|
|
|
#################################################################
|
2019-01-14 22:47:38 +00:00
|
|
|
# Create config.hjson
|
2019-01-12 14:13:21 +00:00
|
|
|
#################################################################
|
|
|
|
echo ""
|
|
|
|
echo "############################################################################"
|
|
|
|
echo "This step will generate a configuration file. The resulting bot will be very"
|
|
|
|
echo "simple and is only able to respond to the message "Hello bot". However, it"
|
|
|
|
echo "forms the perfect base for further development."
|
|
|
|
echo ""
|
|
|
|
echo "In the following steps, an _existing_ user must be provided. If you did not"
|
|
|
|
echo "yet create a user for your bot, please do so now!"
|
2019-01-12 17:02:34 +00:00
|
|
|
echo ""
|
|
|
|
echo "The installation procedure will also ask you to define a super user. A super"
|
|
|
|
echo "user is a normal user that can manage the bot. This SU is passed on to all"
|
|
|
|
echo "plugins."
|
2019-01-12 14:13:21 +00:00
|
|
|
echo "############################################################################"
|
|
|
|
echo ""
|
|
|
|
|
2019-01-14 22:47:38 +00:00
|
|
|
if [[ -f $DIR/config.hjson ]]; then
|
|
|
|
read -p "$DIR/config.hjson already exists. Should I overwrite it? [y/n]: " ow
|
2019-01-12 14:13:21 +00:00
|
|
|
|
|
|
|
if [[ $ow != y ]]; then
|
2019-01-14 22:47:38 +00:00
|
|
|
echo "ERR: Cannot write to $DIR/config.hjson!"
|
2019-01-12 14:13:21 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-01-12 17:02:34 +00:00
|
|
|
read -p 'Matrix homeserver: ' server
|
|
|
|
read -p 'Matrix username: ' username
|
|
|
|
read -p 'Matrix password: ' password
|
|
|
|
read -p 'Super user: ' superuser
|
2019-01-12 14:13:21 +00:00
|
|
|
|
2019-01-12 17:20:39 +00:00
|
|
|
sed -e "s|\${server}|${server}|"\
|
|
|
|
-e "s|\${username}|${username}|"\
|
|
|
|
-e "s|\${password}|${password}|"\
|
|
|
|
-e "s|\${superuser}|${superuser}|"\
|
2019-01-14 22:47:38 +00:00
|
|
|
$DIR/config.hjson.template > $DIR/config.hjson
|
2019-01-12 14:13:21 +00:00
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# Configure service
|
|
|
|
#################################################################
|
|
|
|
if [[ $1 != service ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo useradd -r mchatbot
|
|
|
|
|
2019-01-12 17:20:39 +00:00
|
|
|
sed -e "s|\${DIR}|${DIR}|"\
|
2019-01-12 17:02:34 +00:00
|
|
|
$DIR/plugable-matrix-bot.service.template > $DIR/plugable-matrix-bot.service
|
2019-01-12 14:13:21 +00:00
|
|
|
|
2019-01-12 17:02:34 +00:00
|
|
|
sudo mv $DIR/plugable-matrix-bot.service /etc/systemd/system/plugable-matrix-bot.service
|
2019-01-12 14:13:21 +00:00
|
|
|
|
2019-01-12 17:02:34 +00:00
|
|
|
sudo systemctl enable plugable-matrix-bot.service
|
|
|
|
sudo systemctl start plugable-matrix-bot.service
|