fix if TMPDIR is empty and path may point to /

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-08 12:11:17 +02:00
parent 34d2e3de5c
commit e936e6fe39

View File

@ -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.6-dev-5-g18b3b51 #### $$VERSION$$ v0.6-dev-6-g34d2e3d
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -136,7 +136,7 @@ send_message() {
} }
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"
sent=y sent=y
fi fi
@ -383,15 +383,15 @@ forward() {
background() { background() {
echo "${CHAT[ID]}:$2:$1" >"$TMPDIR/${copname}$2-back.cmd" echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname}$2-back.cmd"
startproc "$1" "back-$2-" startproc "$1" "back-$2-"
} }
startproc() { startproc() {
killproc "$2" killproc "$2"
local fifo="$2${copname}" # add $1 to copname, so we can have more than one running script per chat local fifo="$2${copname}" # add $1 to copname, so we can have more than one running script per chat
mkfifo "$TMPDIR/${fifo}" mkfifo "${TMPDIR:-.}/${fifo}"
TMUX= tmux new-session -d -s "${fifo}" "$1 &>$TMPDIR/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>$TMPDIR/${fifo}" TMUX= tmux new-session -d -s "${fifo}" "$1 &>${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}"
} }
@ -406,12 +406,12 @@ checkproc() {
killback() { killback() {
killproc "back-$1-" killproc "back-$1-"
rm -f "$TMPDIR/${copname}$1-back.cmd" rm -f "${TMPDIR:-.}/${copname}$1-back.cmd"
} }
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() {
@ -429,7 +429,7 @@ process_updates() {
done done
} }
process_client() { process_client() {
local TMP="$TMPDIR/$RANDOM$RANDOM-MESSAGE" local TMP="${TMPDIR:-.}/$RANDOM$RANDOM-MESSAGE"
echo "$UPDATE" >"$TMP" echo "$UPDATE" >"$TMP"
# Message # Message
MESSAGE[0]="$(echo -e "$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","text"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")" | sed 's#\\/#/#g')" MESSAGE[0]="$(echo -e "$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","text"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")" | sed 's#\\/#/#g')"
@ -533,8 +533,8 @@ case "$1" in
line="" line=""
read -r -t 10 line read -r -t 10 line
[ "$line" != "" ] && [ "$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."
@ -577,8 +577,8 @@ case "$1" in
"background" | "resumeback") "background" | "resumeback")
$CLEAR $CLEAR
echo -e "${GREEN}Restart background processes ...${NC}" echo -e "${GREEN}Restart background processes ...${NC}"
for FILE in "${TMPDIR}/"*-back.cmd; do for FILE in "${TMPDIR:-.}/"*-back.cmd; do
if [ "$FILE" == "${TMPDIR}/*-back.cmd" ]; then if [ "$FILE" == "${TMPDIR:-.}/*-back.cmd" ]; then
echo -e "${RED}No background processes to start.${NC}"; break echo -e "${RED}No background processes to start.${NC}"; break
else else
RESTART="$(cat "$FILE")" RESTART="$(cat "$FILE")"
@ -588,9 +588,9 @@ 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
@ -604,8 +604,8 @@ case "$1" in
"killback" | "suspendback") "killback" | "suspendback")
$CLEAR $CLEAR
echo -e "${GREEN}Stopping background processes ...${NC}" echo -e "${GREEN}Stopping background processes ...${NC}"
for FILE in "${TMPDIR}/"*-back.cmd; do for FILE in "${TMPDIR:-.}/"*-back.cmd; do
if [ "$FILE" == "${TMPDIR}/*-back.cmd" ]; then if [ "$FILE" == "${TMPDIR:-.}/*-back.cmd" ]; then
echo -e "${RED}No background processes.${NC}"; break echo -e "${RED}No background processes.${NC}"; break
else else
REMOVE="$(cat "$FILE")" REMOVE="$(cat "$FILE")"
@ -613,7 +613,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
;; ;;