Upgrade dbskill to the latest version and show the update content.
Use cases
- The user actively calls
/dbskill-upgradeupgrade - Show version changes and update content
Upgrade process
Step 1: Detect the installation location
if [ -d "$HOME/.claude/skills/dbs" ]; then
INSTALL_DIR="$HOME/.claude/skills"
echo "Install location: $INSTALL_DIR"
else
echo "ERROR: dbskill not found in ~/.claude/skills/"
exit 1
fi
Step 2: Get the current version
OLD_VERSION=$(cat "$HOME/.claude/skills/dbskill-upgrade/../../VERSION" 2>/dev/null || echo "unknown")
echo "Current version: $OLD_VERSION"
Step 3: Get the remote version
REMOTE_VERSION=$(curl -sL https://raw.githubusercontent.com/dontbesilent2025/dbskill/main/VERSION || echo "")
if [ -z "$REMOTE_VERSION" ]; then
echo "ERROR: Cannot fetch remote version"
exit 1
fi
echo "Remote version: $REMOTE_VERSION"
Step 4: Compare versions
If OLD_VERSION equals REMOTE_VERSION, tell the user it is already the latest version and end.
Otherwise, continue the upgrade.
Step 5: Back up the current version
BACKUP_DIR="$HOME/.claude/skills/.dbskill-backup-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BACKUP_DIR"
cp -r "$HOME/.claude/skills"/dbs* "$BACKUP_DIR/" 2>/dev/null || true
echo "Backup created: $BACKUP_DIR"
Step 6: Download the latest version
TMP_DIR=$(mktemp -d)
git clone --depth 1 https://github.com/dontbesilent2025/dbskill.git "$TMP_DIR/dbskill"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to clone repository"
exit 1
fi
echo "Downloaded to: $TMP_DIR/dbskill"
Step 7: Replace the old version
rm -rf "$HOME/.claude/skills"/dbs*
cp -r "$TMP_DIR/dbskill/skills"/dbs* "$HOME/.claude/skills/"
rm -rf "$TMP_DIR"
echo "Upgrade completed"
If the copy fails, restore from the backup:
if [ $? -ne 0 ]; then
echo "ERROR: Upgrade failed, restoring from backup..."
rm -rf "$HOME/.claude/skills"/dbs*
cp -r "$BACKUP_DIR"/* "$HOME/.claude/skills/"
echo "Restored from backup"
exit 1
fi
Step 8: Show the update content
Read $HOME/.claude/skills/dbs/../../README.md(if it exists), and extract the update content from OLD_VERSION to REMOTE_VERSION .
Format:
dbskill v{REMOTE_VERSION} — 从 v{OLD_VERSION} 升级成功!
更新内容:
- [从 README 提取的更新要点]
升级完成!
Step 9: Clean up the backup
Ask the user whether to delete the backup:
echo "Backup location: $BACKUP_DIR"
echo "Keep backup? (will be auto-deleted in 7 days if not used)"
Do not force deletion; let the user decide.
Error handling
- Network failure: prompt the user to check the network connection
- Git clone failure: restore from the backup
- File copy failure: restore from the backup
Notes
- Only versions installed via
~/.claude/skills/are supported - Automatically back up before upgrading, and automatically restore on failure
- The user does not need to manually operate git