X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=rootsshsync;h=e962f19295b9b1918b70cd8f3ed48f788939fbef;hb=a84e2166aafd58213298ff4b2f674a4b644cc416;hp=baf42967acf4e465b0752a46f454d2422550afbc;hpb=98bcf504ce2a56eeb862a59477cfb897a2ef613c;p=distro-setup diff --git a/rootsshsync b/rootsshsync index baf4296..e962f19 100755 --- a/rootsshsync +++ b/rootsshsync @@ -16,11 +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 -p /root/.ssh - sudo chmod 700 /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