Dennis
0d32c727fa
This commit adds a convenient installation script for Linux and also adds a description on how to install the bot. Furthermore, a very simple example plugin is added. This way, new users can easily discover the possibilities of this plugin. Finally, the default character "Peter"---which is used within Alcuinus---is removed, and a more generic character is added.
129 lines
4.2 KiB
Bash
Executable File
129 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Installation script for matrix-chatbot
|
|
#
|
|
# @author Dennis Potter <dennis@dennispotter.eu>
|
|
# @copyright 2019, Dennis Potter
|
|
# @license GNU General Public License (version 3)
|
|
#
|
|
# matrix-chatbot
|
|
#
|
|
# 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
|
|
# - create initial config.json
|
|
# - (optional) create systemd service
|
|
|
|
if [[ $1 == help ]]; then
|
|
echo "Help:"
|
|
echo "install.sh : Creates a virtualenv, an initial config.json, and installs"
|
|
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
|
|
}
|
|
|
|
#################################################################
|
|
# 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
|
|
|
|
#################################################################
|
|
# Create config.json
|
|
#################################################################
|
|
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!"
|
|
echo "############################################################################"
|
|
echo ""
|
|
|
|
if [[ -f $DIR/config.json ]]; then
|
|
read -p "$DIR/config.json already exists. Should I overwrite it? [y/n]: " ow
|
|
|
|
if [[ $ow != y ]]; then
|
|
echo "ERR: Cannot write to $DIR/config.json!"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
read -p 'Matrix homeserver: ' servervar
|
|
read -p 'Matrix username: ' uservar
|
|
read -p 'Matrix password: ' passvar
|
|
|
|
sed -e "s/\${servervar}/${servervar}/"\
|
|
-e "s/\${uservar}/${uservar}/"\
|
|
-e "s/\${passvar}/${passvar}/"\
|
|
$DIR/config.json.template > $DIR/config.json
|
|
|
|
#################################################################
|
|
# Configure service
|
|
#################################################################
|
|
if [[ $1 != service ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
sudo useradd -r mchatbot
|
|
|
|
sed -e "s/\${DIR}/${DIR}/"\
|
|
$DIR/matrix-chatbot.service.template > $DIR/matrix-chatbot.service
|
|
|
|
sudo mv $DIR/matrix-chatbot.service /etc/systemd/system/matrix-chatbot.service
|
|
|
|
sudo systemctl enable matrix-chatbot.service
|
|
sudo systemctl start matrix-chatbot.service
|