detect if no curl AND no wget

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-11-29 17:20:57 +01:00
parent 282448772a
commit 95b2b9a79d
13 changed files with 146 additions and 131 deletions

View File

@ -5,78 +5,82 @@
<meta name="generator" content="pandoc" /> <meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Bashbot README</title> <title>Bashbot README</title>
<style type="text/css"> <style>
code{white-space: pre-wrap;} code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;} span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;} span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;} div.column{display: inline-block; vertical-align: top; width: 50%;}
</style> div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
<style type="text/css"> ul.task-list{list-style: none;}
a.sourceLine { display: inline-block; line-height: 1.25; } pre > code.sourceCode { white-space: pre; position: relative; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
a.sourceLine:empty { height: 1.2em; } pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; }
code.sourceCode { white-space: pre; position: relative; } div.sourceCode { margin: 1em 0; }
div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; }
pre.sourceCode { margin: 0; } @media screen {
@media screen { div.sourceCode { overflow: auto; }
div.sourceCode { overflow: auto; } }
} @media print {
@media print { pre > code.sourceCode { white-space: pre-wrap; }
code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
a.sourceLine { text-indent: -1em; padding-left: 1em; } }
} pre.numberSource code
pre.numberSource a.sourceLine { counter-reset: source-line 0; }
{ position: relative; left: -4em; } pre.numberSource code > span
pre.numberSource a.sourceLine::before { position: relative; left: -4em; counter-increment: source-line; }
{ content: attr(title); pre.numberSource code > span > a:first-child::before
position: relative; left: -1em; text-align: right; vertical-align: baseline; { content: counter(source-line);
border: none; pointer-events: all; display: inline-block; position: relative; left: -1em; text-align: right; vertical-align: baseline;
-webkit-touch-callout: none; -webkit-user-select: none; border: none; display: inline-block;
-khtml-user-select: none; -moz-user-select: none; -webkit-touch-callout: none; -webkit-user-select: none;
-ms-user-select: none; user-select: none; -khtml-user-select: none; -moz-user-select: none;
padding: 0 4px; width: 4em; -ms-user-select: none; user-select: none;
color: #aaaaaa; padding: 0 4px; width: 4em;
} color: #aaaaaa;
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } }
div.sourceCode pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
{ } div.sourceCode
@media screen { { }
a.sourceLine::before { text-decoration: underline; } @media screen {
} pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
code span.al { color: #ff0000; font-weight: bold; } /* Alert */ }
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.at { color: #7d9029; } /* Attribute */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.bn { color: #40a070; } /* BaseN */ code span.at { color: #7d9029; } /* Attribute */
code span.bu { } /* BuiltIn */ code span.bn { color: #40a070; } /* BaseN */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.bu { } /* BuiltIn */
code span.ch { color: #4070a0; } /* Char */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.cn { color: #880000; } /* Constant */ code span.ch { color: #4070a0; } /* Char */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cn { color: #880000; } /* Constant */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.dt { color: #902000; } /* DataType */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dv { color: #40a070; } /* DecVal */ code span.dt { color: #902000; } /* DataType */
code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.dv { color: #40a070; } /* DecVal */
code span.ex { } /* Extension */ code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.fl { color: #40a070; } /* Float */ code span.ex { } /* Extension */
code span.fu { color: #06287e; } /* Function */ code span.fl { color: #40a070; } /* Float */
code span.im { } /* Import */ code span.fu { color: #06287e; } /* Function */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.im { } /* Import */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.op { color: #666666; } /* Operator */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.ot { color: #007020; } /* Other */ code span.op { color: #666666; } /* Operator */
code span.pp { color: #bc7a00; } /* Preprocessor */ code span.ot { color: #007020; } /* Other */
code span.sc { color: #4070a0; } /* SpecialChar */ code span.pp { color: #bc7a00; } /* Preprocessor */
code span.ss { color: #bb6688; } /* SpecialString */ code span.sc { color: #4070a0; } /* SpecialChar */
code span.st { color: #4070a0; } /* String */ code span.ss { color: #bb6688; } /* SpecialString */
code span.va { color: #19177c; } /* Variable */ code span.st { color: #4070a0; } /* String */
code span.vs { color: #4070a0; } /* VerbatimString */ code span.va { color: #19177c; } /* Variable */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style> </style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head> </head>
<body> <body>
<header> <header id="title-block-header">
<h1 class="title">Bashbot README</h1> <h1 class="title">Bashbot README</h1>
</header> </header>
<h2><img align="middle" src="https://raw.githubusercontent.com/odb/official-bash-logo/master/assets/Logos/Icons/PNG/64x64.png" > <h2><img align="middle" src="https://raw.githubusercontent.com/odb/official-bash-logo/master/assets/Logos/Icons/PNG/64x64.png" >
@ -91,7 +95,7 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).
<p>Uses <a href="http://github.com/dominictarr/JSON.sh">JSON.sh</a> and the magic of sed.</p> <p>Uses <a href="http://github.com/dominictarr/JSON.sh">JSON.sh</a> and the magic of sed.</p>
<p>Even bashbot is written in bash, it depends on commands typically available in a Unix/Linux Environment. More concrete 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>Even bashbot is written in bash, it depends on commands typically available in a Unix/Linux Environment. More concrete 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><strong>Note for MacOS and BSD Users:</strong> As bashbot heavily uses modern bash and (gnu) grep/sed features, bashbot will not run without installing additional software, see <a href="doc/0_install.md">Install Bashbot</a></p> <p><strong>Note for MacOS and BSD Users:</strong> As bashbot heavily uses modern bash and (gnu) grep/sed features, bashbot will not run without installing additional software, see <a href="doc/0_install.md">Install Bashbot</a></p>
<p><strong>Note for embedded systems:</strong> busybox or toybox ONLY is not sufficient, you need a to install a &quot;real&quot; bash, see also <a href="doc/0_install.md">Install Bashbot</a></p> <p><strong>Note for embedded systems:</strong> busybox or toybox ONLY is not sufficient, you need a to install a "real" bash, see also <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 available 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 available on www.github.com</p>
<h2>Documentation</h2> <h2>Documentation</h2>
<ul> <ul>
@ -158,8 +162,8 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).
<p>Now open a terminal and check if bash is installed:</p> <p>Now open a terminal and check if bash is installed:</p>
<pre><code>which bash &amp;&amp; echo &quot;bash seems available...&quot; <pre><code>which bash &amp;&amp; echo &quot;bash seems available...&quot;
</code></pre> </code></pre>
<p>Create a new directory, change to it: <code>mkdir tbb; cd tbb</code> and download the latest '*.tar.gz' file from <a href="https://github.com/topkecleon/telegram-bot-bash/releases" class="uri">https://github.com/topkecleon/telegram-bot-bash/releases</a>. This can be done with the commands:</p> <p>Create a new directory, change to it: <code>mkdir tbb; cd tbb</code> and download the latest '*.tar.gz' file from <a href="https://github.com/topkecleon/telegram-bot-bash/releases">https://github.com/topkecleon/telegram-bot-bash/releases</a>. This can be done with the commands:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb2-1" title="1"><span class="fu">wget</span> -q https://github.com/<span class="va">$(</span><span class="fu">wget</span> -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - <span class="kw">|</span> <span class="fu">egrep</span> <span class="st">&#39;/.*/.*/.*tar.gz&#39;</span> -o<span class="va">)</span></a></code></pre></div> <div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1"></a><span class="fu">wget</span> -q https://github.com/<span class="va">$(</span><span class="fu">wget</span> -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - <span class="kw">|</span> <span class="fu">egrep</span> <span class="st">&#39;/.*/.*/.*tar.gz&#39;</span> -o<span class="va">)</span></span></code></pre></div>
<p>Extract the '*.tar.gz' file and change to bashbot directory: <code>tar -xzf *.tar.gz; cd telegram-bot-bash</code>, install bashbot: <code>./bashbot.sh init</code> and enter your bot token when asked. All other questions can be answered by hitting the &lt;Return&gt; key.</p> <p>Extract the '*.tar.gz' file and change to bashbot directory: <code>tar -xzf *.tar.gz; cd telegram-bot-bash</code>, install bashbot: <code>./bashbot.sh init</code> and enter your bot token when asked. All other questions can be answered by hitting the &lt;Return&gt; key.</p>
<p>That's all, now you can start your bot with <code>./bashbot.sh start</code> and send him messages:</p> <p>That's all, now you can start your bot with <code>./bashbot.sh start</code> and send him messages:</p>
<pre><code>/start <pre><code>/start
@ -196,18 +200,18 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>A powerful tool to improve your scripts is <code>shellcheck</code>. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install shellcheck locally</a>. Shellcheck is used extensively in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a <a href="doc/7_develop.md">test suite</a> to check if important functionality is working as expected.</p> <p>A powerful tool to improve your scripts is <code>shellcheck</code>. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install shellcheck locally</a>. Shellcheck is used extensively in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a <a href="doc/7_develop.md">test suite</a> to check if important functionality is working as expected.</p>
<h3>Use printf whenever possible</h3> <h3>Use printf whenever possible</h3>
<p>If you're writing a script and it is taking external input (from the user as arguments or file system...), you shouldn't use echo to display it. <a href="https://unix.stackexchange.com/a/6581">Use printf whenever possible</a></p> <p>If you're writing a script and it is taking external input (from the user as arguments or file system...), you shouldn't use echo to display it. <a href="https://unix.stackexchange.com/a/6581">Use printf whenever possible</a></p>
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb5-1" title="1"> <span class="co"># very simple</span></a> <div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1"></a> <span class="co"># very simple</span></span>
<a class="sourceLine" id="cb5-2" title="2"> <span class="bu">echo</span> <span class="st">&quot;text with variables. PWD=</span><span class="va">$PWD</span><span class="st">&quot;</span></a> <span id="cb5-2"><a href="#cb5-2"></a> <span class="bu">echo</span> <span class="st">&quot;text with variables. PWD=</span><span class="va">$PWD</span><span class="st">&quot;</span></span>
<a class="sourceLine" id="cb5-3" title="3"> <span class="bu">printf</span> <span class="st">&#39;%s\n&#39;</span> <span class="st">&quot;text with variables. PWD=</span><span class="va">$PWD</span><span class="st">&quot;</span></a> <span id="cb5-3"><a href="#cb5-3"></a> <span class="bu">printf</span> <span class="st">&#39;%s\n&#39;</span> <span class="st">&quot;text with variables. PWD=</span><span class="va">$PWD</span><span class="st">&quot;</span></span>
<a class="sourceLine" id="cb5-4" title="4"> <span class="ex">-</span><span class="op">&gt;</span> text with variables. PWD=/home/xxx</a> <span id="cb5-4"><a href="#cb5-4"></a> <span class="ex">-</span><span class="op">&gt;</span> text with variables. PWD=/home/xxx</span>
<a class="sourceLine" id="cb5-5" title="5"></a> <span id="cb5-5"><a href="#cb5-5"></a></span>
<a class="sourceLine" id="cb5-6" title="6"> <span class="co"># more advanced</span></a> <span id="cb5-6"><a href="#cb5-6"></a> <span class="co"># more advanced</span></span>
<a class="sourceLine" id="cb5-7" title="7"> <span class="va">FLOAT=</span><span class="st">&quot;1.2346777892864&quot;</span> <span class="va">INTEGER=</span><span class="st">&quot;12345.123&quot;</span></a> <span id="cb5-7"><a href="#cb5-7"></a> <span class="va">FLOAT=</span><span class="st">&quot;1.2346777892864&quot;</span> <span class="va">INTEGER=</span><span class="st">&quot;12345.123&quot;</span></span>
<a class="sourceLine" id="cb5-8" title="8"> <span class="bu">echo</span> <span class="st">&quot;text with variabeles. float=</span><span class="va">$FLOAT</span><span class="st">, integer=</span><span class="va">$INTEGER</span><span class="st">, PWD=</span><span class="va">$PWD</span><span class="st">&quot;</span></a> <span id="cb5-8"><a href="#cb5-8"></a> <span class="bu">echo</span> <span class="st">&quot;text with variabeles. float=</span><span class="va">$FLOAT</span><span class="st">, integer=</span><span class="va">$INTEGER</span><span class="st">, PWD=</span><span class="va">$PWD</span><span class="st">&quot;</span></span>
<a class="sourceLine" id="cb5-9" title="9"> <span class="ex">-</span><span class="op">&gt;</span>text with variables. float=1.2346777892864, integer=12345.123, PWD=/home/xxx</a> <span id="cb5-9"><a href="#cb5-9"></a> <span class="ex">-</span><span class="op">&gt;</span>text with variables. float=1.2346777892864, integer=12345.123, PWD=/home/xxx</span>
<a class="sourceLine" id="cb5-10" title="10"></a> <span id="cb5-10"><a href="#cb5-10"></a></span>
<a class="sourceLine" id="cb5-11" title="11"> <span class="bu">printf</span> <span class="st">&quot;text with variables. float=%.2f, integer=%d, PWD=%s\n&quot;</span> <span class="st">&quot;&quot;</span> <span class="st">&quot;</span><span class="va">$INTEGER</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$PWD</span><span class="st">&quot;</span></a> <span id="cb5-11"><a href="#cb5-11"></a> <span class="bu">printf</span> <span class="st">&quot;text with variables. float=%.2f, integer=%d, PWD=%s\n&quot;</span> <span class="st">&quot;&quot;</span> <span class="st">&quot;</span><span class="va">$INTEGER</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$PWD</span><span class="st">&quot;</span></span>
<a class="sourceLine" id="cb5-12" title="12"> <span class="ex">-</span><span class="op">&gt;</span>text with variables. float=1.23, integer=12345, PWD=/home/xxx</a></code></pre></div> <span id="cb5-12"><a href="#cb5-12"></a> <span class="ex">-</span><span class="op">&gt;</span>text with variables. float=1.23, integer=12345, PWD=/home/xxx</span></code></pre></div>
<h3>Do not use #!/usr/bin/env bash</h3> <h3>Do not use #!/usr/bin/env bash</h3>
<p><strong>We stay with /bin/bash shebang, because it's more save from security perspective.</strong></p> <p><strong>We stay with /bin/bash shebang, because it's more save from security perspective.</strong></p>
<p>Use of a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.</p> <p>Use of a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.</p>
@ -237,38 +241,38 @@ It features background tasks and interactive chats, and can serve as an interfac
<h3>Can I send messages from CLI and scripts?</h3> <h3>Can I send messages from CLI and scripts?</h3>
<p>Of course, you can send messages from CLI and scripts, simply install bashbot as <a href="#Your-really-first-bashbot-in-a-nutshell">described here</a>, send the message '/start' to set yourself as botadmin and stop the bot with <code>./bashbot.sh stop</code>.</p> <p>Of course, you can send messages from CLI and scripts, simply install bashbot as <a href="#Your-really-first-bashbot-in-a-nutshell">described here</a>, send the message '/start' to set yourself as botadmin and stop the bot with <code>./bashbot.sh stop</code>.</p>
<p>Run the following commands in your bash shell or script while you are in the installation directory:</p> <p>Run the following commands in your bash shell or script while you are in the installation directory:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb6-1" title="1"><span class="co"># prepare bash / script to send commands</span></a> <div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1"></a><span class="co"># prepare bash / script to send commands</span></span>
<a class="sourceLine" id="cb6-2" title="2"><span class="bu">export</span> <span class="va">BASHBOT_HOME=</span><span class="st">&quot;</span><span class="va">$(</span><span class="bu">pwd</span><span class="va">)</span><span class="st">&quot;</span></a> <span id="cb6-2"><a href="#cb6-2"></a><span class="bu">export</span> <span class="va">BASHBOT_HOME=</span><span class="st">&quot;</span><span class="va">$(</span><span class="bu">pwd</span><span class="va">)</span><span class="st">&quot;</span></span>
<a class="sourceLine" id="cb6-3" title="3"><span class="bu">source</span> ./bashbot.sh source</a> <span id="cb6-3"><a href="#cb6-3"></a><span class="bu">source</span> ./bashbot.sh source</span>
<a class="sourceLine" id="cb6-4" title="4"></a> <span id="cb6-4"><a href="#cb6-4"></a></span>
<a class="sourceLine" id="cb6-5" title="5"><span class="co"># send me a test message</span></a> <span id="cb6-5"><a href="#cb6-5"></a><span class="co"># send me a test message</span></span>
<a class="sourceLine" id="cb6-6" title="6"><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">&quot;botadmin&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;test&quot;</span></a> <span id="cb6-6"><a href="#cb6-6"></a><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">&quot;botadmin&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;test&quot;</span></span>
<a class="sourceLine" id="cb6-7" title="7"></a> <span id="cb6-7"><a href="#cb6-7"></a></span>
<a class="sourceLine" id="cb6-8" title="8"><span class="co"># send me output of a system command</span></a> <span id="cb6-8"><a href="#cb6-8"></a><span class="co"># send me output of a system command</span></span>
<a class="sourceLine" id="cb6-9" title="9"><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">&quot;botadmin&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$(</span><span class="fu">df</span> -h<span class="va">)</span><span class="st">&quot;</span></a></code></pre></div> <span id="cb6-9"><a href="#cb6-9"></a><span class="ex">send_message</span> <span class="st">&quot;</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">&quot;botadmin&quot;</span><span class="va">)</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$(</span><span class="fu">df</span> -h<span class="va">)</span><span class="st">&quot;</span></span></code></pre></div>
<p>For more information see <a href="doc/8_custom.md">Expert Use</a></p> <p>For more information see <a href="doc/8_custom.md">Expert Use</a></p>
<h3>Blocked by telegram?</h3> <h3>Blocked by telegram?</h3>
<p>This may happen if to many or wrong requests are sent to api.telegram.org, e.g. using a invalid token or not existing API calls. If the block stay for longer time you can ask telegram service to unblock your IP-Adress.</p> <p>This may happen if to many or wrong requests are sent to api.telegram.org, e.g. using a invalid token or not existing API calls. If the block stay for longer time you can ask telegram service to unblock your IP-Adress.</p>
<p>You can check with curl or wget if you are blocked by Telegram:</p> <p>You can check with curl or wget if you are blocked by Telegram:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb7-1" title="1"><span class="ex">curl</span> -m 10 https://api.telegram.org/bot</a> <div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1"></a><span class="ex">curl</span> -m 10 https://api.telegram.org/bot</span>
<a class="sourceLine" id="cb7-2" title="2"><span class="co">#curl: (28) Connection timed out after 10001 milliseconds</span></a> <span id="cb7-2"><a href="#cb7-2"></a><span class="co">#curl: (28) Connection timed out after 10001 milliseconds</span></span>
<a class="sourceLine" id="cb7-3" title="3"></a> <span id="cb7-3"><a href="#cb7-3"></a></span>
<a class="sourceLine" id="cb7-4" title="4"><span class="fu">wget</span> -t 1 -T 10 https://api.telegram.org/bot</a> <span id="cb7-4"><a href="#cb7-4"></a><span class="fu">wget</span> -t 1 -T 10 https://api.telegram.org/bot</span>
<a class="sourceLine" id="cb7-5" title="5"><span class="co">#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.</span></a></code></pre></div> <span id="cb7-5"><a href="#cb7-5"></a><span class="co">#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.</span></span></code></pre></div>
<p>Since Version 0.96 bashbot offers the option to recover from broken connections (aka blocked). Therefore you can provide a function named <code>bashbotBlockRecover()</code> in <code>mycommands.sh</code>. If the function exists it is called every time when a broken connection is detected.</p> <p>Since Version 0.96 bashbot offers the option to recover from broken connections (aka blocked). Therefore you can provide a function named <code>bashbotBlockRecover()</code> in <code>mycommands.sh</code>. If the function exists it is called every time when a broken connection is detected.</p>
<p>Possible actions are: Check if network is working, change IP-Adress or simply wait some time.</p> <p>Possible actions are: Check if network is working, change IP-Adress or simply wait some time.</p>
<p>If everything seems OK return 0 for retry or any non 0 value to give up.</p> <p>If everything seems OK return 0 for retry or any non 0 value to give up.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb8-1" title="1"><span class="co"># called when bashbot sedn command failed because we can not connect to telegram</span></a> <div class="sourceCode" id="cb8"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1"></a><span class="co"># called when bashbot sedn command failed because we can not connect to telegram</span></span>
<a class="sourceLine" id="cb8-2" title="2"><span class="co"># return 0 to retry, return non 0 to give up</span></a> <span id="cb8-2"><a href="#cb8-2"></a><span class="co"># return 0 to retry, return non 0 to give up</span></span>
<a class="sourceLine" id="cb8-3" title="3"><span class="fu">bashbotBlockRecover()</span> <span class="kw">{</span></a> <span id="cb8-3"><a href="#cb8-3"></a><span class="fu">bashbotBlockRecover()</span> <span class="kw">{</span></span>
<a class="sourceLine" id="cb8-4" title="4"> <span class="co"># place your commands to unblock here, e.g. change IP-Adess or simply wait</span></a> <span id="cb8-4"><a href="#cb8-4"></a> <span class="co"># place your commands to unblock here, e.g. change IP-Adess or simply wait</span></span>
<a class="sourceLine" id="cb8-5" title="5"> <span class="fu">sleep</span> 60 <span class="kw">&amp;&amp;</span> <span class="bu">return</span> 0 <span class="co"># may be temporary</span></a> <span id="cb8-5"><a href="#cb8-5"></a> <span class="fu">sleep</span> 60 <span class="kw">&amp;&amp;</span> <span class="bu">return</span> 0 <span class="co"># may be temporary</span></span>
<a class="sourceLine" id="cb8-6" title="6"> <span class="bu">return</span> 1 </a> <span id="cb8-6"><a href="#cb8-6"></a> <span class="bu">return</span> 1 </span>
<a class="sourceLine" id="cb8-7" title="7"> <span class="kw">}</span></a> <span id="cb8-7"><a href="#cb8-7"></a> <span class="kw">}</span></span>
<a class="sourceLine" id="cb8-8" title="8"></a></code></pre></div> <span id="cb8-8"><a href="#cb8-8"></a></span></code></pre></div>
<p>@Gnadelwartz</p> <p>@Gnadelwartz</p>
<h2>That's it all guys!</h2> <h2>That's it all guys!</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$$ v1.1-29-ga1773cc</h4> <h4>$$VERSION$$ v1.2-pre2-0-g2824487</h4>
</body> </body>
</html> </html>

View File

@ -265,4 +265,4 @@ bashbotBlockRecover() {
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$$ v1.1-29-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487

View File

@ -151,10 +151,9 @@ debug`
│   ├── BASHBOT.log # log what your bot is doing ... │   ├── BASHBOT.log # log what your bot is doing ...
│   ├── ERROR.log # connection errors from / to telegram API │   ├── ERROR.log # connection errors from / to telegram API
│   │ │   │
│   ├── DEBUG.log # stdout/stderr of you bot (debug mode │   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled)
│   └── MESSAGE.log # full text of all message send/received (debug mode
enabled) enabled)
│   └── MESSAGE.log # full text of all message send/received
(debug mode enabled)
``` ```
---- ----
@ -356,4 +355,4 @@ wait
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$$ v1.1-29-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487

View File

@ -6,7 +6,7 @@
# #
# tested on: ubuntu, opensuse # tested on: ubuntu, opensuse
# #
#### $$VERSION$$ v1.2-pre2-0-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# shellcheck disable=SC2009 # shellcheck disable=SC2009
# shellcheck disable=SC2181 # shellcheck disable=SC2181

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$$ v1.2-pre2-2-g11c1d55 #### $$VERSION$$ v1.2-pre2-0-g2824487
# #
# Exit Codes: # Exit Codes:
# - 0 success (hopefully) # - 0 success (hopefully)
@ -22,6 +22,7 @@
# - 5 cannot connect to telegram bot # - 5 cannot connect to telegram bot
# - 6 mandatory module not found # - 6 mandatory module not found
# - 7 can't get bottoken # - 7 can't get bottoken
# - 8 curl/wget missing
# - 10 not bash! # - 10 not bash!
# shellcheck disable=SC2140,SC2031,SC2120,SC1091,SC1117 # shellcheck disable=SC2140,SC2031,SC2120,SC1091,SC1117
@ -385,6 +386,7 @@ get_file() {
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')" printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
} }
# curl is preferred, try detect curl even not in PATH
# return TRUE if curl is found or custom curl detected # return TRUE if curl is found or custom curl detected
# return FALSE if no curl is found or wget is forced by BASHBOT_WGET # return FALSE if no curl is found or wget is forced by BASHBOT_WGET
# sets BASHBOT_CURL to point to curl # sets BASHBOT_CURL to point to curl
@ -421,8 +423,8 @@ TIMEOUT="${BASHBOT_TIMEOUT}"
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20" [[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
if detect_curl ; then if detect_curl ; then
# here we have curl ----
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl" [ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
# simple curl or wget call, output to stdout
getJson(){ getJson(){
[[ -n "${BASHBOTDEBUG}" && -n "${3}" ]] && printf "%s: getJson (curl) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}" [[ -n "${BASHBOTDEBUG}" && -n "${3}" ]] && printf "%s: getJson (curl) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -459,14 +461,15 @@ if detect_curl ; then
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" & [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
} }
else else
# simple curl or wget call outputs result to stdout # NO curl, try wget
getJson(){ if _exists wget; then
getJson(){
[[ -n "${BASHBOTDEBUG}" && -z "${3}" ]] && printf "%s: getJson (wget) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}" [[ -n "${BASHBOTDEBUG}" && -z "${3}" ]] && printf "%s: getJson (wget) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1" wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1"
} }
# usage: sendJson "chat" "JSON" "URL" # usage: sendJson "chat" "JSON" "URL"
sendJson(){ sendJson(){
local chat=""; local chat="";
[ -n "${1}" ] && chat='"chat_id":'"${1}"',' [ -n "${1}" ] && chat='"chat_id":'"${1}"','
[ -n "${BASHBOTDEBUG}" ] &&\ [ -n "${BASHBOTDEBUG}" ] &&\
@ -476,12 +479,21 @@ else
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -b -n 2>/dev/null )" --header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -b -n 2>/dev/null )"
sendJsonResult "${res}" "sendJson (wget)" "$@" sendJsonResult "${res}" "sendJson (wget)" "$@"
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" & [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" &
} }
sendUpload() { sendUpload() {
log_error "Sorry, wget does not support file upload" log_error "Sorry, wget does not support file upload"
BOTSENT[OK]="false" BOTSENT[OK]="false"
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" & [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
} }
else
# ups, no curl AND no wget
if [ -n "${BASHBOT_WGET}" ]; then
printf "%s: Error: You set BASHBOT_WGET but no wget found!\n" "$(date)"
else
printf "%s: Error: You must at least install curl or wget\n" "$(date)"
fi
exit 8
fi
fi fi
# retry sendJson # retry sendJson

View File

@ -15,7 +15,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$$ v1.1-29-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# #
# adjust your language setting here, e.g. when run from other user or cron. # adjust your language setting here, e.g. when run from other user or cron.

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v1.2-pre2-1-gb5caff0 #### $$VERSION$$ v1.2-pre2-0-g2824487
############ ############
# NOTE: you MUST run install-hooks.sh again when updating this file! # NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -349,5 +349,5 @@ fi
#### [Prev Function Reference](6_reference.md) #### [Prev Function Reference](6_reference.md)
#### $$VERSION$$ v1.2-pre2-1-gb5caff0 #### $$VERSION$$ v1.2-pre2-0-g2824487

View File

@ -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)
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.2-pre2-0-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# 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

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist # files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ... # copy to mycommands.sh and add all your commands and functions here ...
# #
#### $$VERSION$$ v1.2-pre2-0-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# #
# shellcheck disable=SC2154,SC2034,SC1117,SC2221,SC2222 # shellcheck disable=SC2154,SC2034,SC1117,SC2221,SC2222

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.2-pre2-0-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# will be automatically sourced from bashbot # will be automatically sourced from bashbot

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.2-pre2-0-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# will be automatically sourced from bashbot # will be automatically sourced from bashbot

View File

@ -9,7 +9,7 @@
# #### mycommands.clean # #### mycommands.clean
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.2-pre2-0-ga1773cc #### $$VERSION$$ v1.2-pre2-0-g2824487
# #
# uncomment the following lines to overwrite info and help messages # uncomment the following lines to overwrite info and help messages