Skip to content
Back to skills

Install Script Cp To Symlink

BSecurity

Use when a bash install script silently skips steps due to `cp` failing on pre-existing symlinks, or when converting copy-based installs to symlink-based for auto-propagation after `git pull`.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 1, 2026
ai-agentsgobashdockergit

Security analysis

B85/100
  • highPerforms destructive filesystem operations

Pro shows the line behind each finding and how to fix it

Scanned October 1, 2026

npx -y skills add williamblair333/Uncle-J-s-Refinery --skill install-script-cp-to-symlink --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Install Script Cp To Symlink?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Install Script Cp To Symlink
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/williamblair333-install-script-cp-to-symlink/badge)](https://www.skillsdirectory.com/skills/williamblair333-install-script-cp-to-symlink)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: install-script-cp-to-symlink
description: Use when a bash install script silently skips steps due to `cp` failing on pre-existing symlinks, or when converting copy-based installs to symlink-based for auto-propagation after `git pull`.
metadata:
  type: feedback
---

## When to Use

- An install script using `set -euo pipefail` exits early with no output after certain steps
- Skills, configs, or assets installed via `cp` don't update after `git pull`
- You need to diagnose why a `cp -r "$src/." "$dst/"` command fails silently

## The Problem Pattern

`cp` errors when source and destination resolve to the same path — which happens when `$dst` is already a symlink back into `$src`. With `set -euo pipefail`, the script exits immediately, silently skipping all subsequent steps.

# This fails if $dst is already a symlink to $src:
cp -r "$src/." "$dst/"

## Diagnosis

1. Check if any destination paths are already symlinks:
   ```bash
   ls -la ~/.claude/skills/
   ```
2. Run the script with `bash -x` or check what the first erroring step is.
3. Confirm: `set -euo pipefail` at the top of the script means any cp error halts everything.

## The Fix: Switch to `ln -sfn`

Replace the `cp` block with a three-case symlink handler:

if [ -L "$dst" ] && [ "$(readlink -f "$dst")" = "$(readlink -f "$src")" ]; then
    echo "already linked: $skill"
    continue
fi
rm -rf "$dst"
ln -sfn "$src" "$dst"
echo "installed: $skill"

**Three cases handled:**
1. Already correct symlink → skip (no error)
2. Stale copy or wrong symlink → replace
3. Missing → create

## Bonus: Auto-propagation After `git pull`

Symlinks into the repo mean `git pull` updates the target immediately — no re-running install scripts. This applies to any file type installed by copy: skills, hooks, config templates, etc.

## Caveats

- `rm -rf "$dst"` before `ln -sfn` is safe for directories but irreversible for non-symlink copies — confirm the directory isn't user-modified before replacing.
- Docker services (e.g., Langfuse) are a separate category — they go down on machine restart unless `restart: unless-stopped` is set in the compose file.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.