Files
q-tools/rc
Ville Rantanen 4c24e14447 silent update
2015-11-24 12:45:45 +02:00

33 lines
881 B
Plaintext
Executable File

# source me to enable tools
TOOLSPATH=$( readlink -f $( dirname "$BASH_SOURCE" ) )
PATH=$PATH:"$TOOLSPATH"/bin
# remove duplicate path
PATH=$( echo $PATH | awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s:",$i); }}' | sed 's,:\+$,,g' )
export PATH
. "$TOOLSPATH"/qcd_function
function _self_update() {
touch "$TOOLSPATH"/.lastupdate
pushd "$TOOLSPATH" > /dev/null
hg pull -u > /dev/null 2>&1
popd > /dev/null
}
[[ "$1" = "-u" ]] && _self_update
# Update self weekly
[[ -t 0 ]] || return
[[ -t 1 ]] || return
[[ -t 2 ]] || return
[[ -f "$TOOLSPATH"/.lastupdate ]] || touch -t 0101010101 "$TOOLSPATH"/.lastupdate 2> /dev/null
[[ -w "$TOOLSPATH"/.lastupdate ]] || return
TOOLS_LASTUPDATE=$(( $( date +%s ) - $( stat -c %Y "$TOOLSPATH"/.lastupdate ) ))
[[ "$TOOLS_LASTUPDATE" -gt 604800 ]] && _self_update
unset TOOLS_LASTUPDATE
unset -f _self_update