dot

packages and services management
Log | Files | Refs | README

commit a4efdee8d9cb4ed031f1aefdd3edc281313a9580
parent 9e5a146c7b4e51abb4cb5239a0951c025827793b
Author: sshbio <jd@ssh.bio>
Date:   Sun, 14 Aug 2016 12:32:04 +0200

i

Diffstat:
Mbin/irc | 59+++++++++++++++++++++++++++++++----------------------------
Mbin/www | 6+++---
2 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/bin/irc b/bin/irc @@ -3,7 +3,7 @@ # \/ _____ ____ # /\ / ____\/ ___\ # / // / / /__ -# \/ \/ \____\ - Irc client in 222 lines of shell script +# \/ \/ \____\ - Irc client in 225 lines of shell script #=============================================================================== NICK="${NICK-$USER}" @@ -24,7 +24,7 @@ write() { local srv="$1" msg="$2" - printf '\r%s\n' "$msg" >> "$DIR/$srv/IN" + printf '\r%s\n' "$msg" | tee -a ~/log >> "$DIR/$srv/IN" } # @@ -53,7 +53,11 @@ input() while read cmd do user="$(tail "$DIR/NICK")" - arg="${cmd#* }" cmd="${cmd#/}" cmd="${cmd%% *}" + arg="$cmd" + if [ -z "${cmd##/*}" ] + then arg="${arg#* }" cmd="${cmd#/}" cmd="${cmd%% *}" + else cmd='' + fi cmd="$(printf %s "$cmd" | tr [a-z] [A-Z])" case "$cmd" in @@ -76,15 +80,17 @@ input() CA="$(printf '\001')" write "$srv" "PRIVMSG $chan :${CA}ACTION ${arg}${CA}" ;; - TOPIC | LIST ) + TOPIC | LIST | MOTD ) write "$srv" "TOPIC ${arg-chan}" ;; ID | IDENTIFY ) + printf '\033[A\r\033[K> /IDENTIFY *****\v\r> ' 1>&2 write "$srv" "PRIVMSG NickServ :IDENTIFY $arg" - printf '\033[A\r\033[K> /IDENTIFY *****\v\r> ' ;; '' ) - write "$srv" "PRIVMSG $chan $arg" + write "$srv" "PRIVMSG $chan :$arg" + print_msg "$user" "$arg" PRIVMSG yes \ + >> "$DIR/$srv/$chan" ;; * ) write "$srv" "$cmd $arg" @@ -99,12 +105,12 @@ input() # message = [ ":" prefix SPACE ] command [ params ] crlf # prefix = servername / ( nickname [ [ "!" user ] "@" host ] ) # command = 1*letter / 3digit -# params = *14( SPACE middle ) [ SPACE ":" trailing ] -# =/ 14( SPACE middle ) [ SPACE [ ":" ] trailing ] +# params = *14( SPACE mid ) [ SPACE ":" trailing ] +# =/ 14( SPACE mid ) [ SPACE [ ":" ] trailing ] # # nospcrlfcl = %x01-09 / %x0B-0C / %x0E-1F / %x21-39 / %x3B-FF # ; any octet except NUL, CR, LF, " " and ":" -# middle = nospcrlfcl *( ":" / nospcrlfcl ) +# mid = nospcrlfcl *( ":" / nospcrlfcl ) # trailing = *( ":" / " " / nospcrlfcl ) # # SPACE = %x20 ; space character @@ -112,14 +118,14 @@ input() # output() { - local srv="$1" user="$(tail "$DIR/NICK")" cmd params middle chan last + local srv="$1" user="$(tail "$DIR/NICK")" + local cmd params mid chan last check while read msg do # Parse server message - local prefix='' nick='' trail='' sep='' - + local prefix='' nick='' trail='' sep='' # Reset msg="${msg#$CR}" msg="${msg%$CR}" if [ -z "${msg##:*}" ] then @@ -130,32 +136,34 @@ output() cmd="${msg%% *}" msg="${msg#* }" params="$msg" - middle="${msg% }" middle="${msg%%:*}" + mid="${msg% }" mid="${msg%%:*}" [ -z "${params%%*:*}" ] && trail="${params#*:}" - chan="${middle%% *}" + chan="${mid%% *}" case "$chan" in - "$user" | '*' | '' ) chan='SERVER' ;; + *"$srv" | "$user" | '*' | '' ) chan='SERVER' ;; esac # Execute action - # Check if the last command was the - if [ ! "$(printf %s "$last" | grep -F "$chan $cmd $nick")" ] + # Single line separator at the right place. + [ "$cmd" = PRIVMSG ] && c="$chan $cmd $nick" || c="$chan $cmd" + if [ ! "$(printf %s "$last" | grep -F "$c")" ] then sep='yes' fi + last="$(printf '%s %s ' "$chan" "$cmd" + [ "$cmd" = PRIVMSG ] && printf %s "$nick" + printf '\n' + printf '%s\n' "$last" | grep -vF "$chan")" case "$cmd" in PING ) - write "$srv" "PONG $params" + write "$srv" "PONG $trail" ;; * ) print_msg "$nick" "$trail" "$cmd" "$sep" \ >> "$DIR/$srv/$chan" ;; esac - - last="$(printf '%s %s %s\n' "$chan $cmd $nick" - printf '%s\n' "$last" | grep -vF "$chan")" done } @@ -195,7 +203,7 @@ print_msg() #------------------------------------------------------------------------------- # Kill background jobs and delete named pipes while quitting -trap 'find "$DIR" -type p -exec rm {} ";"; kill -9 0' INT EXIT +trap 'find "$DIR" -name IN -exec rm {} ";"; kill -9 0' INT EXIT # Prepare the irc log directory [ -d "$DIR" ] || mkdir -p "$DIR" @@ -213,10 +221,5 @@ then printf '%s\n' "$cmd" >> "$DIR/IN" done else - IFS="$NL" - for file in $(find "$DIR" -mindepth 2 -type f) - do files="$files $file" - done - unset IFS - less -R $files + IFS="$NL"; cd "$DIR"; less -R $(find . -mindepth 2 -type f); unset IFS fi diff --git a/bin/www b/bin/www @@ -22,7 +22,7 @@ parse() # Execute the keyword and print its output. case "${input%%\}\}*}" in - *content* ) [ -f "$item/INDEX" ] && cat "$item/INDEX" ;; + *content* ) [ -f "$item/README" ] && cat "$item/README" ;; *list* ) list "$item" ;; *nav* ) parse "$item" "$nav" ;; *root* ) printf %s "$item/" | sed 's/[^/]//g; s/\//..\//g; s/$/./' ;; @@ -37,7 +37,7 @@ list() local IFS="$NL" stat format='<a href="%s">%-30s</a> %s\n' printf '<b>%-30s %-13s %-10s</b>\n' NAME SIZE EDIT - for path in $(find "$1" -mindepth 1 -maxdepth 1 ! -name 'INDEX') + for path in $(find "$1" -mindepth 1 -maxdepth 1 ! -name 'README') do stat="$(stat -c '%-13b %-10y' "$path")" stat="${stat%:*}" printf "$format" "${path#$1/}" "${path#$1/}" "${stat% *}" @@ -56,7 +56,7 @@ nav="${nav% |}" # Create pages from directory structure, copy static files mkdir -p "$OUT" rm -r "$OUT"/* -find . -mindepth 1 ! -path '*/.*' ! -name 'INDEX' | while read path +find . -mindepth 1 ! -path '*/.*' ! -name 'README' | while read path do path="${path#./}" if [ -d "$path" ] then