diff options
Diffstat (limited to 'util/bin')
-rwxr-xr-x | util/bin/TouchpadToggle | 8 | ||||
-rwxr-xr-x | util/bin/anonbox.net | 8 | ||||
-rwxr-xr-x | util/bin/dict.leo.org | 87 | ||||
-rwxr-xr-x | util/bin/galileo | 3 | ||||
-rwxr-xr-x | util/bin/hrefs | 20 | ||||
-rwxr-xr-x | util/bin/lgoinstall | 131 | ||||
-rwxr-xr-x | util/bin/magic | 63 | ||||
-rwxr-xr-x | util/bin/my-global-ipv4-addr | 3 | ||||
-rwxr-xr-x | util/bin/naturalvoices.att | 4 | ||||
-rwxr-xr-x | util/bin/nextpath | 12 | ||||
-rwxr-xr-x | util/bin/sshkill | 33 | ||||
-rwxr-xr-x | util/bin/translate.google | 4 | ||||
-rwxr-xr-x | util/bin/untouch | 8 |
13 files changed, 374 insertions, 10 deletions
diff --git a/util/bin/TouchpadToggle b/util/bin/TouchpadToggle new file mode 100755 index 00000000..17fd46b8 --- /dev/null +++ b/util/bin/TouchpadToggle @@ -0,0 +1,8 @@ +#!/bin/sh +# +#This script toggles the touchpad on a netbook using synclient. + +status=`synclient|awk '/TouchpadOff/{printf$3}'` +status=`expr \( $status + 1 \) \% 2` +synclient TouchpadOff=$status + diff --git a/util/bin/anonbox.net b/util/bin/anonbox.net index d038cd0a..3b648afb 100755 --- a/util/bin/anonbox.net +++ b/util/bin/anonbox.net @@ -13,12 +13,12 @@ GET() { ## retrieve data eval "$(${GET-GET} | - sed -rn ' -s^<dd><p>([[:alnum:]@.]+)</p></dd>$\ + sed -n ' +s^<dd><p>\([[:alnum:]@.]\+\)</p></dd>$\ email="\1" ; p -s^<dd><p><a href="([^"\\]+)">.*</a></p></dd>$\ +s^<dd><p><a href="\([^"\\]\+\)">.*</a></p></dd>$\ uri="\1/" ; p -s^<dd><p>([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+):([0-9]+) ([ap]).m.</p></dd>$\ +s^<dd><p>\([0-9]\+\)/\([0-9]\+\)/\([0-9]\+\) \([0-9]\+\):\([0-9]\+\) \([ap]\).m.</p></dd>$\ Y=20\3 ; \ m=\1 ; \ d=\2 ; \ diff --git a/util/bin/dict.leo.org b/util/bin/dict.leo.org new file mode 100755 index 00000000..03f16b96 --- /dev/null +++ b/util/bin/dict.leo.org @@ -0,0 +1,87 @@ +#! /bin/sh +#### dict.leo.org version 2.0 beta 1 +set -euf + +cache_dir=/tmp/dict.leo.org/ +file="$cache_dir$*" + +url="http://dict.leo.org/?$*" + +# TODO check sanity of filename + +if test -d "$cache_dir" ; then + test -e "$file" || { curl --silent "$url" | tee "$file" ; } +else + curl --silent "$url" +fi | +sed 's/>\( *.\)/>\n\1/g' | sed -n ' + s/[[:space:]]/ /g + /<!-- # Werbung # -->/,/<\/td>/b + /<!-- ============================================== -->/,/^<\/td>/b + /<!-- # Trailer # -->/,/^ <\/table>/b + /<table id="subnavigation" class="border">/,/<\/table>/b + /<div id="divMoreInfo" class="popup">/,/^ <\/table>/b + + ## show link in rendered version + s/^<a href="\(.*searchLocRelinked.*\)">$/&mehr: \1/ + s/^mehr >>// + + s/<[Bb][Rr] *\/>/,/g + + p + b + :c;# comment + s/-->/\\-\\-\\>/g + s/<!--/\\<\\!\\-\\-/g + s/.*/<!--(&)-->/ + p +' \ +| w3m -cols 1024 -T text/html -dump | sed ' + s/[[:space:]]\+/ /g + s/ ,/,/g + s/^ //;s/ $// + s/[┌┬┐└┴┘├┼┤─]//g + s/ *│ */|/g + s/\[ \]// + s/\[Speichern\] der ausgewa:hlten Wo:rter im Trainer// + s/^||//;s/|| \?$// +' | sed -n ' + /^\[EN-> DE\]/,$b + s/^mehr: /+ / + s/^ENGLISCH||DEUTSCH \?/= Englisch -> Deutsch/ + s/^|\([0-9]\+\) \(Treffer\)|$/= \1 \2/ + s/^\([^|]\+\)||\([^|]\+\)$/- \1|\2/ + + s/^[^=+#-][^|]\+$/## &/ + + p +' | sed -n ' + /^$/b + s/ \([?!]\)/\1/g + s/\([[(]\) /\1/g;s/ \([]\)]\)/\1/g + + s/ ([0-9]\+ of [0-9]\+) \?//;# TODO + + #s/^##.*Grundform.*/\n#&/ + /^## .*Grundform.*/,/^##\( .*\)\?/{ + /##/{/Grundform/!p} + b + } + + /^## Informationen /,$b;# TODO + #/^## Beispiele/,$b;# TODO + #/^## Wendungen/,$b;# TODO + /^+/b;# TODO + #/^=/b;# TODO + + p +' | sed ' + ## + s/|\(.*\)/\n [32m\1[m/g + s/^#.*/\n[33m&[m/ + + s/##.*Treffer $/\n[1;33m#&[m/ +' | less -R +echo + +#### end of file. diff --git a/util/bin/galileo b/util/bin/galileo index 8ca7d834..854f1302 100755 --- a/util/bin/galileo +++ b/util/bin/galileo @@ -1,2 +1,3 @@ #!/bin/sh -./wiki.firstpar http://de.m.wikipedia.org/wiki/::Random | xargs ./naturalvoices.att +export voice=klara +./wiki.firstpar http://de.m.wikipedia.org/wiki/::Random | xargs ./naturalvoices.att diff --git a/util/bin/hrefs b/util/bin/hrefs new file mode 100755 index 00000000..3a1a51de --- /dev/null +++ b/util/bin/hrefs @@ -0,0 +1,20 @@ +#! /bin/sh + +_hrefs() { + sed -n 's/href="\([^"]\+\)"/\n&\n/gp' | + sed -n 's/^href="\([^"]\+\)"$/\1/p'; } + +_add_prefix_to_relative_hrefs() { + sed '/^http:/!s^'"$1"''; } + +_main() { + case $# in + (0) _hrefs;; + (1) _hrefs | _add_prefix_to_relative_hrefs "$1";; + (*) + echo "bad command line: $0 $*" >&2; exit 23;; + esac; } + +set -euf +_main "$@" +#### end of file. diff --git a/util/bin/lgoinstall b/util/bin/lgoinstall new file mode 100755 index 00000000..37ce6e16 --- /dev/null +++ b/util/bin/lgoinstall @@ -0,0 +1,131 @@ +#! /bin/sh +# +# usage: lgoinstall [path [OPTIONS...]] +# +# This script tries to goinstall ${OPTIONS...} local/$(basename $path) +# +# path defaults to $PWD +# +# target=local/$(basename $path) +# ensure there's a symlink local/$target somewhere in $GOROOT or $GOPATH +# goinstall $target +# +# TODO use the same argument order as goinstall +# +set -euf + +#fqtarget="$(readlink -f "$PWD")" +fqtarget="$(cd "${1-$PWD}" && echo "$PWD")" +target="local/$(basename "$fqtarget")" + +# +# resolve PATH [relpath [FS]] # ====> abspath... +# +# Resolve relpath to abspath for each component x separated by FS in PATH +# where x/relpath is an existing file. +# +# relpath defaults to "" +# FS defaults to ":" +# +# Example: +# +# resolve "/bin:/usr/bin" sh # ====> /bin/sh +# +resolve() { + set -- "$1" "${2+/$2}" "${3-:}" "$IFS" + IFS="$3" + for i in $1; do + ! test -x "$i$2" || echo "$i$2" + done + unset i + IFS="$3" +} + +# +# xargstest TEST_ARGS... +# +# Read filenames from stdin and +# write each filename that satisfies test # $TEST_ARGS to stdout. +# +# Each %x in TEST_ARGS gets replaced by the readlink -f of the filename. +# +# Example: +# +# xargstest -d %x <<EOF +# /bin/sh +# /usr +# EOF +# # ====> /usr +# +xargstest() { + while read x; do + fqx="$(readlink -f "$x")" + if sub %x "$x" sub %fqx "$fqx" test "$@"; then + #if test "${@//%x/$fqx}"; then + echo "$x" + fi + done | grep . +} + +sub() { + sub1="$1" + sub2="$2" + shift 2 + set -- "${@//$sub1/$sub2}" + unset sub1 sub2 + "$@" +} + +path="${GOROOT-}${GOPATH+:$GOPATH}" + +# +# if there's a src/$target that points to $fqtarget, then succeed +# +if x="`resolve "$path" src/$target | xargstest "$fqtarget" = %fqx`" +then + echo "good $target: $x -> $fqtarget" >&2 + shift # off $1 = $fqtarget + echo goinstall "$@" "$target" >&2 + exec goinstall "$@" "$target" +fi + +# +# if there's some other src/$target then die +# +if x="`resolve "$path" src/$target | xargstest ! -x %x -o "$fqtarget" != %fqx`" +then + echo bad $target: $x >&2 + echo check your GOROOT and/or GOPATH or eliminate that $target >&2 + exit 23 +fi + +# +# if we've no Go-source in $fqtarget then die to prevent clobbering $GOPATH. +# +if ! ls | grep '\.go$'; then + echo "$1 seems to contain no Go-source... abort." >&2 + exit 23 +fi + +# +# if we can write to some src/local then symlink $PWD and retry +# +if x="`resolve "$path" src/local | xargstest -w %x`" +then + #echo writable src/local: $x + ln -vsnf $fqtarget $x + exec "$0" "$@" +fi + +# +# if we can write to some src then mkdir src/local and retry +# +if x="`resolve "$path" src | xargstest -w %x`" +then + #echo writable src: $x + mkdir "$x/local" + exec "$0" "$@" +fi + +echo "This script failed: good luck, you're on your own!" >&2 +exit 23 diff --git a/util/bin/magic b/util/bin/magic new file mode 100755 index 00000000..a404c0c3 --- /dev/null +++ b/util/bin/magic @@ -0,0 +1,63 @@ +#! /bin/sh +set -euf + +bs="# begin krebs magic <$2>" +es="# end krebs magic <$2>" + +has() { + grep -q "^$bs$" $3 && grep -q "^$es$" $3 +} + +create() { + destroy "$@" + cat>>$3<<EOF +$bs +`cat` +$es +EOF +} + +retrieve() { + sed -n "/^$bs$/,/^$es$/p" $3 | sed '1d;$d' +} + +update() { + ! has "$@" || create "$@" +} + +destroy() { + if has "$@"; then + cache="`cat $3`" + echo "$cache" | sed "/^$bs$/,/^$es$/d" >$3 + fi +} +help() { +cat <<EOF +Usage: $0 FUNCTION DELIMITER_NAME FILE +$0 creates,updates or destroys magic inside a file. +It can be used to reliably add or remove custom lines. +For example add own lines in /etc/rc.local to auto-load +scripts. + +FUNCTION: + create -- creates new magic in file, takes stdin as content in magic + update -- updates already existing magic with text from stdin + destroy -- destroys magic boundary + retrieve -- retrieve the content of magic and writes to stdout + +Not yet implemented is the handling of magic not starting with the +shell comment symbol "#". + +EOF + +} +case $1 in + (create) create "$@" ;; + (retrieve) retrieve "$@" ;; + (update) update "$@" ;; + (destroy) destroy "$@" ;; + (*) + help >&2 + echo 'Error 1: You are made of stupid!' >&2 + exit 23 +esac diff --git a/util/bin/my-global-ipv4-addr b/util/bin/my-global-ipv4-addr index 305d3f80..71608a8a 100755 --- a/util/bin/my-global-ipv4-addr +++ b/util/bin/my-global-ipv4-addr @@ -8,7 +8,8 @@ if test $# = 1; then has() { type "$1" 1>/dev/null 2>/dev/null; } parse() { - sed -rn 's/.*((1?[0-9][0-9]|2[0-5][0-9])\.(1?[0-9][0-9]|2[0-5][0-9])\.(1?[0-9][0-9]|2[0-5][0-9])\.(1?[0-9][0-9]|2[0-5][0-9])).*/\1/p' | grep . + sed -n 's/.*\(\(1\?[0-9][0-9]\|2[0-5][0-9]\)\.\(1\?[0-9][0-9]\|2[0-5][0-9]\)\.\(1\?[0-9][0-9]\|2[0-5][0-9]\)\.\(1\?[0-9][0-9]\|2[0-5][0-9]\)\).*/\1/p' | + grep . } get () { # TODO get random valid user agent diff --git a/util/bin/naturalvoices.att b/util/bin/naturalvoices.att index 9a944d8b..07fb6e17 100755 --- a/util/bin/naturalvoices.att +++ b/util/bin/naturalvoices.att @@ -24,8 +24,8 @@ done (cd "$pwd/../.." && git submodule update --init) { - for arg; do echo "$arg"; done | sed -rn ' - s/^--(.*=.*)/\1/p;t + for arg; do echo "$arg"; done | sed -n ' + s/^--\(.*=.*\)/\1/p;t s/.*/text="${text+$text }&"/p;t ' cat<<EOF diff --git a/util/bin/nextpath b/util/bin/nextpath new file mode 100755 index 00000000..fbffa894 --- /dev/null +++ b/util/bin/nextpath @@ -0,0 +1,12 @@ +#! /bin/sh +# +# nextpath [component...] +# +# echo $PATH with the components stripped +# +set -euf + +pattern="^\\(${1-}$(shift;for i; do echo -n "\\|$i"; done)\\)$" + +echo -n "$(echo -n "$PATH" | tr : '\n' | grep -v "$pattern")" | tr '\n' : +echo diff --git a/util/bin/sshkill b/util/bin/sshkill new file mode 100755 index 00000000..80300483 --- /dev/null +++ b/util/bin/sshkill @@ -0,0 +1,33 @@ +#! /bin/sh +# +# kill ssh client: sshkill user@host:port +# setup bash completion: . sshkill +# +if ! grep -q '^ControlPath /tmp/%u/sshmux/%r@%h:%p$' "$HOME/.ssh/config"; then + echo "Your ~/.ssh/config's ControlPath sucks!" >&2 + (exit 23) +else + if test "${0:0:1}" = -; then + if ! echo "${BASHOPTS-}" | grep -Eq '(^|:)progcomp(:|$)'; then + echo "source sshmux into something other than a progcomp'able bash" >&2 + (exit 23) + else + + # setup bash completion + comp_sshkill() { + if test $COMP_CWORD = 1; then + COMPREPLY=($(cd "/tmp/$LOGNAME/sshmux" && + ls | grep "^${COMP_WORDS[$COMP_CWORD]}.*")) + fi + } + complete -F comp_sshkill sshkill + + fi + else + + # kill ssh client + set -euf + exec pkill -f "^ssh: /tmp/$LOGNAME/sshmux/$1 \[mux\]$" + + fi +fi diff --git a/util/bin/translate.google b/util/bin/translate.google index 1a1be6b6..45da6463 100755 --- a/util/bin/translate.google +++ b/util/bin/translate.google @@ -19,8 +19,8 @@ done (cd "$pwd/../.." && git submodule update --init) { - for arg; do echo "$arg"; done | sed -rn ' - s/^--(.*=.*)/\1/p;t + for arg; do echo "$arg"; done | sed -n ' + s/^--\(.*=.*\)/\1/p;t s/.*/text="${text+$text }&"/p;t ' cat<<EOF diff --git a/util/bin/untouch b/util/bin/untouch new file mode 100755 index 00000000..17fd46b8 --- /dev/null +++ b/util/bin/untouch @@ -0,0 +1,8 @@ +#!/bin/sh +# +#This script toggles the touchpad on a netbook using synclient. + +status=`synclient|awk '/TouchpadOff/{printf$3}'` +status=`expr \( $status + 1 \) \% 2` +synclient TouchpadOff=$status + |