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,63 +17,64 @@ 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() {
printf '%b' "${1//%/\\x}"
printf '%b' "${1//%/\\x}"
}
bot() {
local DEBUG=0
while IFS=: read stanza type from to body; do
case "$stanza" in
m) ;;
p) decode "$stanza:$type:$from:$to" 1>&2
echo 1>&2
continue
;;
*) continue ;;
esac
local DEBUG=0
while IFS=: read stanza type from to body; do
case "$stanza" in
m) ;;
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:"*) ;;
"sudo make me a sandwich")
echo "$USER: you're a sandwich"
;;
sudo*)
echo "I'm sorry, $USER. I'm afraid I can't do that."
;;
uptime)
uptime
;;
runtime)
LC_ALL=POSIX ps -o etime= $$
;;
exit)
echo "exiting ..."
exit 0
;;
debug)
DEBUG=$(( DEBUG ? 0 : 1 ))
;;
*)
if [ "$DEBUG" == "0" ]; then
printf "%s: %s\n" "$USER" "$MSG"
else
echo "$MSG"
fi
;;
esac
done < $out
case $MSG in
*"has set the subject to:"*) ;;
"sudo make me a sandwich")
echo "$USER: you're a sandwich"
;;
sudo*)
echo "I'm sorry, $USER. I'm afraid I can't do that."
;;
uptime)
uptime
;;
runtime)
LC_ALL=POSIX ps -o etime= $$
;;
exit)
echo "exiting ..."
exit 0
;;
debug)
DEBUG=$((DEBUG ? 0 : 1))
;;
*)
if [ "$DEBUG" == "0" ]; then
printf "%s: %s\n" "$USER" "$MSG"
else
echo "$MSG"
fi
;;
esac
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,45 +25,50 @@ TMPDIR=$(mktemp -d)
out=$TMPDIR/out
atexit() {
rm -rf $TMPDIR
rm -rf "$TMPDIR"
}
decode() {
while IFS=: read stanza type from to body; do
case "$stanza" in
m) printf '%b' "${body//%/\\x}" ;;
*) ;;
esac
done
# shellcheck disable=SC2034
while IFS=: read stanza type from to body; do
case "$stanza" in
m) printf '%b' "${body//%/\\x}" ;;
*) ;;
esac
done
}
server() {
CONNECT=0
xmppipe -e -r server -o $1 -b 1024 -x < /dev/null | \
CONNECT=0
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
exec "$PROGNAME" session $@
fi
;;
*) ;;
esac
done > /dev/null
case "$stanza" in
p)
CONNECT=$((CONNECT + 1))
if [ "$CONNECT" -gt "1" ]; then
# shellcheck disable=SC2068
exec "$PROGNAME" session $@
fi
;;
*) ;;
esac
done >/dev/null
}
session(){
mkdir -p $TMPDIR
trap atexit 0
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