tidy up for public access, insert converter for repo change

This commit is contained in:
Ville Rantanen
2016-03-08 15:32:18 +02:00
parent f5d234c3ad
commit 5ead3ea01c
3 changed files with 52 additions and 11 deletions

35
rc
View File

@@ -13,21 +13,50 @@ export PATH
function _self_update() {
touch "$TOOLSPATH"/.lastupdate
pushd "$TOOLSPATH" > /dev/null
timeout 5 hg pull -u > /dev/null 2>&1 &
[[ "$1" = "-u" ]] && {
hg pull -u
} || {
timeout 5 hg pull -u > /dev/null 2>&1
}
popd > /dev/null
}
[[ "$1" = "-u" ]] && _self_update
function _change_hg_repo() {
[[ -w "$TOOLSPATH"/.hg ]] || return
[[ -w "$TOOLSPATH"/.hg/hgrc ]] || return
grep -q moonq.kapsi.fi/repo/ "$TOOLSPATH"/.hg/hgrc && {
echo -e "Converting read only repository to bitbucket\n"
sed 's,\s*default\s*=.*moonq.kapsi.fi.*,default = https://bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc \
| diff "$TOOLSPATH"/.hg/hgrc -
sed -i 's,\s*default\s*=.*moonq.kapsi.fi.*,default = https://bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc
}
grep -q moonq.kapsi.fi/repoz/ "$TOOLSPATH"/.hg/hgrc && {
echo -e "Converting writable repository to bitbucket\n"
sed 's,\s*default\s*=.*moonq.kapsi.fi.*,default = ssh://hg@bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc \
| diff "$TOOLSPATH"/.hg/hgrc -
echo
sed -i 's,\s*default\s*=.*moonq.kapsi.fi.*,default = ssh://hg@bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc
}
}
# Update self weekly
[[ "$1" = "-u" ]] && _self_update -u
# Update self weekly,
# if folder writable, if repository, if an interactive terminal, if not updated the last week
[[ -w "$TOOLSPATH" ]] || return
[[ -w "$TOOLSPATH"/.hg ]] || return
[[ -t 0 ]] || return
[[ -t 1 ]] || return
[[ -t 2 ]] || return
[[ -f "$TOOLSPATH"/.lastupdate ]] || touch -t 0101010101 "$TOOLSPATH"/.lastupdate 2> /dev/null
[[ -w "$TOOLSPATH"/.lastupdate ]] || return
_change_hg_repo
unset -f _change_hg_repo
TOOLS_LASTUPDATE=$(( $( date +%s ) - $( stat -c %Y "$TOOLSPATH"/.lastupdate ) ))
[[ "$TOOLS_LASTUPDATE" -gt 604800 ]] && _self_update
unset TOOLS_LASTUPDATE
unset -f _self_update