telegram-bot-bash/doc/0_install.md

136 lines
5.9 KiB
Markdown
Raw Normal View History

2019-05-16 14:43:44 +00:00
#### [Home](../README.md)
2020-09-23 08:58:18 +00:00
## Check bash installation
2020-09-24 15:13:20 +00:00
There may systems where bash seems to be installed but it is not, e.g. embedded systems, or where bash is to old.
2020-12-27 16:13:37 +00:00
Bashbot has some builtin checks but it may better to check before installing bashbot.
2020-09-23 08:58:18 +00:00
Run the following commands to see if your bash looks ok ...
```bash
2020-09-23 13:35:31 +00:00
# system say bash is there?
if which bash; then echo "bash seems available..."; else echo "NO bash"; fi
2020-09-23 08:58:18 +00:00
# real bash supports ARRAY
2020-09-24 16:20:39 +00:00
bash -c 'if eval "a[1]=1"; then echo "Shell support arrays..."; else echo "Shell has NO arrays"; fi'
2020-09-23 08:58:18 +00:00
2020-09-24 15:13:20 +00:00
# check for bash version by feature
2020-12-27 16:13:37 +00:00
bash -c 'if [ "$(echo -e "\u1111")" != "\u1111" ]; then echo "Bash version ok ..."; else echo "Bash version may to old ..."; fi'
2020-12-27 16:27:04 +00:00
# display bash version, must be greater than 4.3
2020-12-27 16:13:37 +00:00
bash --version | grep "bash"
2020-09-23 08:58:18 +00:00
```
2019-05-16 14:43:44 +00:00
## Install bashbot
1. Go to the directory you want to install bashbot, e.g.
* your $HOME directory (install and run with your user-ID)
* /usr/local if you want to run as service
2020-12-27 16:13:37 +00:00
2. [Download latest release zip / tar archive from github](https://github.com/topkecleon/telegram-bot-bash/releases/latest) and extract all files.
3. Change into the directory `telegram-bot-bash`
4. Copy `mycommands.sh.dist` or `mycommands.sh.clean` to `mycommands.sh`
5. Run `./bashbot.sh init` to setup the environment and enter your Bots token given by botfather.
2019-05-16 14:43:44 +00:00
2020-12-27 16:13:37 +00:00
Edit `mycommands.sh` to fit your needs.
2019-05-16 14:43:44 +00:00
Now your Bot is ready to start ...
**If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)**
2020-09-09 15:48:47 +00:00
### Update bashbot
2019-05-16 14:43:44 +00:00
2020-12-27 16:13:37 +00:00
**Important: all files including `mycommands.sh` may overwritten, make a backup!**
2019-05-21 21:35:56 +00:00
2020-12-27 16:13:37 +00:00
1. Go to the directory where you have installed bashbot, e.g.
2019-05-16 14:43:44 +00:00
* your $HOME directory
* /usr/local
2020-12-27 16:13:37 +00:00
2. [Download latest release zip / tar archive from github](https://github.com/topkecleon/telegram-bot-bash/releases/latest)
3. Stop all running instances of bashbot `./bashbot.sh stop`
2019-05-21 21:35:56 +00:00
4. Extract all files to your existing bashbot dir
2020-12-27 16:13:37 +00:00
5. Run `sudo ./bashbot.sh init` to setup your environment after the update
2019-05-16 14:43:44 +00:00
2020-12-27 16:13:37 +00:00
If you modified `commands.sh` move your changes to `mycommands.sh`, this avoids overwriting your commands on every update.
2019-05-16 14:43:44 +00:00
Now you can restart your bashbot instances.
2019-05-16 14:43:44 +00:00
2020-12-27 16:13:37 +00:00
*Note*: If you are updating from a pre-1.0 version, update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bash/releases/tags/v1.20) first!
2020-09-09 15:48:47 +00:00
2020-12-23 13:00:13 +00:00
### Use JSON.awk (beta)
2020-12-15 16:06:37 +00:00
[JSON.awk](https://github.com/step-/JSON.awk) is an awk port of `JSON.sh`, it provides the same functionality but is 5 times faster.
2020-12-19 21:10:06 +00:00
Most systems with awk can use `JSON.awk` as drop in replacement
( [gnu awk, posix awk, mawk, busybox akw](https://github.com/step-/JSON.awk#compatibility-with-awk-implementations) ).
2020-12-15 16:06:37 +00:00
BSD and MacOS users must install `gnu awk` and adjust the shebang, see below
2021-01-04 11:33:36 +00:00
After you have checked that `JSON.awk.dist` is working correct on your system copy it to `JSON.awk` and (re)start bashbot.
2020-12-23 13:00:13 +00:00
2021-01-04 11:33:36 +00:00
Note: If you are not using the zip / tar archive, you must install `JSON.awk` manually into the same directory as `JSON.sh`:
2020-12-15 16:06:37 +00:00
2020-12-23 12:46:39 +00:00
wget https://cdn.jsdelivr.net/gh/step-/JSON.awk/JSON.awk
wget https://cdn.jsdelivr.net/gh/step-/JSON.awk/tool/patch-for-busybox-awk.sh
2020-12-23 12:14:52 +00:00
bash patch-for-busybox-awk.sh
2020-12-15 16:06:37 +00:00
2020-12-27 16:13:37 +00:00
### Install bashbot from git repo
2020-12-27 16:13:37 +00:00
Installation and Updates should be done using the zip / tar archives provided on github to avoid
2020-12-27 16:27:04 +00:00
problems and not overwriting your bot config and `mycommands.sh`.
2020-12-27 16:13:37 +00:00
Nevertheless you can install or update bashbot from a git repo, see next chapter ...
### Create Installation / Update archives
2020-09-08 10:13:35 +00:00
To install or update bashbot from git repo execute `dev/make-distribution.sh`, this creates the archives and set up bashbot to run in `DIST/telegram.bot-bash`.
*Note:* You should be familiar with `git`.
2020-12-27 16:13:37 +00:00
1. Run `git clone https://github.com/topkecleon/telegram-bot-bash.git`
2. Change into the directory `telegram-bot-bash`
3. Optional: Run ` git checkout develop` for latest develop version
4. Run ` dev/make-distribution.sh` (_add --notest to skip tests_)
5. Change to dir `DIST/`
Use the archives created in `DIST/` to install or update bashbot as described above.
2020-12-30 10:18:48 +00:00
To run a test bot, e.g. while development or testing latest changes, you can use the bashbot installation provided in `DIST/telegram-bot-bash`.
To update the test installation, e.g. after git pull, local changes or switch master/develop, run `dev/make-distrubition.sh` again.
2020-05-19 12:58:29 +00:00
### Note for BSD and MacOS
2020-05-17 11:51:32 +00:00
2020-05-19 13:15:26 +00:00
**On MacOS** you must install a more recent version of bash, as the default bash is way to old,
2020-05-17 11:51:32 +00:00
see e.g. [Install Bash on Mac](http://macappstore.org/bash/)
2020-06-26 09:01:56 +00:00
**On BSD and MacOS** I recommend to install gnu coreutils and include them in your PATH
2020-05-19 13:15:26 +00:00
environment variable before running bashbot, e.g. the gnu versions of sed, grep, find ...
2020-05-19 12:58:29 +00:00
2020-06-26 09:10:12 +00:00
On BSD and MacOS you must adjust the shebang line of the scripts ```bashbot.sh``` and ```json.sh``` to point to to the correct bash
2020-06-26 09:01:56 +00:00
or use the script: ```examples/bash2env *.sh */*.sh``` to convert them for you.
Bashbot will stay with /bin/bash shebang, as using a fixed path is more secure than the portable /usr/bin/env variant, see
[Security Considerations](../README.md#Security-Considerations)
I considered to make bashbot BSD sed compatible, but much of the bashbot "magic" relies on
2020-06-18 10:36:34 +00:00
(gnu) sed features, e.g. alternation ```|```, non printables ```\n\t\<``` or repeat ```?+``` pattern, not supported by BSD sed.
2020-12-27 16:13:37 +00:00
BSD/MacOS sed compatibility will result in a rewrite of all grep/sed commands with an uncertain outcome,
see [BSD/MacOS vs. GNU sed](https://riptutorial.com/sed/topic/9436/bsd-macos-sed-vs--gnu-sed-vs--the-posix-sed-specification)
to get an impression how different they are.
2019-05-16 14:43:44 +00:00
2020-12-27 16:13:37 +00:00
### Notes on Changes
2019-05-16 14:43:44 +00:00
2020-12-27 16:13:37 +00:00
#### Support for update from pre-1.0 removed
2019-05-16 14:43:44 +00:00
2021-01-04 11:33:36 +00:00
From Version 1.21 on updating from a pre-1.0 version (_no \*.jssh config_) is no more supported!
2020-12-27 16:13:37 +00:00
You must update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bash/releases/tags/v1.20) first!
2019-05-16 14:43:44 +00:00
#### [Next Create Bot](1_firstbot.md)
2021-01-03 21:39:36 +00:00
#### $$VERSION$$ v1.21-0-gc85af77
2019-05-16 14:43:44 +00:00