X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=rootsshsync;h=97d2d2f779919413058d70b1ec8282a2a468682e;hb=8826440696abdfbfd6c7f5a40c95163bd489a1b1;hp=592a5aafe8cc14c2c1efdc12e4215497233eefc0;hpb=7828c7fd662aca1327c45854614237ca9a942a00;p=distro-setup diff --git a/rootsshsync b/rootsshsync index 592a5aa..97d2d2f 100755 --- a/rootsshsync +++ b/rootsshsync @@ -16,10 +16,22 @@ 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 $dest + chmod 700 $dest fi -sudo cp -rL $(eval echo ~${SUDO_USER:-$USER})/.ssh/* /root/.ssh -sudo chown -R root:root /root/.ssh + +user_ssh_dir=$(eval echo ~${SUDO_USER:-$USER})/.ssh + +# remove broken links, or else rsync has error about them. +find $user_ssh_dir -xtype l -exec rm '{}' \; +# -t times, so it won't rewrite the file every time, +# -L resolve links +rsync -rtL --delete $user_ssh_dir/ $dest +chown -R root:root /root/.ssh