autoupdate feature

This commit is contained in:
Azlux 2019-06-04 02:23:28 +02:00
parent 4f585952c7
commit a9824537e9
5 changed files with 63 additions and 17 deletions

View File

@ -12,10 +12,11 @@ Bot the can play :
## Menu ## Menu
1. [Web Interface](#web-interface) 1. [Web Interface](#web-interface)
2. [Installation](#installation) 2. [Installation](#installation)
3. [Generate a certificate](#optional-generate-a-certificate) 3. [Update](#udpate)
4. [Starting the bot](#starting-the-bot) 4. [Generate a certificate](#optional-generate-a-certificate)
5. [Custom commands](#custom-commands) 5. [Starting the bot](#starting-the-bot)
6. [Contributors](#contributors) 6. [Custom commands](#custom-commands)
7. [Contributors](#contributors)
### Web interface ### Web interface
@ -29,7 +30,17 @@ You can enable the web interface into the configuration.ini file.
1. You need python 3 with opuslib and protobuf (look at the requirement of pymumble) 1. You need python 3 with opuslib and protobuf (look at the requirement of pymumble)
2. The Bot uses ffmpeg, so you know what you have to do if ffmpeg isn't in your package manager. I personally use [this repository](http://repozytorium.mati75.eu/) on my raspberry. 2. The Bot uses ffmpeg, so you know what you have to do if ffmpeg isn't in your package manager. I personally use [this repository](http://repozytorium.mati75.eu/) on my raspberry.
Example installation commands for Debian and Ubuntu: To Install botamusique (stable and build-in auto-update):
```
curl -Lo botamusique.tar.gz https://azlux.fr/botamusique/sources.tar.gz
tar -xzf botamusique.tar.gz
cd botamusique
python3 -m venv venv
venv/bin/pip install wheel
venv/bin/pip install -r requirements.txt
```
For the master version, you can use Git installation commands (no build-in auto-update allowed):
``` ```
apt install python3-venv ffmpeg libjpeg-dev zlibc zlib1g zlib1g-dev apt install python3-venv ffmpeg libjpeg-dev zlibc zlib1g zlib1g-dev
git clone --recurse-submodules https://github.com/azlux/botamusique.git git clone --recurse-submodules https://github.com/azlux/botamusique.git
@ -39,6 +50,17 @@ venv/bin/pip install wheel
venv/bin/pip install -r requirements.txt venv/bin/pip install -r requirements.txt
``` ```
### Update
If using the recommanded install, you can send to the bot `!update`(command by default)
If using git, you need to make the update manually:
```
git pull --all
git submodule update
venv/bin/pip install --upgrade -r requirements.txt
```
### (Optional) Generate a certificate ### (Optional) Generate a certificate
`$ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout botamusique.pem -out botamusique.pem -subj "/CN=botamusique"` `$ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout botamusique.pem -out botamusique.pem -subj "/CN=botamusique"`

View File

@ -5,7 +5,6 @@ import json
import http.client import http.client
import struct import struct
def get_radio_server_description(url): def get_radio_server_description(url):
p = re.compile('(https?\:\/\/[^\/]*)', re.IGNORECASE) p = re.compile('(https?\:\/\/[^\/]*)', re.IGNORECASE)
res = re.search(p, url) res = re.search(p, url)

View File

@ -55,6 +55,8 @@ type : file
user user
""" """
version = 2
class MumbleBot: class MumbleBot:
def __init__(self, args): def __init__(self, args):
@ -331,17 +333,7 @@ class MumbleBot:
if self.is_admin(user): if self.is_admin(user):
self.mumble.users[text.actor].send_text_message("Starting the update") self.mumble.users[text.actor].send_text_message("Starting the update")
# Need to be improved # Need to be improved
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode() msg = util.update(version)
msg = ""
if "Requirement already up-to-date" in tp:
msg += "Youtube-dl is up-to-date"
else:
msg += "Update done : " + tp.split('Successfully installed')[1]
if 'up-to-date' not in sp.check_output(['/usr/bin/env', 'git', 'pull']).decode():
# Need to change it with release tag
msg += "<br /> I'm up-to-date"
else:
msg += "<br /> I have available updates, need to do it manually"
self.mumble.users[text.actor].send_text_message(msg) self.mumble.users[text.actor].send_text_message(msg)
else: else:
self.mumble.users[text.actor].send_text_message(var.config.get('strings', 'not_admin')) self.mumble.users[text.actor].send_text_message(var.config.get('strings', 'not_admin'))
@ -697,6 +689,13 @@ if __name__ == '__main__':
db = configparser.ConfigParser(interpolation=None, allow_no_value=True, delimiters='²') db = configparser.ConfigParser(interpolation=None, allow_no_value=True, delimiters='²')
db.read(var.dbfile, encoding='latin-1') db.read(var.dbfile, encoding='latin-1')
if 'url_ban' not in db.sections():
db.add_section('url_ban')
if 'bot' not in db.sections():
db.add_section('bot')
if 'user_ban' not in db.sections():
db.add_section('user_ban')
if len(parsed_configs) == 0: if len(parsed_configs) == 0:
logging.error('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr) logging.error('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr)
sys.exit() sys.exit()

5
update.sh Normal file
View File

@ -0,0 +1,5 @@
curl -Lo /tmp/botamusique.tar.gz https://azlux.fr/botamusique/sources.tar.gz
tar -xzf /tmp/botamusique.tar.gz -C /tmp/botamusique
cp -r /tmp/botamusique/* .
rm -r /tmp/botamusique
rm -r /tmp/botamusique.tar.gz

21
util.py
View File

@ -5,6 +5,9 @@ import magic
import os import os
import variables as var import variables as var
import zipfile import zipfile
import urllib.request
import subprocess as sp
import logging
def get_recursive_filelist_sorted(path): def get_recursive_filelist_sorted(path):
@ -78,6 +81,24 @@ def get_user_ban():
return res return res
def update(version):
v = int(urllib.request.urlopen(urllib.request.Request("https://azlux.fr/botamusique/version")).read())
if v > version:
logging.info('New version, starting update')
tp = sp.check_output(['/usr/bin/env', 'bash', 'update.sh']).decode()
logging.debug(tp)
msg = "New version installed"
else:
logging.info('Starting update youtube-dl via pip3')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode()
msg = ""
if "Requirement already up-to-date" in tp:
msg += "Youtube-dl is up-to-date"
else:
msg += "Update done : " + tp.split('Successfully installed')[1]
return msg
def user_ban(user): def user_ban(user):
var.db.set("user_ban", user, None) var.db.set("user_ban", user, None)
res = "User " + user + " banned" res = "User " + user + " banned"