Compare commits

..

10 Commits

9 changed files with 325 additions and 218 deletions

11
.github/prompts/removefabric.prompt.md vendored Normal file
View File

@@ -0,0 +1,11 @@
Create a portable bash shell script to safely uninstall the Fabric AI CLI and related packages on Debian, Ubuntu, and Fedora systems. The script must:
- Detect the operating system and select the appropriate package manager (`apt`, `dnf`, or `yum`).
- Uninstall Fabric packages installed via system package managers and Python package managers (`pip`, `pip3`).
- Check for errors after each removal step; abort the script if a critical error occurs.
- Prompt the user for confirmation before making any changes.
- Advise the user to reboot the system if required after uninstallation.
- Log all actions and errors to a user-specified log file.
- Be fully self-contained and compatible with bash.
Reference the official [Fabric documentation](https://github.com/danielmiessler/Fabric) and your distributions package manager documentation for implementation details.

2
.gitignore vendored
View File

@@ -23,6 +23,7 @@ _book
# Runtime generated files
logs/
uninstall-fabric.log
immich_backups/*.gz
# Backup files - ignore most backups but keep current state files
crontab/crontab-backups/*/archive/
@@ -36,6 +37,7 @@ crontab/crontab-backups/*/archive/
# can be downloaded from <https://github.com/Backblaze/B2_Command_Line_Tool/releases/latest/download/b2-linux>
immich/b2-linux
# Generated dotfiles - these are created dynamically by bootstrap process
dotfiles/my-aliases.zsh

View File

@@ -7,7 +7,6 @@ This repository contains various shell scripts for managing media-related tasks
- **[Backup Scripts](#backup-scripts)** - Enterprise-grade backup solutions
- **[Management Scripts](#management-scripts)** - System and service management
- **[Security](#security)** - Comprehensive security framework and standards
- **[AI Integration](#ai-integration)** - Fabric setup for AI-assisted development
- **[Tab Completion](#tab-completion)** - Intelligent command-line completion
- **[Documentation](#comprehensive-documentation)** - Complete guides and references
- **[Testing](#testing)** - Docker-based validation framework
@@ -72,51 +71,6 @@ All scripts undergo comprehensive security validation:
For security-related changes, refer to the security documentation and follow the established security checklist.
## AI Integration
This repository includes a complete AI development environment with Fabric integration for AI-assisted development tasks.
### Fabric Setup
The system includes:
- **Fabric v1.4.195** with 216+ AI patterns for text processing
- **Google Gemini 2.5 Pro** as primary AI provider
- **External AI providers** support for flexibility
- **Custom shell configuration** for optimal development experience
### Basic Fabric Usage
```bash
# List all available patterns
fabric -l
# Use a pattern (configure your preferred AI provider)
echo "Your text here" | fabric -p summarize
# Use with specific model
echo "Your text here" | fabric -p summarize -m gemini-2.0-flash-exp
# Update patterns
fabric -U
```
### Popular AI Patterns
- `summarize` - Summarize text content
- `explain_code` - Explain code snippets and logic
- `improve_writing` - Enhance writing quality and clarity
- `extract_wisdom` - Extract key insights from content
- `create_quiz` - Generate quiz questions from text
- `analyze_claims` - Analyze and fact-check claims
### Configuration Files
- **Fabric config**: `~/.config/fabric/.env` - AI provider settings and API keys
- **Shell config**: `~/.zshrc` - Main shell configuration
For complete setup instructions, see the setup documentation.
### Development Projects
- **[Telegram Backup Monitoring Bot](./telegram/github-issues/README.md)**: Comprehensive Telegram bot project for monitoring and managing all backup systems with real-time notifications and control capabilities.
@@ -423,22 +377,6 @@ This installs:
- Tab completion for all scripts
- Development tools (Node.js via nvm, VS Code, etc.)
### AI Development Environment
For AI-assisted development, the system includes:
- **Fabric** with 216+ AI patterns for text processing
- **Google Gemini integration** as primary AI provider
- **External AI provider support** for flexibility
- **Custom configuration** for easy management
Test the AI setup:
```bash
# Test Fabric integration
echo "Test text" | fabric -p summarize
```
## Dotfiles
The repository includes dotfiles for system configuration in the `dotfiles` directory. These can be automatically set up using the bootstrap script:

View File

@@ -3,7 +3,7 @@
export PATH=$PATH:$HOME/.local/bin
# Path to your oh-my-zsh installation.
export ZSH="/home/acedanger/.oh-my-zsh"
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
@@ -100,8 +100,10 @@ export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Automatically use node version specified in .nvmrc if present
autoload -U add-zsh-hook
load-nvmrc() {
# Only enable if nvm is loaded
if command -v nvm_find_nvmrc > /dev/null 2>&1; then
autoload -U add-zsh-hook
load-nvmrc() {
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
@@ -113,11 +115,12 @@ load-nvmrc() {
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
fi
[[ -s /home/acedanger/.autojump/etc/profile.d/autojump.sh ]] && source /home/acedanger/.autojump/etc/profile.d/autojump.sh
[[ -s $HOME/.autojump/etc/profile.d/autojump.sh ]] && source $HOME/.autojump/etc/profile.d/autojump.sh
# Enable bash completion compatibility in zsh
autoload -U +X bashcompinit && bashcompinit
@@ -138,48 +141,11 @@ if [ -f "$HOME/shell/completions/env-backup-completion.bash" ]; then
source "$HOME/shell/completions/env-backup-completion.bash"
fi
# Go environment variables (required for Fabric and other Go tools)
# Go environment variables
# GOROOT is auto-detected by Go when installed via package manager
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
# Fabric AI - Pattern aliases and helper functions
if command -v fabric &> /dev/null; then
# Loop through all directories in the ~/.config/fabric/patterns directory to create aliases
if [ -d "$HOME/.config/fabric/patterns" ]; then
for pattern_dir in $HOME/.config/fabric/patterns/*/; do
if [ -d "$pattern_dir" ]; then
# Get the base name of the directory (i.e., remove the directory path)
pattern_name=$(basename "$pattern_dir")
# Create an alias in the form: alias pattern_name="fabric --pattern pattern_name"
alias_command="alias $pattern_name='fabric --pattern $pattern_name'"
# Evaluate the alias command to add it to the current shell
eval "$alias_command"
fi
done
fi
# YouTube transcript helper function
yt() {
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ]; then
echo "Usage: yt [-t | --timestamps] youtube-link"
echo "Use the '-t' flag to get the transcript with timestamps."
return 1
fi
transcript_flag="--transcript"
if [ "$1" = "-t" ] || [ "$1" = "--timestamps" ]; then
transcript_flag="--transcript-with-timestamps"
shift
fi
local video_link="$1"
fabric -y "$video_link" $transcript_flag
}
fi
# SSH Agent Management - Start only if needed and working properly
ssh_agent_start() {
local ssh_agent_env="$HOME/.ssh-agent-env"

View File

@@ -61,14 +61,24 @@ if ! command -v git &>/dev/null; then
esac
fi
# Create shell directory if it doesn't exist
mkdir -p "$HOME/shell"
# Clone or update repository
if [ -d "$DOTFILES_DIR" ]; then
if [ -d "$DOTFILES_DIR/.git" ]; then
echo -e "${YELLOW}Updating existing shell repository...${NC}"
cd "$DOTFILES_DIR"
git pull origin $DOTFILES_BRANCH
elif [ -d "$DOTFILES_DIR" ]; then
echo -e "${YELLOW}Directory exists but is not a git repository.${NC}"
# Check if directory is empty
if [ -z "$(ls -A "$DOTFILES_DIR")" ]; then
echo -e "${YELLOW}Directory is empty. Cloning...${NC}"
git clone "https://github.com/$DOTFILES_REPO.git" "$DOTFILES_DIR"
else
echo -e "${YELLOW}Backing up existing directory...${NC}"
mv "$DOTFILES_DIR" "${DOTFILES_DIR}.bak.$(date +%s)"
echo -e "${YELLOW}Cloning shell repository...${NC}"
git clone "https://github.com/$DOTFILES_REPO.git" "$DOTFILES_DIR"
fi
cd "$DOTFILES_DIR"
else
echo -e "${YELLOW}Cloning shell repository...${NC}"
git clone "https://github.com/$DOTFILES_REPO.git" "$DOTFILES_DIR"

View File

@@ -21,4 +21,3 @@ eza // Modern ls alternative
// These are handled separately in the setup script
// lazygit
// lazydocker
fabric

View File

@@ -185,14 +185,6 @@ for pkg in "${pkgs[@]}"; do
continue
fi
# Handle fabric installation
if [ "$pkg" = "fabric" ]; then
special_installs+=("$pkg")
continue
fi
# Handle lazygit - available in COPR for Fedora, special install for Debian/Ubuntu
if [ "$pkg" = "lazygit" ] && [ "$OS_NAME" != "fedora" ]; then
special_installs+=("$pkg")
@@ -245,28 +237,6 @@ esac
echo -e "${GREEN}Package installation completed for $OS_NAME $OS_VERSION.${NC}"
# Install Go if not present (required for Fabric and other Go tools)
echo -e "${YELLOW}Checking Go installation...${NC}"
if ! command -v go &> /dev/null; then
echo -e "${YELLOW}Installing Go programming language...${NC}"
GO_VERSION="1.21.5" # Stable version that works well with Fabric
# Download and install Go
wget -q "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O /tmp/go.tar.gz
# Remove any existing Go installation
sudo rm -rf /usr/local/go
# Extract Go to /usr/local
sudo tar -C /usr/local -xzf /tmp/go.tar.gz
rm /tmp/go.tar.gz
echo -e "${GREEN}Go ${GO_VERSION} installed successfully!${NC}"
echo -e "${YELLOW}Go PATH will be configured in shell configuration${NC}"
else
echo -e "${GREEN}Go is already installed: $(go version)${NC}"
fi
# Handle special installations that aren't available through package managers
echo -e "${YELLOW}Installing special packages...${NC}"
for pkg in "${special_installs[@]}"; do
@@ -285,44 +255,6 @@ for pkg in "${special_installs[@]}"; do
echo -e "${GREEN}Lazydocker is already installed${NC}"
fi
;;
"fabric")
if ! command -v fabric &> /dev/null; then
echo -e "${YELLOW}Installing Fabric from GitHub releases...${NC}"
# Download and install the latest Fabric binary for Linux AMD64
curl -L https://github.com/danielmiessler/fabric/releases/latest/download/fabric-linux-amd64 -o /tmp/fabric
chmod +x /tmp/fabric
sudo mv /tmp/fabric /usr/local/bin/fabric echo -e "${GREEN}Fabric binary installed successfully!${NC}"
# Verify installation
if fabric --version; then
echo -e "${GREEN}Fabric installation verified!${NC}"
echo -e "${YELLOW}Running Fabric setup...${NC}"
# Create fabric config directory
mkdir -p "$HOME/.config/fabric"
# Run fabric setup with proper configuration
echo -e "${YELLOW}Setting up Fabric patterns and configuration...${NC}"
# Initialize fabric with default patterns
fabric --setup || echo -e "${YELLOW}Initial fabric setup completed${NC}"
# Update patterns to get the latest
echo -e "${YELLOW}Updating Fabric patterns...${NC}"
fabric --updatepatterns || echo -e "${YELLOW}Pattern update completed${NC}"
echo -e "${GREEN}Fabric setup completed successfully!${NC}"
echo -e "${YELLOW}You can test fabric with: fabric --list-patterns${NC}"
else
echo -e "${RED}Fabric installation verification failed${NC}"
fi
else
echo -e "${GREEN}Fabric is already installed${NC}"
# Still try to update patterns
echo -e "${YELLOW}Updating Fabric patterns...${NC}"
fabric --updatepatterns || echo -e "${YELLOW}Pattern update completed${NC}"
fi
;;
"lazygit")
if ! command -v lazygit &> /dev/null; then
echo -e "${YELLOW}Installing Lazygit from GitHub releases...${NC}"
@@ -635,30 +567,8 @@ echo -e "${GREEN}OS: $OS_NAME $OS_VERSION${NC}"
echo -e "${GREEN}Package Manager: $PKG_MANAGER${NC}"
echo -e "${GREEN}Shell: $(basename "$SHELL") → zsh${NC}"
echo -e "\n${YELLOW}Testing Fabric installation...${NC}"
if command -v fabric &> /dev/null; then
echo -e "${GREEN}✓ Fabric is installed${NC}"
# Test fabric patterns
echo -e "${YELLOW}Testing Fabric patterns...${NC}"
if fabric --list-patterns >/dev/null 2>&1; then
echo -e "${GREEN}✓ Fabric patterns are available${NC}"
echo -e "${YELLOW}Number of patterns: $(fabric --list-patterns 2>/dev/null | wc -l)${NC}"
else
echo -e "${YELLOW}⚠ Fabric patterns may need to be updated${NC}"
fi
else
echo -e "${RED}✗ Fabric is not installed${NC}"
fi
echo -e "\n${GREEN}=== Post-Installation Instructions ===${NC}"
echo -e "${YELLOW}1. Restart your shell or run: source ~/.zshrc${NC}"
echo -e "${YELLOW}2. Test Fabric: fabric --list-patterns${NC}"
echo -e "${YELLOW}3. Try a Fabric pattern: echo 'Hello world' | fabric --pattern summarize${NC}"
echo -e "\n${GREEN}=== Useful Commands ===${NC}"
echo -e "${YELLOW}• Fabric help: fabric --help${NC}"
echo -e "${YELLOW}• Update patterns: fabric --updatepatterns${NC}"
echo -e "\n${GREEN}Setup completed successfully for $OS_NAME $OS_VERSION!${NC}"
echo -e "${YELLOW}Note: You may need to log out and log back in for all changes to take effect.${NC}"

214
uninstall-fabric.sh Executable file
View File

@@ -0,0 +1,214 @@
#!/bin/bash
# uninstall-fabric.sh
#
# Description: Safely uninstalls the Fabric AI CLI (Daniel Miessler) and related configuration.
# Avoids removing the 'fabric' Python deployment library.
# Detects OS and uses appropriate package managers if applicable.
# Logs all actions to a file.
#
# Usage: ./uninstall-fabric.sh
#
# Author: GitHub Copilot
set -u
# Configuration
LOG_FILE="uninstall-fabric.log"
CURRENT_DATE=$(date +'%Y-%m-%d %H:%M:%S')
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Initialize log file
echo "Fabric AI CLI Uninstallation Log - Started at $CURRENT_DATE" > "$LOG_FILE"
# Logging functions
log() {
local message="$1"
echo -e "[$(date +'%H:%M:%S')] $message" | tee -a "$LOG_FILE"
}
info() {
local message="$1"
echo -e "${BLUE}[INFO]${NC} $message" | tee -a "$LOG_FILE"
}
success() {
local message="$1"
echo -e "${GREEN}[SUCCESS]${NC} $message" | tee -a "$LOG_FILE"
}
warning() {
local message="$1"
echo -e "${YELLOW}[WARNING]${NC} $message" | tee -a "$LOG_FILE"
}
error() {
local message="$1"
echo -e "${RED}[ERROR]${NC} $message" | tee -a "$LOG_FILE"
exit 1
}
# Function to detect Operating System
detect_os() {
if [[ -f /etc/os-release ]]; then
# shellcheck source=/dev/null
. /etc/os-release
OS_NAME=$ID
VERSION_ID=$VERSION_ID
info "Detected OS: $NAME ($ID) $VERSION_ID"
else
error "Could not detect operating system. /etc/os-release file not found."
fi
}
# Function to check for root privileges
check_privileges() {
if [[ $EUID -ne 0 ]]; then
warning "This script is not running as root."
warning "System package removal might fail or require sudo password."
else
info "Running with root privileges."
fi
}
# Function to confirm action
confirm_execution() {
echo -e "\n${YELLOW}WARNING: This script will attempt to uninstall the Fabric AI CLI (Daniel Miessler).${NC}"
echo -e "It will NOT remove the 'fabric' Python deployment library."
echo -e "It will remove the 'fabric' binary if identified as the AI tool, and configuration files."
echo -e "Please ensure you have backups if necessary.\n"
read -p "Do you want to proceed? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
info "Operation cancelled by user."
exit 0
fi
}
# Function to check if a binary is the Fabric AI tool
is_fabric_ai_tool() {
local bin_path="$1"
# Check help output for keywords
# The AI tool usually mentions 'patterns', 'context', 'session', 'model'
if "$bin_path" --help 2>&1 | grep -qE "Daniel Miessler|patterns|context|session|model"; then
return 0
fi
return 1
}
# Function to uninstall binary
uninstall_binary() {
local bin_path
bin_path=$(command -v fabric)
if [[ -n "$bin_path" ]]; then
info "Found 'fabric' binary at: $bin_path"
if is_fabric_ai_tool "$bin_path"; then
info "Identified as Fabric AI CLI."
# Check if owned by system package
local pkg_owner=""
if [[ "$OS_NAME" =~ (debian|ubuntu|linuxmint|pop|kali) ]]; then
if dpkg -S "$bin_path" &> /dev/null; then
pkg_owner=$(dpkg -S "$bin_path" | cut -d: -f1)
fi
elif [[ "$OS_NAME" =~ (fedora|centos|rhel|almalinux|rocky) ]]; then
if rpm -qf "$bin_path" &> /dev/null; then
pkg_owner=$(rpm -qf "$bin_path")
fi
fi
if [[ -n "$pkg_owner" ]]; then
info "Binary is owned by system package: $pkg_owner"
info "Removing package $pkg_owner..."
local sudo_prefix=""
[[ $EUID -ne 0 ]] && sudo_prefix="sudo"
if [[ "$OS_NAME" =~ (debian|ubuntu|linuxmint|pop|kali) ]]; then
$sudo_prefix apt-get remove -y "$pkg_owner" >> "$LOG_FILE" 2>&1 || error "Failed to remove package $pkg_owner"
else
$sudo_prefix dnf remove -y "$pkg_owner" >> "$LOG_FILE" 2>&1 || error "Failed to remove package $pkg_owner"
fi
success "Removed system package $pkg_owner."
else
info "Binary is not owned by a system package. Removing manually..."
rm -f "$bin_path" || error "Failed to remove $bin_path"
success "Removed binary $bin_path."
fi
else
warning "The binary at $bin_path does not appear to be the Fabric AI CLI. Skipping removal to be safe."
warning "Run '$bin_path --help' to verify what it is."
fi
else
info "'fabric' binary not found in PATH."
fi
}
# Function to uninstall from pipx
uninstall_pipx() {
if command -v pipx &> /dev/null; then
info "Checking pipx for 'fabric'..."
if pipx list | grep -q "package fabric"; then
info "Found 'fabric' installed via pipx. Uninstalling..."
pipx uninstall fabric >> "$LOG_FILE" 2>&1 || error "Failed to uninstall fabric via pipx"
success "Uninstalled fabric via pipx."
else
info "'fabric' not found in pipx."
fi
fi
}
# Function to remove configuration files
remove_config() {
local config_dirs=(
"$HOME/.config/fabric"
"$HOME/.fabric"
"$HOME/.local/share/fabric"
)
for dir in "${config_dirs[@]}"; do
if [[ -d "$dir" ]]; then
info "Found configuration directory: $dir"
rm -rf "$dir" || error "Failed to remove $dir"
success "Removed $dir."
fi
done
}
# Main execution flow
main() {
detect_os
check_privileges
confirm_execution
info "Starting uninstallation process..."
# Check pipx first as it manages its own binaries
uninstall_pipx
# Check binary
uninstall_binary
# Remove config
remove_config
echo -e "\n----------------------------------------------------------------"
success "Uninstallation steps completed."
info "A log of this operation has been saved to: $LOG_FILE"
echo -e "${YELLOW}Note: If you removed system-level components, a reboot might be recommended.${NC}"
echo -e "----------------------------------------------------------------"
}
# Trap interrupts
trap 'echo -e "\n${RED}Script interrupted by user.${NC}"; exit 1' INT TERM
# Run main
main

View File

@@ -59,7 +59,13 @@ readonly CYAN='\033[0;36m'
readonly NC='\033[0m' # No Color
# Configuration
readonly LOG_FILE="/var/log/system-update.log"
if [[ -w "/var/log" ]]; then
LOG_FILE="/var/log/system-update.log"
else
LOG_FILE="$HOME/.local/share/system-update.log"
mkdir -p "$(dirname "$LOG_FILE")"
fi
readonly LOG_FILE
# Global variables
ERRORS_DETECTED=0
@@ -516,6 +522,9 @@ perform_system_update() {
increment_error "Failed to upgrade packages with nala"
return 1
fi
log_message "INFO" "Cleaning up unused packages with nala..."
sudo nala autoremove -y
;;
dnf)
log_message "INFO" "Checking for updates with dnf..."
@@ -526,6 +535,9 @@ perform_system_update() {
increment_error "Failed to upgrade packages with dnf"
return 1
fi
log_message "INFO" "Cleaning up unused packages with dnf..."
sudo dnf autoremove -y
;;
apt)
log_message "INFO" "Updating package lists with apt..."
@@ -539,12 +551,49 @@ perform_system_update() {
increment_error "Failed to upgrade packages with apt"
return 1
fi
log_message "INFO" "Cleaning up unused packages with apt..."
sudo apt autoremove -y && sudo apt autoclean
;;
esac
# Universal packages
if command -v flatpak &> /dev/null; then
log_message "INFO" "Updating Flatpak packages..."
flatpak update -y
log_message "INFO" "Cleaning up unused Flatpak runtimes..."
flatpak uninstall --unused -y
fi
if command -v snap &> /dev/null; then
log_message "INFO" "Updating Snap packages..."
sudo snap refresh
fi
log_message "INFO" "System package update completed successfully"
}
update_signal() {
# check if hostname is `mini`
if [[ "$(hostname)" != "mini" ]]; then
debug_log "Signal update is only available on host 'mini'"
return 0
fi
# check if distrobox is installed
if ! command -v distrobox-upgrade &> /dev/null; then
debug_log "distrobox is not installed"
return 0
fi
# Capture failure to prevent script exit due to set -e
# Known issue: distrobox-upgrade may throw a stat error at the end despite success
if ! distrobox-upgrade signal; then
log_message "WARN" "Signal update reported an error (likely benign 'stat' issue). Continuing..."
fi
}
################################################################################
# Main Execution
################################################################################
@@ -583,6 +632,9 @@ main() {
upgrade_oh_my_zsh
perform_system_update
# signal is made available using distrobox and is only available on `mini`
update_signal
# Restart services
if [[ "$SKIP_SERVICES" != true ]]; then
if [[ "$SKIP_PLEX" != true ]]; then
@@ -594,6 +646,11 @@ main() {
debug_log "Skipping all service management due to --skip-services flag"
fi
# Check for reboot requirement
if [[ -f /var/run/reboot-required ]]; then
log_message "WARN" "A system reboot is required to complete the update."
fi
# Final status
if [[ $ERRORS_DETECTED -eq 0 ]]; then
log_message "INFO" "System update completed successfully!"