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