mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-01-01 06:11:46 +00:00
first shellcheck iteration for bashbot.sh
This commit is contained in:
parent
614eae85c7
commit
b4e13bd354
@ -447,4 +447,4 @@ No - its not less (in)secure as any other Bot written in any other language. But
|
|||||||
|
|
||||||
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.6-dev-1-gf463a1f
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
|
@ -7,7 +7,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.5-rc-4-g92e9e9c
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
|
|
||||||
|
|
||||||
SHELL=/bin/sh
|
SHELL=/bin/sh
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# description: Start or stop telegram-bash-bot
|
# description: Start or stop telegram-bash-bot
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.6-dev-2-gda5e96d
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
# shellcheck disable=SC2009
|
# shellcheck disable=SC2009
|
||||||
# shellcheck disable=SC2181
|
# shellcheck disable=SC2181
|
||||||
|
|
||||||
|
105
bashbot.sh
105
bashbot.sh
@ -10,7 +10,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.5-rc-4-g92e9e9c
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -29,8 +29,8 @@ if [ -t 1 ] && [ "$TERM" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# get location of bashbot.sh an change to bashbot dir
|
# get location of bashbot.sh an change to bashbot dir
|
||||||
SCRIPT="./$(basename $0)"
|
SCRIPT="./$(basename "$0")"
|
||||||
SCRIPTDIR="$(dirname $0)"
|
SCRIPTDIR="$(dirname "$0")"
|
||||||
|
|
||||||
if ! cd "${SCRIPTDIR}" ; then
|
if ! cd "${SCRIPTDIR}" ; then
|
||||||
echo -e "${RED}ERROR: Can't change to ${SCRIPTDIR} ...${NC}"
|
echo -e "${RED}ERROR: Can't change to ${SCRIPTDIR} ...${NC}"
|
||||||
@ -52,7 +52,7 @@ if [ ! -f "token" ]; then
|
|||||||
$CLEAR
|
$CLEAR
|
||||||
echo -e "${RED}TOKEN MISSING.${NC}"
|
echo -e "${RED}TOKEN MISSING.${NC}"
|
||||||
echo -e "${ORANGE}PLEASE WRITE YOUR TOKEN HERE${NC}"
|
echo -e "${ORANGE}PLEASE WRITE YOUR TOKEN HERE${NC}"
|
||||||
read token
|
read -r token
|
||||||
echo "$token" >> "token"
|
echo "$token" >> "token"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ FORWARD_URL=$URL'/forwardMessage'
|
|||||||
INLINE_QUERY=$URL'/answerInlineQuery'
|
INLINE_QUERY=$URL'/answerInlineQuery'
|
||||||
ME_URL=$URL'/getMe'
|
ME_URL=$URL'/getMe'
|
||||||
DELETE_URL=$URL'/deleteMessage'
|
DELETE_URL=$URL'/deleteMessage'
|
||||||
ME=$(curl -s $ME_URL | ./JSON.sh/JSON.sh -s | egrep '\["result","username"\]' | cut -f 2 | cut -d '"' -f 2)
|
ME=$(curl -s "$ME_URL" | ./JSON.sh/JSON.sh -s | grep '\["result","username"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
|
||||||
|
|
||||||
FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
|
FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
|
||||||
@ -113,47 +113,48 @@ urlencode() {
|
|||||||
|
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
|
local chat, text, arg, keyboard, file, lat long, title, adress, sent
|
||||||
[ "$2" = "" ] && return 1
|
[ "$2" = "" ] && return 1
|
||||||
local chat="$1"
|
chat="$1"
|
||||||
local text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
local arg="$3"
|
arg="$3"
|
||||||
[ "$3" != "safe" ] && {
|
[ "$arg" != "safe" ] && {
|
||||||
text="$(echo "$text" | sed 's/ mynewlinestartshere /\r\n/g')" # hack for linebreaks in startproc scripts
|
text="$(echo "$text" | sed 's/ mynewlinestartshere /\r\n/g')" # hack for linebreaks in startproc scripts
|
||||||
local no_keyboard="$(echo $2 | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
|
no_keyboard="$(echo "$2" | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
|
||||||
|
|
||||||
local keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local file="$(echo "$2" | sed '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
file="$(echo "$2" | sed '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local lat="$(echo "$2" | sed '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
lat="$(echo "$2" | sed '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')"
|
address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
}
|
}
|
||||||
if [ "$no_keyboard" != "" ]; then
|
if [ "$no_keyboard" != "" ]; then
|
||||||
echo "remove_keyboard $chat $text" > $TMPDIR/prova
|
echo "remove_keyboard $chat $text" > $TMPDIR/prova
|
||||||
remove_keyboard "$chat" "$text"
|
remove_keyboard "$chat" "$text"
|
||||||
local sent=y
|
sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$keyboard" != "" ]; then
|
if [ "$keyboard" != "" ]; then
|
||||||
send_keyboard "$chat" "$text" "$keyboard"
|
send_keyboard "$chat" "$text" "$keyboard"
|
||||||
local sent=y
|
sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$file" != "" ]; then
|
if [ "$file" != "" ]; then
|
||||||
send_file "$chat" "$file" "$text"
|
send_file "$chat" "$file" "$text"
|
||||||
local sent=y
|
sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$lat" != "" -a "$long" != "" -a "$address" = "" -a "$title" = "" ]; then
|
if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then
|
||||||
send_location "$chat" "$lat" "$long"
|
send_location "$chat" "$lat" "$long"
|
||||||
local sent=y
|
sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$lat" != "" -a "$long" != "" -a "$address" != "" -a "$title" != "" ]; then
|
if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then
|
||||||
send_venue "$chat" "$lat" "$long" "$title" "$address"
|
send_venue "$chat" "$lat" "$long" "$title" "$address"
|
||||||
local sent=y
|
sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$sent" != "y" ];then
|
if [ "$sent" != "y" ];then
|
||||||
send_text "$chat" "$text"
|
send_text "$chat" "$text"
|
||||||
@ -291,7 +292,7 @@ send_keyboard() {
|
|||||||
local keyboard=init
|
local keyboard=init
|
||||||
OLDIFS=$IFS
|
OLDIFS=$IFS
|
||||||
IFS=$(echo -en "\"")
|
IFS=$(echo -en "\"")
|
||||||
for f in $*;do [ "$f" != " " ] && local keyboard="$keyboard, [\"$f\"]";done
|
for f in "$@" ;do [ "$f" != " " ] && local keyboard="$keyboard, [\"$f\"]";done
|
||||||
IFS=$OLDIFS
|
IFS=$OLDIFS
|
||||||
local keyboard=${keyboard/init, /}
|
local keyboard=${keyboard/init, /}
|
||||||
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")"
|
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")"
|
||||||
@ -305,14 +306,14 @@ remove_keyboard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_file() {
|
get_file() {
|
||||||
[ "$1" != "" ] && echo $FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | egrep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)
|
[ "$1" != "" ] && echo "$FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
send_file() {
|
send_file() {
|
||||||
[ "$2" = "" ] && return
|
[ "$2" = "" ] && return
|
||||||
local chat_id=$1
|
local chat_id=$1
|
||||||
local file=$2
|
local file=$2
|
||||||
echo "$file" | grep -qE $FILE_REGEX || return
|
echo "$file" | grep -qE "$FILE_REGEX" || return
|
||||||
local ext="${file##*.}"
|
local ext="${file##*.}"
|
||||||
case $ext in
|
case $ext in
|
||||||
mp3|flac)
|
mp3|flac)
|
||||||
@ -351,7 +352,7 @@ send_file() {
|
|||||||
local CAPTION="$3"
|
local CAPTION="$3"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
send_action $chat_id $STATUS
|
send_action "$chat_id" "$STATUS"
|
||||||
res="$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$CAPTION")"
|
res="$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$CAPTION")"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +371,7 @@ send_location() {
|
|||||||
send_venue() {
|
send_venue() {
|
||||||
[ "$5" = "" ] && return
|
[ "$5" = "" ] && return
|
||||||
[ "$6" != "" ] add="-F \"foursquare_id=$6\""
|
[ "$6" != "" ] add="-F \"foursquare_id=$6\""
|
||||||
res="$(curl -s "$VENUE_URL" -F "chat_id=$1" -F "latitude=$2" -F "longitude=$3" -F "title=$4" -F "address=$5" $add)"
|
res="$(curl -s "$VENUE_URL" -F "chat_id=$1" -F "latitude=$2" -F "longitude=$3" -F "title=$4" -F "address=$5" $add)" # what is add for?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -409,11 +410,11 @@ killback() {
|
|||||||
|
|
||||||
killproc() {
|
killproc() {
|
||||||
local fifo="$1${copname}"
|
local fifo="$1${copname}"
|
||||||
(tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>$TMPDIR/${fifo}; tmux kill-session -t sendprocess_${fifo}; rm -f -r $TMPDIR/${fifo})2>/dev/null
|
(tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>"$TMPDIR/${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "$TMPDIR/${fifo}")2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
inproc() {
|
inproc() {
|
||||||
tmux send-keys -t $copname "$MESSAGE ${URLS[*]}
|
tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]}
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
process_updates() {
|
process_updates() {
|
||||||
@ -492,7 +493,7 @@ process_client() {
|
|||||||
# Location
|
# Location
|
||||||
LOCATION[LONGITUDE]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","location","longitude"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
|
LOCATION[LONGITUDE]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","location","longitude"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
|
||||||
LOCATION[LATITUDE]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","location","latitude"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
|
LOCATION[LATITUDE]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","location","latitude"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
|
||||||
NAME="$(echo ${URLS[*]} | sed 's/.*\///g')"
|
NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')"
|
||||||
rm "$TMP"
|
rm "$TMP"
|
||||||
|
|
||||||
# Tmux
|
# Tmux
|
||||||
@ -508,10 +509,10 @@ process_client() {
|
|||||||
# source the script with source as param to use functions in other scripts
|
# source the script with source as param to use functions in other scripts
|
||||||
while [ "$1" == "startbot" ]; do {
|
while [ "$1" == "startbot" ]; do {
|
||||||
|
|
||||||
UPDATE="$(curl -s $UPD_URL$OFFSET | ./JSON.sh/JSON.sh)"
|
UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./JSON.sh/JSON.sh)"
|
||||||
|
|
||||||
# Offset
|
# Offset
|
||||||
OFFSET="$(echo "$UPDATE" | egrep '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
|
OFFSET="$(echo "$UPDATE" | grep '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
|
||||||
OFFSET=$((OFFSET+1))
|
OFFSET=$((OFFSET+1))
|
||||||
|
|
||||||
if [ "$OFFSET" != "1" ]; then
|
if [ "$OFFSET" != "1" ]; then
|
||||||
@ -529,24 +530,24 @@ case "$1" in
|
|||||||
"outproc")
|
"outproc")
|
||||||
until [ "$line" = "imprettydarnsuredatdisisdaendofdacmd" ];do
|
until [ "$line" = "imprettydarnsuredatdisisdaendofdacmd" ];do
|
||||||
line=""
|
line=""
|
||||||
read -t 10 line
|
read -r -t 10 line
|
||||||
[ "$line" != "" -a "$line" != "imprettydarnsuredatdisisdaendofdacmd" ] && send_message "$2" "$line"
|
[ "$line" != "" ] && [ "$line" != "imprettydarnsuredatdisisdaendofdacmd" ] && send_message "$2" "$line"
|
||||||
done <$TMPDIR/$3
|
done <"$TMPDIR/$3"
|
||||||
rm -f -r $TMPDIR/$3
|
rm -f -r "$TMPDIR/$3"
|
||||||
;;
|
;;
|
||||||
"count")
|
"count")
|
||||||
echo "A total of $(wc -l ${COUNT} | sed 's/count//g')users used me."
|
echo "A total of $(wc -l "${COUNT}" | sed 's/count//g')users used me."
|
||||||
;;
|
;;
|
||||||
"broadcast")
|
"broadcast")
|
||||||
echo "Sending the broadcast $* to $(wc -l ${COUNT} | sed 's/count//g')users."
|
echo "Sending the broadcast $* to $(wc -l "${COUNT}" | sed 's/count//g')users."
|
||||||
[ "$(wc -l ${COUNT} | sed 's/ count//g')" -gt "300" ] && sleep="sleep 0.5"
|
[ "$(wc -l "${COUNT}" | sed 's/ count//g')" -gt "300" ] && sleep="sleep 0.5"
|
||||||
shift
|
shift
|
||||||
for f in "$(cat ${COUNT})";do send_message ${f//COUNT} "$*"; $sleep;done
|
for f in $(cat "${COUNT}"); do send_message "${f//COUNT}" "$*"; $sleep;done
|
||||||
;;
|
;;
|
||||||
"start")
|
"start")
|
||||||
$CLEAR
|
$CLEAR
|
||||||
tmux kill-session -t $ME&>/dev/null
|
tmux kill-session -t "$ME" &>/dev/null
|
||||||
tmux new-session -d -s $ME "bash $SCRIPT startbot" && echo -e "${GREEN}Bot started successfully.${NC}"
|
tmux new-session -d -s "$ME" "bash $SCRIPT startbot" && echo -e "${GREEN}Bot started successfully.${NC}"
|
||||||
echo "Tmux session name $ME" || echo -e "${RED}An error occurred while starting the bot. ${NC}"
|
echo "Tmux session name $ME" || echo -e "${RED}An error occurred while starting the bot. ${NC}"
|
||||||
send_markdown_message "${CHAT[ID]}" "*Bot started*"
|
send_markdown_message "${CHAT[ID]}" "*Bot started*"
|
||||||
;;
|
;;
|
||||||
@ -554,19 +555,19 @@ case "$1" in
|
|||||||
MYUSER="$USER"
|
MYUSER="$USER"
|
||||||
[[ "$(id -u)" -eq "0" ]] && MYUSER="nobody"
|
[[ "$(id -u)" -eq "0" ]] && MYUSER="nobody"
|
||||||
echo -n "Enter User to run basbot [$MYUSER]: "
|
echo -n "Enter User to run basbot [$MYUSER]: "
|
||||||
read TOUSER
|
read -r TOUSER
|
||||||
[ "$TOUSER" = "" ] && TOUSER="$MYUSER"
|
[ "$TOUSER" = "" ] && TOUSER="$MYUSER"
|
||||||
if ! compgen -u "$TOUSER" 2>&1 >/dev/null; then
|
if ! compgen -u "$TOUSER" >/dev/null 2&>1; then
|
||||||
echo -e "${RED}User \"$TOUSER\" not found!${NC}"
|
echo -e "${RED}User \"$TOUSER\" not found!${NC}"
|
||||||
exit 3
|
exit 3
|
||||||
else
|
else
|
||||||
echo "Adjusting user in bashbot.rc ..."
|
echo "Adjusting user in bashbot.rc ..."
|
||||||
sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' bashbot.rc
|
sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' bashbot.rc
|
||||||
echo "Adjusting Owner and Permissions ..."
|
echo "Adjusting Owner and Permissions ..."
|
||||||
chown -R "$TOUSER" . *
|
chown -R "$TOUSER" . ./*
|
||||||
chmod 711 .
|
chmod 711 .
|
||||||
chmod -R a-w *
|
chmod -R a-w ./*
|
||||||
chmod -R u+w "$COUNT" "$TMPDIR" *.log 2>/dev/null
|
chmod -R u+w "$COUNT" "$TMPDIR" ./*.log 2>/dev/null
|
||||||
chmod -R o-r,o-w "$COUNT" "$TMPDIR" token 2>/dev/null
|
chmod -R o-r,o-w "$COUNT" "$TMPDIR" token 2>/dev/null
|
||||||
ls -la
|
ls -la
|
||||||
exit
|
exit
|
||||||
@ -586,10 +587,10 @@ case "$1" in
|
|||||||
JOB="${JOB%:*}"
|
JOB="${JOB%:*}"
|
||||||
fifo="back-${JOB}-${ME}_${CHAT[ID]}" # compose fifo from jobname, $ME (botname) and CHAT[ID]
|
fifo="back-${JOB}-${ME}_${CHAT[ID]}" # compose fifo from jobname, $ME (botname) and CHAT[ID]
|
||||||
echo "restartbackground ${PROG} ${fifo}"
|
echo "restartbackground ${PROG} ${fifo}"
|
||||||
( tmux kill-session -t "${fifo}"; tmux kill-session -t sendprocess_${fifo}; rm -f -r $TMPDIR/${fifo}) 2>/dev/null
|
( tmux kill-session -t "${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "$TMPDIR/${fifo}") 2>/dev/null
|
||||||
mkfifo "$TMPDIR/${fifo}"
|
mkfifo "$TMPDIR/${fifo}"
|
||||||
TMUX= tmux new-session -d -s "${fifo}" "${PROG} &>$TMPDIR/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>$TMPDIR/${fifo}"
|
TMUX= tmux new-session -d -s "${fifo}" "${PROG} &>$TMPDIR/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>$TMPDIR/${fifo}"
|
||||||
TMUX= tmux new-session -d -s sendprocess_${fifo} "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}"
|
TMUX= tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
@ -611,7 +612,7 @@ case "$1" in
|
|||||||
fifo="back-${JOB%:*}-${ME}_${REMOVE%%:*}"
|
fifo="back-${JOB%:*}-${ME}_${REMOVE%%:*}"
|
||||||
echo "killbackground ${fifo}"
|
echo "killbackground ${fifo}"
|
||||||
[ "$1" == "killback" ] && rm -f "$FILE" # remove job
|
[ "$1" == "killback" ] && rm -f "$FILE" # remove job
|
||||||
( tmux kill-session -t "${fifo}"; tmux kill-session -t sendprocess_${fifo}; rm -f -r $TMPDIR/${fifo}) 2>/dev/null
|
( tmux kill-session -t "${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "$TMPDIR/${fifo}") 2>/dev/null
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
@ -636,7 +637,7 @@ esac
|
|||||||
|
|
||||||
# warn if root
|
# warn if root
|
||||||
if [[ "$(id -u)" -eq "0" ]] ; then
|
if [[ "$(id -u)" -eq "0" ]] ; then
|
||||||
echo -e "\n${ORANGE}WARNING: ${SCRIPT} was started as ROOT (UID 0)!${NC}"
|
echo -e "\\n${ORANGE}WARNING: ${SCRIPT} was started as ROOT (UID 0)!${NC}"
|
||||||
echo -e "${ORANGE}You are at HIGH RISK when processing user input with root privilegs!${NC}"
|
echo -e "${ORANGE}You are at HIGH RISK when processing user input with root privilegs!${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -4,7 +4,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.6-dev-2-gda5e96d
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
#
|
#
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
2
notify
2
notify
@ -2,7 +2,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.6-dev-2-gda5e96d
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
|
|
||||||
# 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
|
||||||
|
2
question
2
question
@ -3,7 +3,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.6-dev-2-gda5e96d
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
||||||
|
|
||||||
# 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
|
||||||
|
Loading…
Reference in New Issue
Block a user