From f2f5e116101df2b47bb66a2c207744b5775590c5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 28 May 2019 20:44:40 +0200 Subject: [PATCH] TMPDIR is used from BASH -> DATADIR --- bashbot.sh | 36 ++++++++++++++++++------------------ modules/background.sh | 16 ++++++++-------- modules/sendMessage.sh | 4 ++-- test/d-send_message-test.sh | 4 ++-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index b950b8f..2e46037 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.90-dev2-9-gbbbc8ae +#### $$VERSION$$ v0.90-dev2-11-g59aa9fc # # Exit Codes: # - 0 sucess (hopefully) @@ -106,12 +106,12 @@ if [ ! -f "${BOTACL}" ]; then printf '\n' >"${BOTACL}" fi -TMPDIR="${BASHBOT_VAR:-.}/data-bot-bash" -if [ ! -d "${TMPDIR}" ]; then - mkdir "${TMPDIR}" -elif [ ! -w "${TMPDIR}" ]; then - echo -e "${RED}ERROR: Can't write to ${TMPDIR}!.${NC}" - ls -ld "${TMPDIR}" +DATADIR="${BASHBOT_VAR:-.}/data-bot-bash" +if [ ! -d "${DATADIR}" ]; then + mkdir "${DATADIR}" +elif [ ! -w "${DATADIR}" ]; then + echo -e "${RED}ERROR: Can't write to ${DATADIR}!.${NC}" + ls -ld "${DATADIR}" exit 2 fi @@ -157,14 +157,14 @@ fi ################# # BASHBOT INTERNAL functions -# $1 URL, $2 filename in TMPDIR +# $1 URL, $2 filename in DATADIR # outputs final filename download() { local empty="no.file" file="${2:-${empty}}" if [[ "$file" = *"/"* ]] || [[ "$file" = "."* ]]; then file="${empty}"; fi - while [ -f "${TMPDIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done - getJson "$1" >"${TMPDIR:-.}/${file}" || return - printf '%s\n' "${TMPDIR:-.}/${file}" + while [ -f "${DATADIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done + getJson "$1" >"${DATADIR:-.}/${file}" || return + printf '%s\n' "${DATADIR:-.}/${file}" } # $1 postfix, e.g. chatid @@ -566,8 +566,8 @@ start_bot() { [ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\"" [[ "${DEBUG}" = "xdebug"* ]] && set -x #cleaup old pipes and empty logfiles - find "${TMPDIR}" -type p -delete - find "${TMPDIR}" -size 0 -name "*.log" -delete + find "${DATADIR}" -type p -delete + find "${DATADIR}" -size 0 -name "*.log" -delete # load addons on startup for addons in ${ADDONDIR:-.}/*.sh ; do # shellcheck source=./modules/aliases.sh @@ -597,7 +597,7 @@ bot_init() { local DEBUG="$1" # upgrade from old version local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash" - [ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${TMPDIR}"; rmdir "${OLDTMP}"; } + [ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${DATADIR}"; rmdir "${OLDTMP}"; } [ -f "modules/inline.sh" ] && rm -f "modules/inline.sh" # load addons on startup for addons in ${ADDONDIR:-.}/*.sh ; do @@ -622,8 +622,8 @@ bot_init() { chown -R "$TOUSER" . ./* chmod 711 . chmod -R a-w ./* - chmod -R u+w "${COUNTFILE}" "${TMPDIR}" "${BOTADMIN}" ./*.log 2>/dev/null - chmod -R o-r,o-w "${COUNTFILE}" "${TMPDIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null + chmod -R u+w "${COUNTFILE}" "${DATADIR}" "${BOTADMIN}" ./*.log 2>/dev/null + chmod -R o-r,o-w "${COUNTFILE}" "${DATADIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null ls -la fi } @@ -665,8 +665,8 @@ if [ "${SOURCE}" != "yes" ]; then while read -r line ;do [ "$line" != "" ] && send_message "$2" "$line" done - rm -f -r "${TMPDIR:-.}/$3" - [ -s "${TMPDIR:-.}/$3.log" ] || rm -f "${TMPDIR:-.}/$3.log" + rm -f -r "${DATADIR:-.}/$3" + [ -s "${DATADIR:-.}/$3.log" ] || rm -f "${DATADIR:-.}/$3.log" exit ;; "startbot" ) diff --git a/modules/background.sh b/modules/background.sh index dec0030..cdd5347 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,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.90-dev2-0-gec85636 +#### $$VERSION$$ v0.90-dev2-11-g59aa9fc # source from commands.sh if you want ro use interactive or background jobs @@ -37,7 +37,7 @@ killproc() { # $2 program # $3 jobname start_back() { - local fifo; fifo="${TMPDIR:-.}/$(procname "$1")" + local fifo; fifo="${DATADIR:-.}/$(procname "$1")" printf '%s\n' "$1:$3:$2" >"${fifo}$3-back.cmd" start_proc "$1" "$2" "back-$3-" } @@ -49,7 +49,7 @@ start_back() { start_proc() { [ "$2" = "" ] && return [ -x "${2%% *}" ] || return 1 - local fifo; fifo="${TMPDIR:-.}/$(procname "$1" "$3")" + local fifo; fifo="${DATADIR:-.}/$(procname "$1" "$3")" kill_proc "$1" "$3" mkfifo "${fifo}" nohup bash -c "{ tail -f < \"${fifo}\" | $2 \"\" \"\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\" @@ -75,7 +75,7 @@ check_proc() { # $2 jobname kill_back() { kill_proc "$1" "back-$2-" - rm -f "${TMPDIR:-.}/$(procname "$1")$2-back.cmd" + rm -f "${DATADIR:-.}/$(procname "$1")$2-back.cmd" } @@ -85,7 +85,7 @@ kill_proc() { local fifo prid fifo="$(procname "$1" "$2")" prid="$(proclist "${fifo}")" - fifo="${TMPDIR:-.}/${fifo}" + fifo="${DATADIR:-.}/${fifo}" # shellcheck disable=SC2086 [ "${prid}" != "" ] && kill ${prid} [ -s "${fifo}.log" ] || rm -f "${fifo}.log" @@ -95,7 +95,7 @@ kill_proc() { # $1 chat # $2 message send_interactive() { - local fifo; fifo="${TMPDIR:-.}/$(procname "$1")" + local fifo; fifo="${DATADIR:-.}/$(procname "$1")" [ -p "${fifo}" ] && printf '%s\n' "$2" >"${fifo}" & # not blocking! } @@ -111,8 +111,8 @@ inproc() { # resumeb* job_control() { local content proc CHAT job fifo killall="" - for FILE in "${TMPDIR:-.}/"*-back.cmd; do - [ "${FILE}" = "${TMPDIR:-.}/*-back.cmd" ] && echo -e "${RED}No background processes.${NC}" && break + for FILE in "${DATADIR:-.}/"*-back.cmd; do + [ "${FILE}" = "${DATADIR:-.}/*-back.cmd" ] && echo -e "${RED}No background processes.${NC}" && break content="$(< "${FILE}")" CHAT="${content%%:*}" job="${content#*:}" diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index bd8aec2..6f20766 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,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.90-dev2-0-gec85636 +#### $$VERSION$$ v0.90-dev2-11-g59aa9fc # source from commands.sh to use the sendMessage functions @@ -85,7 +85,7 @@ send_button() { } -UPLOADDIR="${BASHBOT_UPLOAD:-${TMPDIR}/upload}" +UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}" # for now this can only send local files with curl! # extend to allow send files by URL or telegram ID diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index a114305..0b8a658 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.90-dev2-0-gec85636 +#### $$VERSION$$ v0.90-dev2-11-g59aa9fc # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -42,7 +42,7 @@ ALLOW='/tmp/allowed' FILE_REGEX="$ALLOW/.*" [ -d "$ALLOW" ] || mkdir "$ALLOW" touch "$ALLOW/this_is_my.gif" "$ALLOW/this_is_my.doc" -touch "$TMPDIR/this_is_my.gif" "$TMPDIR/this_is_my.doc" +touch "$DATADIR/this_is_my.gif" "$DATADIR/this_is_my.doc" while read -r line ; do echo -n "."