added synlink creation/update utility

This commit is contained in:
2025-04-12 22:20:24 +02:00
parent 7036744704
commit a4110f2e42

43
autodeploy/symlink.sh Executable file
View File

@ -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 <target> <link>"
exit 1
fi
target="$1"
link="$2"
symlink "$target" "$link"