From 614eae85c74c526ad071fe9e827e96275284776d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 1 Apr 2019 18:24:05 +0200 Subject: [PATCH] start using shellcheck --- bashbot.rc | 5 ++++- commands.sh | 19 +++++++++++-------- notify | 2 +- question | 6 +++--- version | 11 ++++++----- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 631f20e..83a4acc 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,10 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.5-rc-4-g92e9e9c +#### $$VERSION$$ v0.6-dev-2-gda5e96d +# shellcheck disable=SC2009 +# shellcheck disable=SC2181 + # ### BEGIN INIT INFO # Provides: bashbot diff --git a/commands.sh b/commands.sh index cd3eadb..406441b 100755 --- a/commands.sh +++ b/commands.sh @@ -4,7 +4,10 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.5-rc-3-gf67503c +#### $$VERSION$$ v0.6-dev-2-gda5e96d +# +# shellcheck disable=SC2154 +# shellcheck disable=SC2034 # adjust your language setting here, e.g.when run from other user or cron. # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment @@ -26,11 +29,11 @@ if [ "$1" = "source" ];then else if ! tmux ls | grep -v send | grep -q "$copname"; then [ ! -z "${URLS[*]}" ] && { - curl -s ${URLS[*]} -o $NAME + curl -s "${URLS[*]}" -o "$NAME" send_file "${CHAT[ID]}" "$NAME" "$CAPTION" rm -f "$NAME" } - [ ! -z ${LOCATION[*]} ] && send_location "${CHAT[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" + [ ! -z "${LOCATION[*]}" ] && send_location "${CHAT[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" # Inline if [ $INLINE == 1 ]; then @@ -61,7 +64,7 @@ else case "$MESSAGE" in '/question') checkproc - if [ $res -gt 0 ] ; then + if [ "$res" -gt 0 ] ; then startproc "./question" else send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." @@ -70,7 +73,7 @@ else '/run-notify') myback="notify"; checkback "$myback" - if [ $res -gt 0 ] ; then + if [ "$res" -gt 0 ] ; then background "./notify 60" "$myback" # notify every 60 seconds else send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." @@ -78,7 +81,7 @@ else ;; '/stop-notify') myback="notify"; checkback "$myback" - if [ $res -eq 0 ] ; then + if [ "$res" -eq 0 ] ; then killback "$myback" send_normal_message "${CHAT[ID]}" "Background command $myback canceled." else @@ -120,10 +123,10 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) '/cancel') checkprog - if [ $res -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi + if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi ;; *) - if tmux ls | grep -v send | grep -q $copname;then inproc; else send_message "${CHAT[ID]}" "$MESSAGE" "safe";fi + if tmux ls | grep -v send | grep -q "$copname";then inproc; else send_message "${CHAT[ID]}" "$MESSAGE" "safe";fi ;; esac fi diff --git a/notify b/notify index 9e09814..6f990bf 100755 --- a/notify +++ b/notify @@ -2,7 +2,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) -#### $$VERSION$$ v0.5-rc-3-gf67503c +#### $$VERSION$$ v0.6-dev-2-gda5e96d # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/question b/question index 96cd161..8fcf0fd 100755 --- a/question +++ b/question @@ -3,7 +3,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) -#### $$VERSION$$ v0.5-rc-3-gf67503c +#### $$VERSION$$ v0.6-dev-2-gda5e96d # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment @@ -16,11 +16,11 @@ unset IFS echo "Why hello there. Would you like some tea (y/n)?" -read answer +read -r answer [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]] && echo "OK then, here you go: http://www.rivertea.com/blog/wp-content/uploads/2013/12/Green-Tea.jpg" || echo "OK then." until [ "$SUCCESS" = "y" ] ;do echo 'Do you like Music? mykeyboardstartshere "Yass!" "No"' - read answer + read -r answer case $answer in 'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;; 'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;; diff --git a/version b/version index 79e21fe..e1695fd 100755 --- a/version +++ b/version @@ -1,6 +1,7 @@ -#!/bin/sh +#!/bin/bash # -#### $$VERSION$$ v0.5-rc-3-gf67503c +#### $$VERSION$$ v0.6-dev-2-gda5e96d +# shellcheck disable=SC2016 # # Easy Versioning in git: # @@ -36,15 +37,15 @@ unset IFS # set -f # if you are paranoid use set -f to disable globbing -VERSION="`git describe --tags --long`" +VERSION="$(git describe --tags --long)" echo "Update files to version $VERSION ..." -for file in `ls` +for file in * do [ ! -f "$file" ] && continue #[ "$file" == "version" ] && continue echo -n " $file" - sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '$VERSION'/' $file + sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '"$VERSION"'/' "$file" done echo " done."