Skip to content

Commit

Permalink
create_or_update_link
Browse files Browse the repository at this point in the history
  • Loading branch information
kinjelom committed Jun 7, 2024
1 parent 5f03189 commit 82bc8b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions jobs/haproxy/templates/pre-start.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ create_or_update_link() {
local target="$1"
local link="$2"

# check if the symlink already exists
if [ -L "$link" ]; then
# symlink already exists
# check if the existing symlink does not point to the target
if [ "$(readlink "$link")" != "$target" ]; then
echo "Updating symbolic link..."
echo "Updating symbolic link ($link -> $target)..."
sudo ln -sf "$target" "$link"
fi
else
# symlink doesn't exist
# If the path exists but is not a symlink, remove it (could be a regular file or directory)
if [ -e "$link" ]; then
echo "Removing existing file and creating a new symbolic link..."
echo "Removing existing path ($link)..."
sudo rm "$link"
else
echo "Creating new symbolic link..."
sudo ln -s "$target" "$link"
fi
echo "Creating new symbolic link ($link -> $target)..."
sudo ln -s "$target" "$link"
fi
}

Expand Down

0 comments on commit 82bc8b6

Please sign in to comment.