[Assorted-commits] SF.net SVN: assorted:[1468] shell-tools/trunk/src/bash-commons/common.bash
Brought to you by:
yangzhang
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. |