diff options
author | Alan Pearce | 2013-04-28 20:54:18 +0100 |
---|---|---|
committer | Alan Pearce | 2013-04-28 20:54:18 +0100 |
commit | e7657d6ba54ad5714657cff9be86ec416d342a4c (patch) | |
tree | 50a2fada14e8d5f76ef890c4b860fbdd4faf812f /zsh/functions/runit/renamesv | |
parent | 6bec14c2d18c915a3510aba36a37e78a8b83170f (diff) | |
download | dotfiles-e7657d6ba54ad5714657cff9be86ec416d342a4c.tar.lz dotfiles-e7657d6ba54ad5714657cff9be86ec416d342a4c.tar.zst dotfiles-e7657d6ba54ad5714657cff9be86ec416d342a4c.zip |
Migrate repository from mercurial without history
Diffstat (limited to 'zsh/functions/runit/renamesv')
-rw-r--r-- | zsh/functions/runit/renamesv | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/zsh/functions/runit/renamesv b/zsh/functions/runit/renamesv new file mode 100644 index 0000000..dba1098 --- /dev/null +++ b/zsh/functions/runit/renamesv @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +local svdir=${SVDIR:-/service} +if [[ -z $1 || -z $2 ]]; then + echo "Usage: $0 source target" + return 64 +fi + +if [[ ! -h $svdir/$1 ]]; then + echo $svdir/$1 does not exist + return 2 +fi + +if [[ -e $svdir/$2 ]]; then + echo $svdir/$2 already exists + return 3 +fi + +local servicedir=`getservicedir` + +if [[ ! ( -w $svdir && -w $servicedir ) ]]; then + echo $svdir or $servicedir is not writeable +fi + +# The service doesn't have to be stopped as removing the link will do that +# However, running the same service twice isn't a great idea, so wait here +sv stop $1 + +rm -f $svdir/$1 || return + +mv $servicedir/{$1,$2} || return + +ln -s {$servicedir,$svdir}/$2 || return + +sv start $2 + +return |