examples: format and run shellcheck

~~~
shfmt -i 2 -ci -w examples
shellcheck examples/*
~~~
master
Michael Santos 4 years ago
parent 11ee1c92f4
commit 25d8272656

@ -9,7 +9,7 @@ trap cleanup 0
BOT_DEBUG=${BOT_DEBUG-""}
if [ "$BOT_DEBUG" ]; then
set -x
set -x
fi
TMPDIR=$(mktemp -d)
@ -17,11 +17,11 @@ TMPDIR=$(mktemp -d)
in="$TMPDIR/stdin"
out="$TMPDIR/stdout"
mkfifo $in
mkfifo $out
mkfifo "$in"
mkfifo "$out"
cleanup() {
rm -rf $TMPDIR
rm -rf "$TMPDIR"
}
decode() {
@ -33,15 +33,16 @@ bot() {
while IFS=: read stanza type from to body; do
case "$stanza" in
m) ;;
p) decode "$stanza:$type:$from:$to" 1>&2
p)
decode "$stanza:$type:$from:$to" 1>&2
echo 1>&2
continue
;;
*) continue ;;
esac
USER="$(decode ${from#*/})"
MSG="$(decode ${body})"
USER="$(decode "${from#*/}")"
MSG="$(decode "$body")"
case $MSG in
*"has set the subject to:"*) ;;
@ -62,7 +63,7 @@ bot() {
exit 0
;;
debug)
DEBUG=$(( DEBUG ? 0 : 1 ))
DEBUG=$((DEBUG ? 0 : 1))
;;
*)
if [ "$DEBUG" == "0" ]; then
@ -72,8 +73,8 @@ bot() {
fi
;;
esac
done < $out
done <"$out"
}
bot > $in &
xmppipe "$@" <$in >$out
bot >"$in" &
xmppipe "$@" <"$in" >"$out"

@ -17,7 +17,7 @@ set -o nounset
set -o pipefail
if [ "$DEBUG" ]; then
set -x
set -x
fi
PROGNAME=$0
@ -25,10 +25,11 @@ TMPDIR=$(mktemp -d)
out=$TMPDIR/out
atexit() {
rm -rf $TMPDIR
rm -rf "$TMPDIR"
}
decode() {
# shellcheck disable=SC2034
while IFS=: read stanza type from to body; do
case "$stanza" in
m) printf '%b' "${body//%/\\x}" ;;
@ -39,31 +40,35 @@ decode() {
server() {
CONNECT=0
xmppipe -e -r server -o $1 -b 1024 -x < /dev/null | \
xmppipe -e -r server -o "$1" -b 1024 -x </dev/null |
while IFS=: read stanza rest; do
case "$stanza" in
p)
CONNECT=$((CONNECT + 1))
if [ "$CONNECT" -gt "1" ]; then
# shellcheck disable=SC2068
exec "$PROGNAME" session $@
fi
;;
*) ;;
esac
done > /dev/null
done >/dev/null
}
session(){
mkdir -p $TMPDIR
session() {
mkdir -p "$TMPDIR"
trap atexit 0
mkfifo $out
mkfifo "$out"
nc $2 $3 < $out | xmppipe -P 100 -r session -o $1 -x -s | decode > $out
nc "$2" "$3" <"$out" |
xmppipe -P 100 -r session -o "$1" -x -s |
decode >"$out"
}
client() {
xmppipe -P 100 -r client -o $1 -x -s | decode
xmppipe -P 100 -r client -o "$1" -x -s | decode
}
# shellcheck disable=SC2068
$@

Loading…
Cancel
Save