Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make symlink_ds.sh more robust by checking if /usr is a distinct mountpoint #1846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .scripts/symlink_ds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ symlink_ds() {

local SYMLINK_TARGETS=("/usr/bin/ds" "/usr/local/bin/ds")

if findmnt -n /usr | grep -P "\bro\b" > /dev/null; then
local FINDMNT_CHECK_TARGET="/usr"

# Checks if /usr is a distinct filesystem or if /usr is part of the root filesystem.
if mount | grep -vq " on /usr "; then
FINDMNT_CHECK_TARGET="/"
fi

if findmnt -n $FINDMNT_CHECK_TARGET -o OPTIONS | grep -P "\bro\b" > /dev/null; then
SYMLINK_TARGETS=("${HOME}/bin/ds" "${HOME}/.local/bin/ds")
fi

for SYMLINK_TARGET in "${SYMLINK_TARGETS[@]}"; do
if [[ -L ${SYMLINK_TARGET} ]] && [[ ${SCRIPTNAME} != "$(readlink -f "${SYMLINK_TARGET}")" ]]; then
if [[ -L "${SYMLINK_TARGET}" ]] && [[ ${SCRIPTNAME} != "$(readlink -f "${SYMLINK_TARGET}")" ]]; then
info "Attempting to remove ${SYMLINK_TARGET} symlink."
sudo rm -f "${SYMLINK_TARGET}" || fatal "Failed to remove file.\nFailing command: ${F[C]}sudo rm -f \"${SYMLINK_TARGET}\""
fi
Expand Down
Loading