From 3871c3fc8fca3871f0b22552cc181c8d4619f0d1 Mon Sep 17 00:00:00 2001 From: Craig Date: Wed, 23 Apr 2025 16:44:45 +0100 Subject: [PATCH] Create new script to run this python script from anywhere, and a setup script to add it to path. --- CLAUDE.md | 3 +++ README.md | 26 +++++++++++++++++++++++--- backup | 2 ++ setup.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100755 backup create mode 100755 setup.sh diff --git a/CLAUDE.md b/CLAUDE.md index 72cc418..fa07c1d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,6 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Commands - Run the backup script: `python3 backup.py` +- Install for system-wide access: `./setup.sh` - No formal testing framework is used ## Code Style Guidelines @@ -18,6 +19,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Project Structure - `/configs/`: JSON configuration files for different backup jobs - `backup.py`: Main script for creating tar.gz or zip archives of specified directories +- `backup`: Shell script wrapper to run backup.py from any directory +- `setup.sh`: Installation script to make the backup command available system-wide ## Config File Format ```json diff --git a/README.md b/README.md index f29a7be..993357a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,26 @@ Simple-Backup provides: - Pattern-based file exclusion - Cross-platform compatibility on Linux systems +## Installation + +You can install Simple-Backup system-wide to run it from anywhere: + +```bash +# Clone the repository +git clone https://github.com/yourusername/simple-backup.git +cd simple-backup + +# Run the setup script +./setup.sh +``` + +The setup script will either: +1. Create a symlink in `/usr/local/bin` if you have write permissions +2. Prompt you to run with sudo if needed +3. Offer to add the directory to your PATH in ~/.bashrc + +After installation, you can run the `backup` command from any directory. + ## Configuration Create new backup jobs by adding JSON configuration files to the `configs/` directory. Each configuration file should include: @@ -45,10 +65,10 @@ You can run backups manually or as a scheduled task: ### Manual Execution ```bash -# Make the script executable if needed -chmod +x backup.py +# Once installed, simply run: +backup -# Run the backup +# Or from the repository directory: ./backup.py ``` diff --git a/backup b/backup new file mode 100755 index 0000000..1b9514b --- /dev/null +++ b/backup @@ -0,0 +1,2 @@ +#!/bin/bash +cd "$(dirname "$(realpath "$0")")" && python3 backup.py \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..6706cd2 --- /dev/null +++ b/setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Create executable backup script +chmod +x backup.py +chmod +x backup + +# Create a symlink in /usr/local/bin to make it accessible from anywhere +if [ -w /usr/local/bin ]; then + # If we have write permission to /usr/local/bin + ln -sf "$(realpath backup)" /usr/local/bin/backup + echo "Created symlink in /usr/local/bin/backup" +else + # If we don't have permission, suggest using sudo + echo "To install system-wide, run:" + echo "sudo ln -sf $(realpath backup) /usr/local/bin/backup" + + # Offer to add to user's path as an alternative + read -p "Would you like to add it to your PATH in ~/.bashrc instead? (y/n) " choice + if [[ $choice == "y" || $choice == "Y" ]]; then + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + echo "export PATH=\"\$PATH:$SCRIPT_DIR\"" >> ~/.bashrc + echo "Added to PATH in ~/.bashrc" + echo "Run 'source ~/.bashrc' to apply changes" + fi +fi + +echo "Setup complete. You can now run 'backup' from anywhere." \ No newline at end of file