From 09de089a64c67fa458d54d3f04a2d822e8204ae5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 11 Jul 2022 07:08:42 +0300 Subject: make-symlinks: allow per-host configs Sponsored-by: author --- make-symlinks | 25 ++++++++++++++++++++----- 1 file 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 -- cgit v1.2.1