Thread: [Assorted-commits] SF.net SVN: assorted:[967] shell-tools/trunk/src/bash-commons/common.bash
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-09-18 02:47:22
|
Revision: 967 http://assorted.svn.sourceforge.net/assorted/?rev=967&view=rev Author: yangzhang Date: 2008-09-18 02:47:32 +0000 (Thu, 18 Sep 2008) Log Message: ----------- distinguish empty files/dirs more clearly Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2008-09-17 03:00:55 UTC (rev 966) +++ shell-tools/trunk/src/bash-commons/common.bash 2008-09-18 02:47:32 UTC (rev 967) @@ -374,16 +374,12 @@ echo "$dir" } -is-empty() { +is-empty-file() { [[ -f "$1" && "$( stat -c%s "$1" )" == 0 ]] } -rm-empty() { - for i in "$@" ; do - if is-empty "$i" - then rm "$i" - fi - done +rm-empty-files() { + find "${1:-}" -type f -empty -print0 | xargs -0 rm } run-if-def() { @@ -467,6 +463,10 @@ xargs -0 -I_ ln -s "$( realpath "$src" )/_" "$dst/_" } +rm-empty-dirs() { + find "${1:-.}" -type d -empty -print0 | xargs -0r rmdir -p +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-10-22 20:02:16
|
Revision: 1025 http://assorted.svn.sourceforge.net/assorted/?rev=1025&view=rev Author: yangzhang Date: 2008-10-22 20:02:01 +0000 (Wed, 22 Oct 2008) Log Message: ----------- fixed cabal-install Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2008-10-22 20:00:37 UTC (rev 1024) +++ shell-tools/trunk/src/bash-commons/common.bash 2008-10-22 20:02:01 UTC (rev 1025) @@ -469,8 +469,8 @@ cabal-install() { for i in "${@:-}" ; do + pushd "$i" && local pkg="$(basename "$(pwd)" )" && - pushd "$i" && runhaskell Setup.*hs clean && runhaskell Setup.*hs configure --user --prefix="$HOME/.local/pkg/ghc-${pkg%-*}" && runhaskell Setup.*hs build && This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-12-19 23:46:29
|
Revision: 1110 http://assorted.svn.sourceforge.net/assorted/?rev=1110&view=rev Author: yangzhang Date: 2008-12-19 23:46:26 +0000 (Fri, 19 Dec 2008) Log Message: ----------- added stripext, cabal-install-all, is-function Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2008-12-19 23:45:53 UTC (rev 1109) +++ shell-tools/trunk/src/bash-commons/common.bash 2008-12-19 23:46:26 UTC (rev 1110) @@ -224,6 +224,11 @@ quiet popd } +is-function() { + local name="$1" + type "$name" 2> /dev/null | head -1 | fgrep -q "$name is a function" +} + prepend() { while read line ; do echo "$@$line" @@ -486,19 +491,28 @@ sudo -u pkg stow -t "$GLOBAL_PREFIX" "$@" !(armed) ) } -cabal-install() { +cabal-install-all() { for i in "${@:-}" ; do pushd "$i" && - local pkg="$(basename "$(pwd)" )" && - runhaskell Setup.*hs clean && - runhaskell Setup.*hs configure --user --prefix="$HOME/.local/pkg/ghc-${pkg%-*}" && - runhaskell Setup.*hs build && - runhaskell Setup.*hs install --user && + cabal-install && popd || break done } +cabal-install() { + local pkg="$(basename "$(pwd)" )" && + runhaskell Setup.*hs clean && + runhaskell Setup.*hs configure --user --prefix="$HOME/.local/pkg/ghc-${pkg%-*}" "$@" && + runhaskell Setup.*hs build && + runhaskell Setup.*hs install --user +} + +stripext() { + local path="$1" + mv "$path" "${path%.*}" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-01-09 06:27:38
|
Revision: 1123 http://assorted.svn.sourceforge.net/assorted/?rev=1123&view=rev Author: yangzhang Date: 2009-01-09 06:27:26 +0000 (Fri, 09 Jan 2009) Log Message: ----------- added mkcdbs Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-01-08 22:39:12 UTC (rev 1122) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-01-09 06:27:26 UTC (rev 1123) @@ -513,6 +513,11 @@ mv "$path" "${path%.*}" } +mkcdbs() { + echo -e 'b\n\n' | dh_make --createorig + rm debian/{dirs,docs,README*,*.ex,*.EX} +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-05-07 05:36:38
|
Revision: 1378 http://assorted.svn.sourceforge.net/assorted/?rev=1378&view=rev Author: yangzhang Date: 2009-05-07 05:36:34 +0000 (Thu, 07 May 2009) Log Message: ----------- added flac2mp3 Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-05-07 05:36:15 UTC (rev 1377) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-05-07 05:36:34 UTC (rev 1378) @@ -526,6 +526,12 @@ sed -i 's/Standards-Version: .*/Standards-Version: 3.8.0/' debian/control } +flac2mp3() { + for i in "$@" + do flac -cd "$i" | lame - "${i%flac}mp3" + done +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-05-25 18:33:03
|
Revision: 1434 http://assorted.svn.sourceforge.net/assorted/?rev=1434&view=rev Author: yangzhang Date: 2009-05-25 18:32:50 +0000 (Mon, 25 May 2009) Log Message: ----------- tweaked cpbkup; refactored symlink-tree into cp-tree-skel, op-tree-files, cp-tree, symlink-tree; added printable-slides Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-05-25 18:31:33 UTC (rev 1433) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-05-25 18:32:50 UTC (rev 1434) @@ -106,7 +106,9 @@ cpbkup() { eval "$get_all_opts" for file in "$@" ; do - cp $opts "$file" "$file.backup" + dst="$( echo "$file" | sed 's/\/\+$//' ).backup" + echo cp $opts "$file" "$dst" + cp $opts "$file" "$dst" done } @@ -467,14 +469,35 @@ done } -symlink-tree() { +# Reproduce a dir tree (just the dirs). +cp-tree-skel() { local src="$1" dst="$2" find "$src" -type d -printf '%P\0' | xargs -0 -I_ mkdir -p "$dst/_" +} + +# op-tree <src> <dst> <op> [<op args...>] +# Performs operation on each file in the tree. +op-tree-files() { + local src="$1" dst="$2" find "$src" -not -type d -printf '%P\0' | - xargs -0 -I_ ln -s "$( realpath "$src" )/_" "$dst/_" + xargs -0 -I_ "$@" "$( realpath "$src" )/_" "$dst/_" } +# Make a deep copy of a directory. +cp-tree() { + local src="$1" dst="$2" + cp-tree-skel "$src" "$dst" + op-tree-files "$src" "$dst" cp +} + +# Make a deep symlink copy of a directory. +symlink-tree() { + local src="$1" dst="$2" + cp-tree-skel "$src" "$dst" + op-tree-files "$src" "$dst" ln -s +} + rm-empty-dirs() { find "${1:-.}" -type d -empty -print0 | xargs -0r rmdir -p } @@ -526,6 +549,10 @@ sed -i 's/Standards-Version: .*/Standards-Version: 3.8.0/' debian/control } +printable-slides() { + pdfnup --paper letterpaper --nup 2x3 --frame true --scale .9 "$@" +} + flac2mp3() { for i in "$@" do flac -cd "$i" | lame - "${i%flac}mp3" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-08-22 00:35:07
|
Revision: 1468 http://assorted.svn.sourceforge.net/assorted/?rev=1468&view=rev Author: yangzhang Date: 2009-08-22 00:34:59 +0000 (Sat, 22 Aug 2009) Log Message: ----------- realpath -> readlink -f; added maybe-add-ssh, install-and-setup-exes, setup-exes Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-08-13 00:53:35 UTC (rev 1467) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-08-22 00:34:59 UTC (rev 1468) @@ -243,7 +243,7 @@ # TODO is this necessary in light of advanced var expansions? is_declared() { - declare -p "$1" &> /dev/null + declare -p "$1" >& /dev/null } # checks if a service is running; if not, start it! @@ -382,7 +382,7 @@ local dir=. while true ; do if "$@" "$dir" ; then break ; fi - if [[ "$( realpath "$dir" )" == / ]] ; then return 1 ; fi + if [[ "$( readlink -f "$dir" )" == / ]] ; then return 1 ; fi dir="$dir/.." done echo "$dir" @@ -481,7 +481,7 @@ op-tree-files() { local src="$1" dst="$2" find "$src" -not -type d -printf '%P\0' | - xargs -0 -I_ "$@" "$( realpath "$src" )/_" "$dst/_" + xargs -0 -I_ "$@" "$( readlink -f "$src" )/_" "$dst/_" } # Make a deep copy of a directory. @@ -559,6 +559,39 @@ done } +# Add keys if not already added. +maybe-ssh-add() { + if ( ssh-add -l && ! ssh-add -l | fgrep $1 ) >& /dev/null + then ssh-add ~/.ssh/$1 + fi +} + +# Useful for installing packages that come in a tree that runs out-of-the-box, +# like Firefox, Thunderbird, Eclipse, Netbeans, JProfiler. First argument is +# the package directory to install (it's installed using mv), and the second +# argument is the place to install to (defaults to ~/.local/pkg/<package +# directory basename>). +install-and-setup-exes() { + local dir="$1" base="$(basename "$1")" + local dst="${2:-~/.local/pkg/$base}/" + mkdir -p "$dst/bin/" + mv "$dir" "$dst" + setup-exes "$dst/$base/bin/" "$dst/bin/" +} + +# Create shell script wrappers in the dst directory for any executables in the +# src directory. +setup-exes() { + local src="$1" dst="$2" + for i in "$src/"* ; do + if [[ -x "$i" ]] ; then + echo -e "#!/usr/bin/env bash\nexec $(quote "$(readlink -f "$i")") \"\$@\"" \ + > "$dst/$(basename "$i")" + chmod +x "$dst/$(basename "$i")" + fi + done +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-12-31 00:57:10
|
Revision: 1536 http://assorted.svn.sourceforge.net/assorted/?rev=1536&view=rev Author: yangzhang Date: 2009-12-31 00:57:00 +0000 (Thu, 31 Dec 2009) Log Message: ----------- added pdfsplit, capitalize; renamed colors Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-12-30 18:31:32 UTC (rev 1535) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-12-31 00:57:00 UTC (rev 1536) @@ -23,15 +23,30 @@ # \e = \E = \033 # 0;34m = 34m # 30's are foregrounds, 40's are backgrounds +# Escape sequences begin with \e[ and end with m. +# Each is a sequence of commands, separated by ;. +# 0 and 1 set the lightness, but 0 also resets everything (fg/bg). +# 3x sets the foreground. +# 4x sets the background. -dark_blue="\e[0;34m"; bright_blue="\e[1;34m" -dark_green="\e[0;32m"; bright_green="\e[1;32m" -dark_cyan="\e[0;36m"; bright_cyan="\e[1;36m" -dark_red="\e[0;31m"; bright_red="\e[1;31m" -dark_magenta="\e[0;35m"; bright_magenta="\e[1;35m" -brown="\e[0;33m"; yellow="\e[1;33m" -black="\e[0;30m"; dark_gray="\e[1;30m"; -bold_white="\e[1;37m" white="\e[0;37m" +fg_dark_blue="\e[0;34m"; fg_bright_blue="\e[1;34m" +fg_dark_green="\e[0;32m"; fg_bright_green="\e[1;32m" +fg_dark_cyan="\e[0;36m"; fg_bright_cyan="\e[1;36m" +fg_dark_red="\e[0;31m"; fg_bright_red="\e[1;31m" +fg_dark_magenta="\e[0;35m"; fg_bright_magenta="\e[1;35m" +fg_brown="\e[0;33m"; fg_yellow="\e[1;33m" +fg_black="\e[0;30m"; fg_dark_gray="\e[1;30m" +fg_white="\e[0;37m"; fg_bold_white="\e[1;37m" + +bg_dark_blue="\e[0;44m"; bg_bright_blue="\e[1;44m" +bg_dark_green="\e[0;42m"; bg_bright_green="\e[1;42m" +bg_dark_cyan="\e[0;46m"; bg_bright_cyan="\e[1;46m" +bg_dark_red="\e[0;41m"; bg_bright_red="\e[1;41m" +bg_dark_magenta="\e[0;45m"; bg_bright_magenta="\e[1;45m" +bg_brown="\e[0;43m"; bg_yellow="\e[1;43m" +bg_black="\e[0;40m"; bg_dark_gray="\e[1;40m" +bg_white="\e[0;47m"; bg_bold_white="\e[1;47m" + normal_color="\e[0m" # Don't use 'error' to print the message because error might be a special @@ -559,6 +574,19 @@ done } +pdfsplit() { + local f="$@" + for i in $( seq $( pdfpages "$f" ) ) + do pdftk "$f" cat $i output "${f%.pdf}-$i.pdf" + done +} + +# capitalize the first letter of the given arg +capitalize() { + echo -n "${1:0:1}" | tr '[:lower:]' '[:upper:]' + echo "${1:1}" +} + # Add keys if not already added. maybe-ssh-add() { if ( ssh-add -l && ! ssh-add -l | fgrep $1 ) >& /dev/null This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-12-31 01:04:32
|
Revision: 1540 http://assorted.svn.sourceforge.net/assorted/?rev=1540&view=rev Author: yangzhang Date: 2009-12-31 01:04:22 +0000 (Thu, 31 Dec 2009) Log Message: ----------- added python-version; fixed refresh-opt to use `pkg` user only if avail; enabled extglob Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-12-31 01:02:05 UTC (rev 1539) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-12-31 01:04:22 UTC (rev 1540) @@ -49,6 +49,8 @@ normal_color="\e[0m" +shopt -s extglob + # Don't use 'error' to print the message because error might be a special # logging facility. Our intent is to actual produce some plain output for the # user here. @@ -455,12 +457,16 @@ done } +python-version() { + python -c 'import sys; print ".".join(map(str,sys.version_info[0:2]))' +} + # Install a python package to the specified directory. Takes care of creating # the dir and setting the PYTHONPATH appropriately for the setup process. pyinstall() { - local prefix="$1" pkgdir="$1/lib/python2.5/site-packages" + local prefix="$1" pkgdir="$1/lib/python$(python-version)/site-packages" mkdir -p $pkgdir - PYTHONPATH="$pkgdir:$PYTHONPATH" ./setup.py install --prefix "$prefix" + PYTHONPATH="$pkgdir:$PYTHONPATH" python setup.py install --prefix "$prefix" } # Check that a file exists and has private permissions. @@ -524,9 +530,17 @@ } refresh-opt() { - ( sudo -u pkg mkdir -p "$GLOBAL_PREFIX" && + local pkg_user= + if [[ "$PKG_USER" ]] ; then + pkg_user="$PKG_USER" + elif sudo -u pkg echo -n ; then + pkg_user=pkg + else + pkg_user=root + fi + ( sudo -u "$pkg_user" mkdir -p "$GLOBAL_PREFIX" && cd "$GLOBAL_PKG" && - sudo -u pkg stow -t "$GLOBAL_PREFIX" !(armed) ) + sudo -u "$pkg_user" stow -t "$GLOBAL_PREFIX" !(armed) ) } cabal-install-all() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-01-30 18:10:55
|
Revision: 1557 http://assorted.svn.sourceforge.net/assorted/?rev=1557&view=rev Author: yangzhang Date: 2010-01-30 18:10:45 +0000 (Sat, 30 Jan 2010) Log Message: ----------- tweak so bootstrap.bash doesn't throw up Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-01-26 19:24:52 UTC (rev 1556) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-01-30 18:10:45 UTC (rev 1557) @@ -531,7 +531,7 @@ refresh-opt() { local pkg_user= - if [[ "$PKG_USER" ]] ; then + if [[ "${PKG_USER:-}" ]] ; then pkg_user="$PKG_USER" elif sudo -u pkg echo -n ; then pkg_user=pkg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-04-01 18:16:00
|
Revision: 1593 http://assorted.svn.sourceforge.net/assorted/?rev=1593&view=rev Author: yangzhang Date: 2010-04-01 18:15:53 +0000 (Thu, 01 Apr 2010) Log Message: ----------- don't show error if pkg user doesn't exist Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-04-01 18:13:54 UTC (rev 1592) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-04-01 18:15:53 UTC (rev 1593) @@ -533,7 +533,7 @@ local pkg_user= if [[ "${PKG_USER:-}" ]] ; then pkg_user="$PKG_USER" - elif sudo -u pkg echo -n ; then + elif sudo -u pkg echo -n >& /dev/null ; then pkg_user=pkg else pkg_user=root This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-04 02:16:06
|
Revision: 1676 http://assorted.svn.sourceforge.net/assorted/?rev=1676&view=rev Author: yangzhang Date: 2010-06-04 02:15:59 +0000 (Fri, 04 Jun 2010) Log Message: ----------- in-place Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-06-03 19:28:52 UTC (rev 1675) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-06-04 02:15:59 UTC (rev 1676) @@ -634,6 +634,13 @@ done } +# Edit files in-place. +in-place() { + local file="$1" + shift + "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-07-30 01:14:32
|
Revision: 1685 http://assorted.svn.sourceforge.net/assorted/?rev=1685&view=rev Author: yangzhang Date: 2010-07-30 01:14:25 +0000 (Fri, 30 Jul 2010) Log Message: ----------- continuous-make Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-07-16 01:36:50 UTC (rev 1684) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-07-30 01:14:25 UTC (rev 1685) @@ -641,6 +641,13 @@ "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" } +continuous-make() { + while true ; do + make -s "$@" + sleep 1 + done +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-08-27 17:04:36
|
Revision: 1689 http://assorted.svn.sourceforge.net/assorted/?rev=1689&view=rev Author: yangzhang Date: 2010-08-27 17:04:30 +0000 (Fri, 27 Aug 2010) Log Message: ----------- Added buffer-to Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-08-13 03:26:19 UTC (rev 1688) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-08-27 17:04:30 UTC (rev 1689) @@ -648,6 +648,12 @@ done } +# Don't prematurely clobber files. E.g. `cat a b | buffer-to a` +buffer-to() { + local buf="$(cat)" out="$1" + echo "$buf" > "$out" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-08-31 03:53:09
|
Revision: 1692 http://assorted.svn.sourceforge.net/assorted/?rev=1692&view=rev Author: yangzhang Date: 2010-08-31 03:53:03 +0000 (Tue, 31 Aug 2010) Log Message: ----------- Added clobber-freespace Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-08-31 03:52:38 UTC (rev 1691) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-08-31 03:53:03 UTC (rev 1692) @@ -654,6 +654,13 @@ echo "$buf" > "$out" } +# Quickly fill up free space with randomness (insecure) by writing to specified +# output file +clobber-freespace() { + dd if=/dev/random bs=1k count=1 | + openssl enc -kfile /dev/fd/0 -in /dev/zero -aes-128-cbc > "$@" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-09-01 06:03:22
|
Revision: 1693 http://assorted.svn.sourceforge.net/assorted/?rev=1693&view=rev Author: yangzhang Date: 2010-09-01 06:03:16 +0000 (Wed, 01 Sep 2010) Log Message: ----------- buffer-to deprecated; use sponge Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-08-31 03:53:03 UTC (rev 1692) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-09-01 06:03:16 UTC (rev 1693) @@ -648,12 +648,6 @@ done } -# Don't prematurely clobber files. E.g. `cat a b | buffer-to a` -buffer-to() { - local buf="$(cat)" out="$1" - echo "$buf" > "$out" -} - # Quickly fill up free space with randomness (insecure) by writing to specified # output file clobber-freespace() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-01-25 00:19:46
|
Revision: 1743 http://assorted.svn.sourceforge.net/assorted/?rev=1743&view=rev Author: yangzhang Date: 2011-01-25 00:19:40 +0000 (Tue, 25 Jan 2011) Log Message: ----------- Add pg-grant-tables Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-01-08 02:41:57 UTC (rev 1742) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-01-25 00:19:40 UTC (rev 1743) @@ -655,6 +655,18 @@ openssl enc -kfile /dev/fd/0 -in /dev/zero -aes-128-cbc > "$@" } +# Given a user, grant permissions (default: all) on all tables in some schema +# (default: public) to that user. +pg-grant-tables() { + local schema=${schema:-public} perms=${perms:-all} user=$1 + psql -A -t -c " + select 'grant $perms on '||schemaname||'.'||tablename||' to $user;' + from pg_tables + where schemaname = '$schema' + order by schemaname, tablename;" | + psql +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-02-18 22:35:51
|
Revision: 1746 http://assorted.svn.sourceforge.net/assorted/?rev=1746&view=rev Author: yangzhang Date: 2011-02-18 22:35:45 +0000 (Fri, 18 Feb 2011) Log Message: ----------- Add scp-resume & /proc-based utils (from gnprice) /proc utils include phantom-progress, sample-context-switches, oom-scores Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-02-18 22:11:22 UTC (rev 1745) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-02-18 22:35:45 UTC (rev 1746) @@ -667,6 +667,43 @@ psql } +# Resume SCP; from <http://joen.dk/wordpress/?p=34> +scp-resume() { + rsync --partial --progress "$@" +} + +# Show a running process's progress through a file. (Or, "when it's too late +# for pv....") +# <http://blog.ksplice.com/2011/01/solving-problems-with-proc/> +phantom-progress() { + local fd=/proc/$1/fd/$2 + local fdinfo=/proc/$1/fdinfo/$2 + local name=$(readlink $fd) + local size=$(wc -c $fd | awk '{print $1}') + local dialog=${dialog:-gdialog} # can also use 'dialog' + while [ -e $fd ]; do + local progress=$(cat $fdinfo | grep ^pos | awk '{print $2}') + echo $((100*$progress / $size)) + sleep 1 + done | $dialog --gauge "Progress reading $name" 7 100 +} + +# Sample info on context switches. Mostly voluntary means IO-bound. +sample-context-switches() { + watch -d -n 1 "cat /proc/$PID/status | fgrep ctxt_switches" +} + +# Report OOM scores. +oom-scores() { + for procdir in $(find /proc -maxdepth 1 -regex '/proc/[0-9]+'); do + printf "%10d %6d %s\n" \ + "$(cat $procdir/oom_score)" \ + "$(basename $procdir)" \ + "$(cat $procdir/cmdline | tr '\0' ' ' | head -c 100)" + done 2>/dev/null | sort -nr | head -n 20 +} + + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-03-18 06:26:00
|
Revision: 1766 http://assorted.svn.sourceforge.net/assorted/?rev=1766&view=rev Author: yangzhang Date: 2011-03-18 06:25:54 +0000 (Fri, 18 Mar 2011) Log Message: ----------- Tweak pg-grant-tables to grant schema perms Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-03-15 01:23:14 UTC (rev 1765) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-03-18 06:25:54 UTC (rev 1766) @@ -660,6 +660,7 @@ pg-grant-tables() { local schema=${schema:-public} perms=${perms:-all} user=$1 psql -A -t -c " + grant $perms on schema $schema to $user; select 'grant $perms on '||schemaname||'.'||tablename||' to $user;' from pg_tables where schemaname = '$schema' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-04-07 01:56:15
|
Revision: 1772 http://assorted.svn.sourceforge.net/assorted/?rev=1772&view=rev Author: yangzhang Date: 2011-04-07 01:56:09 +0000 (Thu, 07 Apr 2011) Log Message: ----------- Add pg-space Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-04-03 19:48:49 UTC (rev 1771) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-04-07 01:56:09 UTC (rev 1772) @@ -704,6 +704,50 @@ done 2>/dev/null | sort -nr | head -n 20 } +pg-space() { + local schema=${schema:-${1:-}} + case ${schema:-} in + '*' ) local query='select * from tables' ;; + '' ) local query='select * from schemas' ;; + * ) local query="select * from tables where _schema = '$schema'" ;; + esac + psql -c " + with + total as ( + select sum(pg_relation_size(oid)) from pg_class where relkind = 'r' + ), + basic as ( + select + n.nspname as _schema, + relname as _table, + pg_relation_size(r.oid) as bytes, + (100*pg_relation_size(r.oid)/(select * from total))::numeric(4,1) as pct + from pg_class r inner join pg_namespace n on (n.oid = relnamespace) + where relkind = 'r' + ), + tables as ( + select + _schema, + _table, + bytes, + lpad(pg_size_pretty(bytes), 9) as size, + pct + from basic + order by bytes desc + ), + schemas as ( + select + _schema, + sum(bytes) as bytes, + lpad(pg_size_pretty(sum(bytes)::int), 9) as size, + sum(pct) as pct + from basic + group by _schema + order by bytes desc + ) + $query; + " +} #if ! is_declared indent ; then # noindent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-04-08 01:10:19
|
Revision: 1773 http://assorted.svn.sourceforge.net/assorted/?rev=1773&view=rev Author: yangzhang Date: 2011-04-08 01:10:13 +0000 (Fri, 08 Apr 2011) Log Message: ----------- Add pg-stat Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-04-07 01:56:09 UTC (rev 1772) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-04-08 01:10:13 UTC (rev 1773) @@ -749,6 +749,23 @@ " } +pg-stat() { + psql -c " + select + usename as usr, + waiting, + current_query, + array_to_string(array_agg(distinct nspname), ', ') as schemas, + array_to_string(array_agg(distinct relname), ', ') as tables + from + pg_stat_activity + inner join pg_locks on (pid=procpid) + inner join pg_class on (relfilenode=relation) + inner join pg_namespace n on (n.oid=relnamespace) + where current_query not like '%pg_stat_activity%' + group by usename, procpid, current_query, waiting;" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-04-08 02:52:41
|
Revision: 1774 http://assorted.svn.sourceforge.net/assorted/?rev=1774&view=rev Author: yangzhang Date: 2011-04-08 02:52:35 +0000 (Fri, 08 Apr 2011) Log Message: ----------- Clarify group-by ordering in pg-stat Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-04-08 01:10:13 UTC (rev 1773) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-04-08 02:52:35 UTC (rev 1774) @@ -763,7 +763,7 @@ inner join pg_class on (relfilenode=relation) inner join pg_namespace n on (n.oid=relnamespace) where current_query not like '%pg_stat_activity%' - group by usename, procpid, current_query, waiting;" + group by procpid, usename, waiting, current_query;" } #if ! is_declared indent ; then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-04-08 18:44:15
|
Revision: 1775 http://assorted.svn.sourceforge.net/assorted/?rev=1775&view=rev Author: yangzhang Date: 2011-04-08 18:44:09 +0000 (Fri, 08 Apr 2011) Log Message: ----------- Add key() to common.bash Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-04-08 02:52:35 UTC (rev 1774) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-04-08 18:44:09 UTC (rev 1775) @@ -766,6 +766,11 @@ group by procpid, usename, waiting, current_query;" } +key() { + local minutes=${1:-1} + eval "$(keychain --eval --timeout $minutes id_rsa)" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-04-24 19:26:41
|
Revision: 1783 http://assorted.svn.sourceforge.net/assorted/?rev=1783&view=rev Author: yangzhang Date: 2011-04-24 19:26:35 +0000 (Sun, 24 Apr 2011) Log Message: ----------- Fix pg-space to use pg_total_relation_size Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-04-21 01:48:07 UTC (rev 1782) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-04-24 19:26:35 UTC (rev 1783) @@ -705,23 +705,24 @@ } pg-space() { - local schema=${schema:-${1:-}} + local schema=${schema:-${1:-}} flags= case ${schema:-} in + total ) local query='select sum(bytes) from schemas' flags=-At ;; '*' ) local query='select * from tables' ;; '' ) local query='select * from schemas' ;; * ) local query="select * from tables where _schema = '$schema'" ;; esac - psql -c " + psql $flags -c " with total as ( - select sum(pg_relation_size(oid)) from pg_class where relkind = 'r' + select sum(pg_total_relation_size(oid)) from pg_class where relkind = 'r' ), - basic as ( + base as ( select n.nspname as _schema, relname as _table, - pg_relation_size(r.oid) as bytes, - (100*pg_relation_size(r.oid)/(select * from total))::numeric(4,1) as pct + pg_total_relation_size(r.oid) as bytes, + (100*pg_total_relation_size(r.oid)/(select * from total))::numeric(4,1) as pct from pg_class r inner join pg_namespace n on (n.oid = relnamespace) where relkind = 'r' ), @@ -732,7 +733,7 @@ bytes, lpad(pg_size_pretty(bytes), 9) as size, pct - from basic + from base order by bytes desc ), schemas as ( @@ -741,7 +742,7 @@ sum(bytes) as bytes, lpad(pg_size_pretty(sum(bytes)::int), 9) as size, sum(pct) as pct - from basic + from base group by _schema order by bytes desc ) @@ -749,6 +750,12 @@ " } +pg-dbspace() { + for db in $(psql -Atc 'select datname from pg_database') + do printf '%12d %s\n' "$(PGDATABASE=$db pg-space total)" "$db" + done | sort -rn +} + pg-stat() { psql -c " select This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2011-05-06 06:53:57
|
Revision: 1788 http://assorted.svn.sourceforge.net/assorted/?rev=1788&view=rev Author: yangzhang Date: 2011-05-06 06:53:51 +0000 (Fri, 06 May 2011) Log Message: ----------- Add wait-idle Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2011-05-06 01:51:20 UTC (rev 1787) +++ shell-tools/trunk/src/bash-commons/common.bash 2011-05-06 06:53:51 UTC (rev 1788) @@ -778,6 +778,13 @@ eval "$(keychain --eval --timeout $minutes id_rsa)" } +wait-idle() { + while (( $( top -b -n 2 | grep ^Cpu | tail -1 | + sed 's/.* \([[:digit:]]*\)\.[[:digit:]]*%id.*/\1/g' ) < 50 )) + do sleep ${sleep:-60} + done +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |