X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=rootsshsync;h=e962f19295b9b1918b70cd8f3ed48f788939fbef;hb=a84e2166aafd58213298ff4b2f674a4b644cc416;hp=592a5aafe8cc14c2c1efdc12e4215497233eefc0;hpb=7828c7fd662aca1327c45854614237ca9a942a00;p=distro-setup diff --git a/rootsshsync b/rootsshsync index 592a5aa..e962f19 100755 --- a/rootsshsync +++ b/rootsshsync @@ -16,10 +16,17 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -if sudo test -e /q/root/.ssh; then - sudo /a/exe/lnf /q/root/.ssh /root +[[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@" + +if test -e /q/root/.ssh; then + dest=/q/root/.ssh + /a/exe/lnf $dest /root else - sudo mkdir /root/.ssh + dest=/root/.ssh + mkdir -p /root/.ssh + chmod 700 /root/.ssh fi -sudo cp -rL $(eval echo ~${SUDO_USER:-$USER})/.ssh/* /root/.ssh -sudo chown -R root:root /root/.ssh +# -t times, so it won't rewrite the file every time, +# -L resolve links +rsync -rtL $(eval echo ~${SUDO_USER:-$USER})/.ssh $dest +chown -R root:root /root/.ssh