diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-07-11 07:08:42 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-07-11 07:08:42 +0300 |
commit | 09de089a64c67fa458d54d3f04a2d822e8204ae5 (patch) | |
tree | c94600f831d27a0e30ca7d05d234b06f22adf601 | |
parent | e416e8a76864587aef634fd3043ab542cd7cc670 (diff) | |
download | liw-dot-files-09de089a64c67fa458d54d3f04a2d822e8204ae5.tar.gz |
make-symlinks: allow per-host configs
Sponsored-by: author
-rwxr-xr-x | make-symlinks | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/make-symlinks b/make-symlinks index fb90154..5a5176a 100755 --- a/make-symlinks +++ b/make-symlinks @@ -1,6 +1,6 @@ #!/bin/sh -set -e +set -eu die() { echo "$@" 1>&2 @@ -11,6 +11,20 @@ abspath() { (cd "$1" && pwd) } +src() { + dirname="$1" + file="$2" + hosted="$dirname/$(hostname)/$file" + plain="$dirname/$file" + if [ -e "$hosted" ]; then + echo "$hosted" + elif [ -e "$plain" ]; then + echo "$plain" + else + die "$file does not exist" + fi +} + dirname="$(abspath "$(dirname "$0")")" echo "$dirname" @@ -29,18 +43,19 @@ files=" ssh/config ssh/config-pers config/starship/config.toml + config/vmadm/config.yaml " install -d "$HOME/.config" for x in $files; do - [ -e "$dirname/$x" ] || die "$dirname/$x does not exist, oops" - # [ ! -L "$HOME/.$x" ] || die "$HOME/.$x is already a symlink, oops" + src "$dirname" "$x" done for x in $files; do - d="$(dirname $x)" + y="$(src "$dirname" "$x")" + d="$(dirname "$y")" if [ ! -e "$HOME/.$d" ]; then mkdir -p "$HOME/.$d" fi - ln -sf "$dirname/$x" "$HOME/.$x" + ln -sf "$y" "$HOME/.$x" done |