From a4110f2e42fc5f5fed1b3510d6d65e7a5deecc37 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 12 Apr 2025 22:20:24 +0200 Subject: [PATCH] added synlink creation/update utility --- autodeploy/symlink.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 autodeploy/symlink.sh diff --git a/autodeploy/symlink.sh b/autodeploy/symlink.sh new file mode 100755 index 0000000..569bcbd --- /dev/null +++ b/autodeploy/symlink.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +function symlink() { + local target="$1" + local link="$2" + + local arrow="$link -> $target" + local current_target=$(readlink "$link") + + # link is already correct + if [ -L "$link" ] && [ "$current_target" == "$target" ]; then + echo "Symlink ($arrow) already exists" + return 0 + fi + + # link exists but is not a symlink + if [ -e "$link" ] && [ ! -L "$link" ]; then + echo "Error: $link exists but is not a symlink" + exit 1 + fi + + # link points to wrong target + if [ -L "$link" ]; then + echo "Symlink $link points to the wrong target: $current_target" + rm "$link" + fi + + ln -s "$target" "$link" + echo "Symlink ($arrow) created" +} + + +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +target="$1" +link="$2" + +symlink "$target" "$link" + +