From 1fd125aa2c08d93ddb74724ca1cdd340f5b380ed Mon Sep 17 00:00:00 2001 From: topkecleon Date: Tue, 6 Sep 2016 20:34:57 -0400 Subject: [PATCH 1/9] Add Lua 5.2 compatibility. --- README.md | 8 ++++---- install-dependencies.sh | 32 ++++++++++++++++++-------------- launch.sh | 17 +++++++++++++---- otouto/plugins/luarun.lua | 19 +++++++++++-------- otouto/utilities.lua | 6 ++++-- tg-install.sh | 3 +-- 6 files changed, 51 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 29af4a6..5622e43 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ otouto (including all plugins and documentation) is free software; you are free ## Setup To get your bot running as soon as possible, see [Quick start](#quick-start). -otouto uses Lua 5.3 and the following Lua libraries: luasocket, luasec, multipart-post, dkjson, and lpeg. It is recommended you install these with Luarocks. This can be done easily on Ubuntu 16.04 and later with the `install-dependencies.sh` script. +otouto uses Lua (5.3 is recommended) and the following Lua libraries: luasocket, luasec, multipart-post, dkjson, and lpeg. If you are using Lua 5.2, luautf8 is also required. It is recommended you install these with Luarocks. This can be done easily on Ubuntu with the `install-dependencies.sh` script. To get started, clone the repository and set the following values in `config.lua`: @@ -29,7 +29,7 @@ To get started, clone the repository and set the following values in `config.lua Some plugins are not enabled by default. If you wish to enable them, add their names (sans file extension) to the `plugins` table in the configuration file. -When you are ready to start the bot, run the `launch.sh` script. This script will automatically restart the bot five seconds after being stopped. If this behavior is undesired, start the bot manually with `lua5.3 main.lua`. +When you are ready to start the bot, run the `launch.sh` script. This script will automatically restart the bot five seconds after being stopped. If this behavior is undesired, start the bot manually with `lua main.lua`. To stop the bot, send "/halt" through Telegram. You can exit with Ctrl-C (or two Ctrl-C if using `launch.sh`), but this is not recommended as it risks data loss. @@ -38,11 +38,11 @@ Note that certain plugins, such as `translate.lua` and `greetings.lua`, will req ### Quick start 1. Clone the repository. `git clone http://otou.to/code otouto` -2. Install dependencies: Lua 5.3, and the following Lua libs: luasocket, luasec, multipart-post, dkjson, and lpeg.† +2. Install dependencies: Lua and the following Lua libs: luasocket, luasec, multipart-post, dkjson, and lpeg.† 3. Add your bot token and Telegram ID to `config.lua`. 4. Start the bot with `./launch.sh`. -**†** On Ubuntu 16.04, this can be done easily with the `install-dependencies.sh` script. +**†** On Ubuntu, this can be done easily with the `install-dependencies.sh` script. ## Configuration otouto is configured in the `config.lua` file. It is the single point of configuration for the bot, and contains any necessary user-specific variables, such as API keys, custom error messages, and enabled plugins. diff --git a/install-dependencies.sh b/install-dependencies.sh index 4c6924d..623fe40 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -1,31 +1,35 @@ -# This script will attempt to install Lua 5.3, Luarocks (pointed at 5.3), and -# the rocks necssary to run otouto. This script targets Ubuntu 16.04; it will -# probably not work on earlier versions of Ubuntu. +# Install Lua, Luarocks, and otouto dependencies. Works in Ubuntu, maybe Debian. +# Installs Lua 5.3 if Ubuntu 16.04. Otherwise, 5.2. #!/bin/sh -echo "This script is intended for Ubuntu 16.04 and later. It will not work in" -echo "14.04 or earlier." +if [ $(lsb_release -r | cut -f 2) == "16.04" ]; then + luaver="5.3" + rocklist="luasocket luasec multipart-post lpeg dkjson" +else + luaver="5.2" + rocklist="luasocket luasec multipart-post lpeg dkjson serpent" +fi + +echo "This script is intended for Ubuntu. It may work in Debian." echo "This script will request root privileges to install the following packages:" -echo "lua5.3 liblua5.3-dev git libssl-dev fortune-mod fortunes unzip" +echo "lua$luaver liblua$luaver-dev git libssl-dev fortune-mod fortunes unzip make" echo "It will also request root privileges to install Luarocks to to /usr/local/" echo "along with the following rocks:" -echo "luasocket luasec multipart-post lpeg dkjson" +echo $rocklist echo "Press enter to continue. Use Ctrl-C to exit." read sudo apt-get update -sudo apt-get install -y lua5.3 liblua5.3-dev git libssl-dev fortune-mod fortunes unzip +sudo apt-get install -y lua$luaver liblua$luaver-dev git libssl-dev fortune-mod fortunes unzip make git clone http://github.com/keplerproject/luarocks cd luarocks -./configure --lua-version=5.3 --versioned-rocks-dir --lua-suffix=5.3 +./configure --lua-version=$luaver --versioned-rocks-dir --lua-suffix=$luaver make build sudo make install -sudo luarocks-5.3 install luasocket -sudo luarocks-5.3 install luasec -sudo luarocks-5.3 install multipart-post -sudo luarocks-5.3 install lpeg -sudo luarocks-5.3 install dkjson +for rock in $rocklist; do + sudo luarocks-$luaver install $rock +done sudo -k cd .. diff --git a/launch.sh b/launch.sh index 17e973e..6ba0265 100755 --- a/launch.sh +++ b/launch.sh @@ -1,5 +1,8 @@ -# Launch otouto, after checking for Lua 5.3. -# Restart otouto five seconds after halted. +# Run otouto in Lua 5.3, if available. +# (Specifying lua5.3 because "lua" is not linked to it in Ubuntu 16.04.) +# Otherwise, use any generic installed Lua. +# If none, give an error and a friendly suggestion. +# If Lua was found, restart otouto five seconds after halting each time. #!/bin/sh @@ -10,7 +13,13 @@ if type lua5.3 >/dev/null 2>/dev/null; then echo "otouto has stopped. ^C to exit." sleep 5s done +elif type lua >/dev/null 2>/dev/null; then + while true; do + lua main.lua + echo "otouto has stopped. ^C to exit." + sleep 5s + done else - echo "Lua 5.3 was not found." - echo "If you're on Ubuntu 16.04+, try running ./install-dependencies.sh." + echo "Lua not found." + echo "If you're on Ubuntu, try running ./install-dependencies.sh." fi diff --git a/otouto/plugins/luarun.lua b/otouto/plugins/luarun.lua index 1e5e230..6c66bd2 100644 --- a/otouto/plugins/luarun.lua +++ b/otouto/plugins/luarun.lua @@ -17,6 +17,12 @@ function luarun:init(config) return JSON.encode(t, {indent=true}) end end + -- Lua 5.2 compatibility. + -- "loadstring" was renamed "load" in 5.3. + luarun.loadstring = load or loadstring + luarun.err_msg = function(x) + return 'Error:\n' .. tostring(x) + end end function luarun:action(msg, config) @@ -35,8 +41,8 @@ function luarun:action(msg, config) input = 'return ' .. input end - local output, success = - load("local bot = require('otouto.bot')\n\z + local output, success = luarun.loadstring( + "local bot = require('otouto.bot')\n\z local bindings = require('otouto.bindings')\n\z local utilities = require('otouto.utilities')\n\z local drua = require('otouto.drua-tg')\n\z @@ -44,16 +50,13 @@ function luarun:action(msg, config) local URL = require('socket.url')\n\z local HTTP = require('socket.http')\n\z local HTTPS = require('ssl.https')\n\z - return function (self, msg, config)\n" .. input .. "\nend") - - local function err_msg(x) - return "Error:\n" .. tostring(x) - end + return function (self, msg, config)\n" .. input .. "\nend" + ) if output == nil then output = success else - success, output = xpcall(output(), err_msg, self, msg, config) + success, output = xpcall(output(), luarun.err_msg, self, msg, config) end if output == nil then diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 8461ffc..7a44f28 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -26,6 +26,9 @@ local HTTPS = require('ssl.https') local URL = require('socket.url') local JSON = require('dkjson') local bindings = require('otouto.bindings') + -- Lua 5.2 compatibility. + -- If no built-in utf8 is available, load the library. +local utf8 = utf8 or require('lua-utf8') -- For the sake of ease to new contributors and familiarity to old contributors, -- we'll provide a couple of aliases to real bindings here. @@ -324,8 +327,7 @@ end -- Converts a gross string back into proper UTF-8. -- Useful for fixing improper encoding caused by bad JSON escaping. function utilities.fix_utf8(str) - return string.char(utf8.codepoint(str, 1, -1)) + return string.char(utf8.codepoint(str, 1, -1)) end - return utilities diff --git a/tg-install.sh b/tg-install.sh index 1b6ea6c..15baf11 100755 --- a/tg-install.sh +++ b/tg-install.sh @@ -2,8 +2,7 @@ #!/bin/sh -echo "This script is intended for Ubuntu 16.04 and later. It will probably work on" -echo "14.04 or 12.04 as well as Debian, but this is not guaranteed." +echo "This script is intended for Ubuntu. It has been tested on 16.04 and 14.04." echo "This script will request root privileges to install the following packages:" echo "git libreadline-dev libssl-dev libevent-dev make" echo "Press enter to continue. Use Ctrl-C to exit." From 87ebf193362425bf86460e9497679206afaf65a5 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Tue, 6 Sep 2016 20:39:39 -0400 Subject: [PATCH 2/9] whoops --- install-dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index 623fe40..458d2c8 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -8,7 +8,7 @@ if [ $(lsb_release -r | cut -f 2) == "16.04" ]; then rocklist="luasocket luasec multipart-post lpeg dkjson" else luaver="5.2" - rocklist="luasocket luasec multipart-post lpeg dkjson serpent" + rocklist="luasocket luasec multipart-post lpeg dkjson luautf8" fi echo "This script is intended for Ubuntu. It may work in Debian." From 8c57402b2f93b687c13c7cb076407e6d800b0df2 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 15:44:34 +0200 Subject: [PATCH 3/9] =?UTF-8?q?F=C3=BCge=20Installationsskript=20f=C3=BCr?= =?UTF-8?q?=20Ubuntu=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + install-dependencies.sh | 38 ++++++++++++++++++++++++++++++++++++++ launch.sh | 8 ++++---- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100755 install-dependencies.sh diff --git a/.gitignore b/.gitignore index 6642611..b88435c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config.lua *.db tg +luarocks diff --git a/install-dependencies.sh b/install-dependencies.sh new file mode 100755 index 0000000..2180fc3 --- /dev/null +++ b/install-dependencies.sh @@ -0,0 +1,38 @@ +# Install Lua, Luarocks, and otouto dependencies. Works in Ubuntu, maybe Debian. +# Installs Lua 5.3 if Ubuntu 16.04. Otherwise, 5.2. + +#!/bin/sh + +if [ $(lsb_release -r | cut -f 2) == "16.04" ]; then + luaver="5.3" + rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent" +else + luaver="5.2" + rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent luautf8" +fi + +echo "Dieses Skript ist für Ubuntu, es wird wahrscheinlich auch für Debian funktionieren." +echo "Dieses Skript benötigt Root-Rechte, um folgende Pakete zu installieren:" +echo "lua$luaver liblua$luaver-dev git libssl-dev fortune-mod fortunes redis-server unzip make" +echo "Es werden auch Root-Rechte benötigt, um LuaRocks in /usr/local/" +echo "mit den folgenden Rocks zu installieren:" +echo $rocklist +echo "Drücke ENTER, um fortzufahren, oder Strg-C zum Beenden." +read + +sudo apt-get update +sudo apt-get install -y lua$luaver liblua$luaver-dev git libssl-dev fortune-mod fortunes redis-server unzip make +git clone http://github.com/keplerproject/luarocks +cd luarocks +./configure --lua-version=$luaver --versioned-rocks-dir --lua-suffix=$luaver +make build +sudo make install +for rock in $rocklist; do + sudo luarocks-$luaver install $rock +done +sudo -k +cd .. +cp config.lua.example config.lua + +echo "Vorgang beendet! Nutze ./launch.sh, um den Bot zu starten." +echo "Setze vorher dein Bot-Token in der config.lua." diff --git a/launch.sh b/launch.sh index c9248b7..bd9f412 100755 --- a/launch.sh +++ b/launch.sh @@ -10,16 +10,16 @@ if type lua5.3 >/dev/null 2>/dev/null; then while true; do lua5.3 main.lua - echo "Brawlbot has stopped. ^C to exit." + echo "Brawlbot wurde angehalten. ^C zum Beenden." sleep 5s done elif type lua >/dev/null 2>/dev/null; then while true; do lua main.lua - echo "Brawlbot has stopped. ^C to exit." + echo "Brawlbot wurde angehalten. ^C zum Beenden." sleep 5s done else - echo "Lua not found." - echo "If you're on Ubuntu, try running ./install-dependencies.sh." + echo "Lua nicht gefunden." + echo "Falls du Ubuntu verwendest, führe vorher ./install-dependencies.sh aus." fi From 743cd717e350eced61725f0b2c926432c45ff83b Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 15:55:57 +0200 Subject: [PATCH 4/9] =?UTF-8?q?Entfernte=20Unterst=C3=BCtzung=20f=C3=BCr?= =?UTF-8?q?=20Lua=205.3,=20da=20OAuth=20damit=20nicht=20funktioniert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install-dependencies.sh | 23 +++++++---------------- otouto/utilities.lua | 6 ++---- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index 2180fc3..2b93546 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -1,19 +1,11 @@ -# Install Lua, Luarocks, and otouto dependencies. Works in Ubuntu, maybe Debian. -# Installs Lua 5.3 if Ubuntu 16.04. Otherwise, 5.2. - #!/bin/sh +# Installiert Lua, Luarocks und andere Abhängigkeiten. Sollte auch auf Debian funktionieren. -if [ $(lsb_release -r | cut -f 2) == "16.04" ]; then - luaver="5.3" - rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent" -else - luaver="5.2" - rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent luautf8" -fi +rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent luautf8" echo "Dieses Skript ist für Ubuntu, es wird wahrscheinlich auch für Debian funktionieren." echo "Dieses Skript benötigt Root-Rechte, um folgende Pakete zu installieren:" -echo "lua$luaver liblua$luaver-dev git libssl-dev fortune-mod fortunes redis-server unzip make" +echo "lua5.2 liblua5.2-dev git libssl-dev fortune-mod fortunes redis-server unzip make" echo "Es werden auch Root-Rechte benötigt, um LuaRocks in /usr/local/" echo "mit den folgenden Rocks zu installieren:" echo $rocklist @@ -21,18 +13,17 @@ echo "Drücke ENTER, um fortzufahren, oder Strg-C zum Beenden." read sudo apt-get update -sudo apt-get install -y lua$luaver liblua$luaver-dev git libssl-dev fortune-mod fortunes redis-server unzip make +sudo apt-get install -y lua5.2 liblua5.2-dev git libssl-dev fortune-mod fortunes redis-server unzip make git clone http://github.com/keplerproject/luarocks cd luarocks -./configure --lua-version=$luaver --versioned-rocks-dir --lua-suffix=$luaver +./configure --lua-version=5.2 --versioned-rocks-dir --lua-suffix=5.2 make build sudo make install for rock in $rocklist; do - sudo luarocks-$luaver install $rock + sudo luarocks-5.2 install $rock done sudo -k cd .. -cp config.lua.example config.lua echo "Vorgang beendet! Nutze ./launch.sh, um den Bot zu starten." -echo "Setze vorher dein Bot-Token in der config.lua." +echo "Setze vorher dein Bot-Token in der config.lua.example und kopiere sie nach config.lua." diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 91a9416..733e0d3 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -20,6 +20,7 @@ local utilities = {} +utf8 = require('lua-utf8') ltn12 = require('ltn12') http = require('socket.http') https = require('ssl.https') @@ -32,9 +33,6 @@ redis = (loadfile "./otouto/redis.lua")() mime = (loadfile "./otouto/mimetype.lua")() OAuth = require "OAuth" helpers = require "OAuth.helpers" - -- Lua 5.2 compatibility. - -- If no built-in utf8 is available, load the library. -local utf8 = utf8 or require('lua-utf8') http.timeout = 5 https.timeout = 5 @@ -1107,4 +1105,4 @@ function utilities.fix_utf8(str) end -return utilities \ No newline at end of file +return utilities From 86a7bb41ed1a3c035aa76d324375f61489405311 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 16:00:13 +0200 Subject: [PATCH 5/9] Mehr Installationsanweisungen --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 290ab54..9aea600 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,9 @@ Brawlbot v2 ist freie Software; du darfst ihn modifizieren und weiterverbreiten, Ubuntu und Debian liefern Luarocks nur für Lua 5.1 aus. Um Luarocks für Lua 5.2 zu verwenden, folge bitte der [Anleitung auf StackOverflow](http://stackoverflow.com/a/20359102). ### Setup -Du benötigst **Lua 5.2+**, eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**: +Falls du Ubuntu oder Debian verwendest, kannst du einfach `./install dependencies.sh` ausführen, damit alles installiert wird. Ergänze dann noch den `bot_api_key` und die `admin`-ID (Bekommst du in Telegram mit `@Brawlbot id`) und kopiere die config.lua.example nach config.lua. + +Du benötigst **Lua 5.2** (Lua 5.3 funktioniert NICHT!), eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**: * luautf8 * luasocket * luasec @@ -185,4 +187,4 @@ Das ist die Datenbank-Struktur: `database.userdata` speichert Daten von verschiedenen Plugins, hierzu wird aber für Brawlbot-Plugins Redis verwendet. -`database.version` speichert die Bot-Version. \ No newline at end of file +`database.version` speichert die Bot-Version. From 7bd1a405c4f111ba6104b6375adef24a19c04b65 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 16:02:14 +0200 Subject: [PATCH 6/9] Moar --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9aea600..9f99a5b 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ Brawlbot v2 ist freie Software; du darfst ihn modifizieren und weiterverbreiten, # Für User ## Setup ### Ubuntu und Debian -Ubuntu und Debian liefern Luarocks nur für Lua 5.1 aus. Um Luarocks für Lua 5.2 zu verwenden, folge bitte der [Anleitung auf StackOverflow](http://stackoverflow.com/a/20359102). - -### Setup Falls du Ubuntu oder Debian verwendest, kannst du einfach `./install dependencies.sh` ausführen, damit alles installiert wird. Ergänze dann noch den `bot_api_key` und die `admin`-ID (Bekommst du in Telegram mit `@Brawlbot id`) und kopiere die config.lua.example nach config.lua. +Für eine manuelle Installation musst du LuaRocks für 5.2 [selbst kompilieren](http://stackoverflow.com/a/20359102). + +### Setup Du benötigst **Lua 5.2** (Lua 5.3 funktioniert NICHT!), eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**: * luautf8 * luasocket From e41bd82c38bf32527f3b0c981947f34a6213a10e Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 16:03:26 +0200 Subject: [PATCH 7/9] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f99a5b..0d90538 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Brawlbot v2 ist freie Software; du darfst ihn modifizieren und weiterverbreiten, # Für User ## Setup ### Ubuntu und Debian -Falls du Ubuntu oder Debian verwendest, kannst du einfach `./install dependencies.sh` ausführen, damit alles installiert wird. Ergänze dann noch den `bot_api_key` und die `admin`-ID (Bekommst du in Telegram mit `@Brawlbot id`) und kopiere die config.lua.example nach config.lua. +Falls du Ubuntu oder Debian verwendest, kannst du einfach `./install-dependencies.sh` ausführen, damit alles installiert wird. Ergänze dann noch den `bot_api_key` und die `admin`-ID (Bekommst du in Telegram mit `@Brawlbot id`) und kopiere die config.lua.example nach config.lua. Für eine manuelle Installation musst du LuaRocks für 5.2 [selbst kompilieren](http://stackoverflow.com/a/20359102). From ce9d689de644719b14e71bd8c0253b546e2f1655 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 16:16:27 +0200 Subject: [PATCH 8/9] Passe launch.sh an --- launch.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/launch.sh b/launch.sh index bd9f412..63b0124 100755 --- a/launch.sh +++ b/launch.sh @@ -1,15 +1,11 @@ -# Run Brawlbot in Lua 5.3, if available. -# (Specifying lua5.3 because "lua" is not linked to it in Ubuntu 16.04.) -# Otherwise, use any generic installed Lua. +#!/bin/sh +# Run Brawlbot. # If none, give an error and a friendly suggestion. # If Lua was found, restart Brawlbot five seconds after halting each time. -#!/bin/sh - -# Ubuntu 16.04 seems to not link "lua" to lua5.3. -if type lua5.3 >/dev/null 2>/dev/null; then +if type lua5.2 >/dev/null 2>/dev/null; then while true; do - lua5.3 main.lua + lua5.2 main.lua echo "Brawlbot wurde angehalten. ^C zum Beenden." sleep 5s done From 529ca0e923d0a8f8c1a611c9677162ac5f6cd9ce Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 7 Sep 2016 19:21:29 +0200 Subject: [PATCH 9/9] =?UTF-8?q?Installationsskript=20f=C3=BCr=20Uberspace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++ install-on-uberspace.sh | 98 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 install-on-uberspace.sh diff --git a/README.md b/README.md index 0d90538..fe7b747 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ Brawlbot v2 ist freie Software; du darfst ihn modifizieren und weiterverbreiten, * * * # Für User ## Setup +### Uberspace +Der Bot kann mit einem einfachen Installationsskript bei [Uberspace](https://uberspace.de) gehostet werden. Führe einfach `./install-on-uberspace.sh` aus! + ### Ubuntu und Debian Falls du Ubuntu oder Debian verwendest, kannst du einfach `./install-dependencies.sh` ausführen, damit alles installiert wird. Ergänze dann noch den `bot_api_key` und die `admin`-ID (Bekommst du in Telegram mit `@Brawlbot id`) und kopiere die config.lua.example nach config.lua. diff --git a/install-on-uberspace.sh b/install-on-uberspace.sh new file mode 100755 index 0000000..6801252 --- /dev/null +++ b/install-on-uberspace.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# Dieses Skript installiert den Bot auf Uberspace. +# Lua 5.2 (falls nicht vorhanden) und LuaRocks werden installiert und Redis wird gestartet, +# zudem wird die config.lua des Bots angepasst. +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $HOME + +if [ -n "$1" ]; then + echo "Überspringe Lua" +else + # LUA 5.2 + if [ -d "/package/host/localhost/lua-5.2" ]; then + echo "export PATH=/package/host/localhost/lua-5.2/bin:\$PATH" >> $HOME/.bash_profile + INSTALLED_DIR="/package/host/localhost/lua-5.2" + else + echo "Dieser Uberspace hat kein Lua 5.2, kompiliere selbst..." + wget https://www.lua.org/ftp/lua-5.2.4.tar.gz + tar -xvf lua-5.2.*.tar.gz + rm lua-5.2.*.tar.gz + cd lua-5.2.* + make linux + if [ ! -f "src/lua" ]; then + echo "Kompilierung nicht erfolgreich. Breche ab..." + exit 1 + fi + mkdir -p $HOME/lua5.2 + make install INSTALL_TOP=$HOME/lua5.2 + echo "export PATH=\$HOME/lua5.2/bin:\$PATH" >> $HOME/.bash_profile + INSTALLED_DIR="$HOME/lua5.2" + fi + cd $HOME + rm -rf lua-5.2.* + source $HOME/.bash_profile + echo "LUA 5.2 ist installiert!" +fi + +cd $HOME +INSTALLED_DIR="$HOME/lua5.2" # REMOVE THIS!!!!! + +# LuaRocks +if [ -n "$2" ]; then + echo "Überspringe LuaRocks" +else + echo "Installiere LuaRocks" + git clone http://github.com/keplerproject/luarocks luarocks-git + cd luarocks-git + ./configure --lua-version=5.2 --versioned-rocks-dir --with-lua=$INSTALLED_DIR --prefix=$HOME/luarocks + make build + make install + if [ ! -f "$HOME/luarocks/bin/luarocks-5.2" ]; then + echo "Kompilierung nicht erfolgreich. Breche ab..." + exit 1 + fi + echo "export PATH=\$HOME/luarocks/bin:\$PATH" >> $HOME/.bash_profile + cd $HOME + rm -rf luarocks-git + source $HOME/.bash_profile + luarocks-5.2 path >> $HOME/.bash_profile + source $HOME/.bash_profile + echo "Luarocks ist installiert!" +fi + +cd $HOME + +# LuaRocks-Module +if [ -n "$3" ]; then + echo "Überspringe LuaRocks-Module" +else + echo "Installiere LuaRocks-Module" + rocklist="luasocket luasec multipart-post lpeg dkjson redis-lua fakeredis oauth xml feedparser serpent luautf8" + for rock in $rocklist; do + luarocks-5.2 install $rock --local + done + echo "Alle LuaRocks-Module wurden installiert!" +fi + +cd $SCRIPTDIR + +# Redis +if [ -n "$4" ]; then + echo "Überspringe Redis" +else + echo "Setze Redis auf" + test -d ~/service || uberspace-setup-svscan + uberspace-setup-redis + # Passe Config an + NAME=$(whoami) + sed s/"use_socket = false,"/"use_socket = true,"/ config.lua.example > config.lua + sed -i s/"socket_path = 'unix:\/\/\/home\/path\/to\/your\/redis\/sock',"/"socket_path = \'unix:\/\/\/home\/$NAME\/.redis\/sock',"/g config.lua + echo "Redis aufgesetzt!" +fi + +echo "Alles fertig! Vergiss nicht, noch deinen Bot-Token und deine Telegram-ID in der config.lua zu ergänzen!" +echo "Führe bitte vorher noch einmal" +echo "source ~/.bash_profile" +echo "aus oder melde dich ab und wieder an." + +exit 0 \ No newline at end of file