TMPDIR is used from BASH -> DATADIR
This commit is contained in:
parent
59aa9fca8b
commit
f2f5e11610
36
bashbot.sh
36
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" )
|
||||
|
|
|
@ -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#*:}"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 "."
|
||||
|
|
Loading…
Reference in New Issue