install gnu utils on BSD and MacOS ...

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-05-19 14:58:29 +02:00
parent 3d92bf3ca8
commit 876361f562
6 changed files with 76 additions and 49 deletions

View File

@ -91,7 +91,8 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
<p>Released to the public domain wherever applicable. Elsewhere, consider it released under the <a href="http://www.wtfpl.net/txt/copying/">WTFPLv2</a>.</p> <p>Released to the public domain wherever applicable. Elsewhere, consider it released under the <a href="http://www.wtfpl.net/txt/copying/">WTFPLv2</a>.</p>
<h2>Prerequisites</h2> <h2>Prerequisites</h2>
<p>Uses <a href="http://github.com/dominictarr/JSON.sh">JSON.sh</a>, but no more TMUX.</p> <p>Uses <a href="http://github.com/dominictarr/JSON.sh">JSON.sh</a>, but no more TMUX.</p>
<p>Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. More concret on the common commands provided by <a href="https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands">coreutils</a>, <a href="https://en.wikipedia.org/wiki/BusyBox#Commands">busybox</a> or <a href="https://landley.net/toybox/help.html">toybox</a>, see <a href="doc/7_develop.md#common-commands">Developer Notes</a></p> <p>Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. More concret on the common commands provided by recent versions of <a href="https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands">coreutils</a>, <a href="https://en.wikipedia.org/wiki/BusyBox#Commands">busybox</a> or <a href="https://landley.net/toybox/help.html">toybox</a>, see <a href="doc/7_develop.md#common-commands">Developer Notes</a></p>
<p>Note for MacOS and BSD Users: As bashbot use behaivior of recent bash and (gnu)sed versions, bashbot may not run without installing additional software, see <a href="doc/0_install.md">Install Bashbot</a></p>
<p>Bashbot <a href="https://github.com/topkecleon/telegram-bot-bash">Documentation</a> and <a href="https://github.com/topkecleon/telegram-bot-bash/releases">Downloads</a> are availible on www.github.com</p> <p>Bashbot <a href="https://github.com/topkecleon/telegram-bot-bash">Documentation</a> and <a href="https://github.com/topkecleon/telegram-bot-bash/releases">Downloads</a> are availible on www.github.com</p>
<h2>Documentation</h2> <h2>Documentation</h2>
<ul> <ul>
@ -150,8 +151,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
<li><a href="examples/README.md">Examples Dir</a></li> <li><a href="examples/README.md">Examples Dir</a></li>
</ul> </ul>
<h3>Your really first bashbot in a nutshell</h3> <h3>Your really first bashbot in a nutshell</h3>
<p>Note for MacOS: you must install install a more current bash, see <a href="doc/0_install.md">Install Bashbot</a></p> <p>To install and run bashbot you need acess to a linux/unix command line. If you don't know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(</p>
<p>To install and run bashbot you need acess to a linux/unix/bsd command line. If you don't know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(</p>
<p>In addition you need a <a href="https://telegram.org">Telegram client</a> and a mobile phone to <a href="https://telegramguide.com/create-a-telegram-account/">register an account</a>. If you don't want to register for Telegram you should stop reading here ;-)</p> <p>In addition you need a <a href="https://telegram.org">Telegram client</a> and a mobile phone to <a href="https://telegramguide.com/create-a-telegram-account/">register an account</a>. If you don't want to register for Telegram you should stop reading here ;-)</p>
<p>After you're registered to Telegram send a message to <a href="https://telegram.me/botfather">@botfather</a>, <a href="doc/1_firstbot.md">create a new Telegram Bot token</a> and write it down. You need the token to install the bot.</p> <p>After you're registered to Telegram send a message to <a href="https://telegram.me/botfather">@botfather</a>, <a href="doc/1_firstbot.md">create a new Telegram Bot token</a> and write it down. You need the token to install the bot.</p>
<p>Now open a linux/unix/bsd terminal and check if bash is installed: <code>which bash &amp;&amp; echo "bash installed!"</code>. If you get an error message bash is not installed.</p> <p>Now open a linux/unix/bsd terminal and check if bash is installed: <code>which bash &amp;&amp; echo "bash installed!"</code>. If you get an error message bash is not installed.</p>
@ -228,6 +228,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>@Gnadelwartz</p> <p>@Gnadelwartz</p>
<h2>That's it!</h2> <h2>That's it!</h2>
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p> <p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
<h4>$$VERSION$$ V0.94-2-gced78d3</h4> <h4>$$VERSION$$ V0.94-7-g3d92bf3</h4>
</body> </body>
</html> </html>

View File

@ -12,7 +12,9 @@ Elsewhere, consider it released under the [WTFPLv2](http://www.wtfpl.net/txt/cop
Uses [JSON.sh](http://github.com/dominictarr/JSON.sh), but no more TMUX. Uses [JSON.sh](http://github.com/dominictarr/JSON.sh), but no more TMUX.
Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment.
More concret on the common commands provided by [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html), see [Developer Notes](doc/7_develop.md#common-commands) More concret on the common commands provided by recent versions of [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html), see [Developer Notes](doc/7_develop.md#common-commands)
Note for MacOS and BSD Users: As bashbot use behaivior of recent bash and (gnu)sed versions, bashbot may not run without installing additional software, see [Install Bashbot](doc/0_install.md)
Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are availible on www.github.com Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are availible on www.github.com
@ -60,9 +62,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
### Your really first bashbot in a nutshell ### Your really first bashbot in a nutshell
Note for MacOS: you must install install a more current bash, see [Install Bashbot](doc/0_install.md) To install and run bashbot you need acess to a linux/unix command line. If you don't know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(
To install and run bashbot you need acess to a linux/unix/bsd command line. If you don't know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(
In addition you need a [Telegram client](https://telegram.org) and a mobile phone to [register an account](https://telegramguide.com/create-a-telegram-account/). In addition you need a [Telegram client](https://telegram.org) and a mobile phone to [register an account](https://telegramguide.com/create-a-telegram-account/).
If you don't want to register for Telegram you should stop reading here ;-) If you don't want to register for Telegram you should stop reading here ;-)
@ -192,4 +192,4 @@ This may happen if to many wrong requests are sent to api.telegram.org, e.g. usi
If you feel that there's something missing or if you found a bug, feel free to submit a pull request! If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ V0.94-2-gced78d3 #### $$VERSION$$ V0.94-7-g3d92bf3

View File

@ -17,12 +17,16 @@ Uses [JSON.sh](http://github.com/dominictarr/JSON.sh), but no more TMUX.
Even bashbot is written in bash, it depends on commands typically availible in Even bashbot is written in bash, it depends on commands typically availible in
a Unix/Linux Environment. a Unix/Linux Environment.
More concret on the common commands provided by More concret on the common commands provided by recent versions of
[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands),
[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or
[toybox](https://landley.net/toybox/help.html), see [Developer [toybox](https://landley.net/toybox/help.html), see [Developer
Notes](doc/7_develop.md#common-commands) Notes](doc/7_develop.md#common-commands)
Note for MacOS and BSD Users: As bashbot use behaivior of recent bash and
(gnu)sed versions, bashbot may not run without installing additional software,
see [Install Bashbot](doc/0_install.md)
Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and
[Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are
@ -71,12 +75,9 @@ availible on www.github.com
### Your really first bashbot in a nutshell ### Your really first bashbot in a nutshell
Note for MacOS: you must install install a more current bash, see [Install To install and run bashbot you need acess to a linux/unix command line. If you
Bashbot](doc/0_install.md) don't know how to get accces to a linux/unix/bsd like command line you should
stop reading here :-(
To install and run bashbot you need acess to a linux/unix/bsd command line. If
you don't know how to get accces to a linux/unix/bsd like command line you
should stop reading here :-(
In addition you need a [Telegram client](https://telegram.org) and a mobile In addition you need a [Telegram client](https://telegram.org) and a mobile
phone to [register an phone to [register an
@ -269,4 +270,4 @@ tor proxy on your server you may uncomment the ```BASHBOT_CURL_ARGS``` line in
If you feel that there's something missing or if you found a bug, feel free to If you feel that there's something missing or if you found a bug, feel free to
submit a pull request! submit a pull request!
#### $$VERSION$$ V0.94-2-gced78d3 #### $$VERSION$$ V0.94-7-g3d92bf3

View File

@ -11,7 +11,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ V0.94-6-gdcf6534 #### $$VERSION$$ V0.94-7-g3d92bf3
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -111,12 +111,9 @@ if [ -z "${BOTTOKEN}" ]; then
printf '%s\n' "${BOTTOKEN}" > "${TOKENFILE}" printf '%s\n' "${BOTTOKEN}" > "${TOKENFILE}"
fi fi
fi fi
if [ "$(cat -v "${TOKENFILE}" | wc | sed -e 's/[[:space:]]//g')" != "1146" ]; then # read BOTTOKEN from file and removen everyting from first newline to end
echo -e "${ORANGE}Warning, something may wrong with your token file.${NC}"
echo -e "${ORANGE}The file musst be 1 newline, 1 word, and 46 byte, your's is:${NC}\c"
cat -v "${TOKENFILE}" | wc | sed -e 's/[[:space:]]\+/ /g'
fi
BOTTOKEN="$(< "${TOKENFILE}")" BOTTOKEN="$(< "${TOKENFILE}")"
BOTTOKEN="${BOTTOKEN%%$'\n'*}"
# setup botadmin file # setup botadmin file
if [ ! -f "${BOTADMIN}" ]; then if [ ! -f "${BOTADMIN}" ]; then
@ -155,16 +152,24 @@ if [ -z "${BOTTOKEN}" ]; then
exit 2 exit 2
fi fi
fi fi
if [[ ! "${BOTTOKEN}" =~ ^[0-9]+:[a-zA-Z0-9_-]+$ ]]; then # do we have BSD sed
echo -e "${ORANGE}Warning, your bottoken may incorrent. it sould have the following format:${NC}" if ! sed '1ia' </dev/null 2>/dev/null; then
echo -e "${ORANGE}Warning: You may run on a BSD style system without gnu utils ...${NC}"
fi
# BOTTOKEN format checks
if [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ ]]; then
echo -e "${ORANGE}Warning, your bottoken may incorrect. it should have the following format:${NC}"
echo -e "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}\c" echo -e "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}\c"
echo -e "${GREY}9 digits${RED}:${GREY}35 alnum characters + '_-'${NC}" echo -e "${GREY}8-10 digits${RED}:${GREY}35 alnum characters + '_-'${NC}"
echo -e "${ORANGE}Your current token is: '${GREY}$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")' (one $ is ok){NC}" echo -e "${ORANGE}Your current token is: '${GREY}^$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")${ORANGE}'${NC}"
fi [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]] &&\
if [ "${BOTTOKEN#bot}" != "${BOTTOKEN}" ]; then echo -e "${ORANGE}Possible problem in the digits part, len is $(($(wc -c <<<"${BOTTOKEN%:*}")-1))${NC}"
echo -e "${ORANGE}Warning, your token starts with '${GREY}bot${NC}${ORANGE}', did you forget to remove it?.${NC}" [[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\
echo -e "${ORANGE}Posilbe problem in the charatcers part, len is $(($(wc -c <<<"${BOTTOKEN#*:}")-1))${NC}"
fi fi
exit
################## ##################
# here we start with the real stuff # here we start with the real stuff
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"

View File

@ -43,13 +43,16 @@ If you modified ```commands.sh``` move your changes to ```mycommands.sh```, this
Now you can restart your bashbot instances. Now you can restart your bashbot instances.
### Note for MacOS Users ### Note for BSD and MacOS
You must install a more current version of bash, as the default bash is way to old, **On MacOS** You must install a more current version of bash, as the default bash is way to old,
see e.g. [Install Bash on Mac](http://macappstore.org/bash/) see e.g. [Install Bash on Mac](http://macappstore.org/bash/)
After installation / update of bashbot you must change the shebang line to point to your bash location **On BSD and MacOS** I recommend to install the gnu variants of coreutils and include them in front of your PATH
e.g. with the provided script ```bash -c "examples/bash2env *.sh */*.sh"``` environment variable before running bashbot, e.g. sed, grep, find
In adition you must adjust the shebang line of the scripts ```bashbot.sh``` and ```json.sh``` to point to to the correct bash
or use the example script: ```examples/bash2env *.sh */*.sh```
We stay with /bin/bash shebang, because using the system bash is more save, see We stay with /bin/bash shebang, because using the system bash is more save, see
[Security Considerations](../README.md#Security-Considerations) [Security Considerations](../README.md#Security-Considerations)
@ -98,5 +101,5 @@ The old format is supported for backward compatibility, but may fail for corner
#### [Next Create Bot](1_firstbot.md) #### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ V0.94-4-gf0a7d85 #### $$VERSION$$ V0.94-7-g3d92bf3

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# file: bash2env.sh # file: bash2env.sh
# simole helper script to convert bash shebang from # simole helper script to convert bash shebang from
# ! /bin/bash TO ! /usr/bin/env bash # ! /bin/bash TO ! /usr/bin/env bash
@ -6,7 +6,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ V0.94-0-gbdb50c8 #### $$VERSION$$ V0.94-7-g3d92bf3
# adjust your language setting here # adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
@ -15,23 +15,41 @@ export 'LANG=C.UTF-8'
export 'LANGUAGE=C.UTF-8' export 'LANGUAGE=C.UTF-8'
unset IFS unset IFS
MYSHEBANG=""
################ ################
# uncomment thenfollowing line to make the conversion # uncomment one of the following lines to make the conversion
# DOIT="yes" # linux/unix bash
# MYSHEBANG="#!/bin/bash"
# BSD bash
# MYSHEBANG="#!/usr/bin/bash"
# homebrew gnu bash on MacOS
# MYSHEBANG="#!/usr/local/opt/bash"
# use portable /usr/bin/env
# MYSHEBANG="#!/usr/bin/env bash"
# bashbot default bash
FROMSHEBANG="#!/bin/bash"
# uncomment to convert back to bashbot default bash
# FROMSHEBANG="#!/usr/bin/env bash"
# MYSHEBANG="#!/bin/bash"
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0: convert bash shebang to /usr/bin/env bash" echo "$0: convert bash shebang to point to your local installation"
echo "usage: $0 script [script ...]" echo "usage: $0 script [script ...]"
exit exit
fi fi
# loop tomprocess files # loop tomprocess files
if [ "${DOIT}" = "yes" ]; then if [ "${MYSHEBANG}" != "" ]; then
echo "Warning, changes will be done!" echo "Warning, shebang will changed from ${FROMSHEBANG} changed to ${MYSHEBANG}!"
else else
echo "Dry run, output changes only!" echo "Dry run, demonstration only!"
echo "Uncomment DOIT=\"yes\" in script to make the changes permanent." echo "Uncomment one of the MYSHEBANG= lines fitting your environment to make the changes permanent."
fi fi
@ -45,15 +63,15 @@ do
file "${file}" file "${file}"
if [[ "$(file -b "${file}")" =~ Bourne.*script.*text ]]; then if [[ "$(file -b "${file}")" =~ Bourne.*script.*text ]]; then
echo "Processing ${file} ..." echo "Processing ${file} ..."
if head -n 1 "${file}" | grep -q '^#!/bin/bash'; then if head -n 1 "${file}" | grep -q "^${FROMSHEBANG}"; then
if [ "${DOIT}" = "yes" ]; then if [ "${MYSHEBANG}" != "" ]; then
sed -i -e '1 s|^#!/bin/bash|#!/usr/bin/env bash|' "${file}" sed -i -e '1 s|^'"${FROMSHEBANG}"'|'"${MYSHEBANG}"'|' "${file}"
head -n 1 "${file}" head -n 1 "${file}"
else else
sed -n -e '1 s|^#!/bin/bash|#!/usr/bin/env bash (dry run)|p' "${file}" sed -n -e '1 s|^'"${FROMSHEBANG}"'|#!/some/shebang/bash (dry run)|p' "${file}"
fi fi
else else
echo "No #!/bin/bash shebang, nothing to convert." echo "Found: $(head -n 1 "${file}") - Nothing to convert."
fi fi
echo -e "... done.\n" echo -e "... done.\n"
else else