# Getting Started with SRX

This guide will help you install SRX and get up and running quickly.

---

## 📋 Prerequisites

Before installing SRX, ensure you have:

- **Rust 1.70+** - Required for compilation
- **Git** - For cloning the repository
- **A C compiler** - For native dependencies (gcc, clang, or MSVC)

### Checking Rust Installation

```bash
rustc --version
cargo --version
```

If Rust is not installed, get it from [rustup.rs](https://rustup.rs/):

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

---

## 🚀 Installation

### Option 1: Build from Source

```bash
# Clone the repository
git clone https://github.com/Jamshed-develop/srx.git
cd srx

# Build in release mode
cargo build --release
```

The binary will be available at `./target/release/srx`.

#### Optional: Install System-wide

```bash
# Copy to /usr/local/bin (requires sudo)
sudo cp ./target/release/srx /usr/local/bin/

# Or add to your PATH
export PATH="$PATH:$(pwd)/target/release"
```

### Option 2: Install via Cargo

```bash
cargo install srx
```

### Option 3: Download Pre-built Binary

Pre-built binaries are available for:
- Linux (x86_64, ARM64)
- macOS (Intel, Apple Silicon)
- Windows (x86_64)

Download from the [Releases](https://github.com/Jamshed-develop/srx/releases) page.

---

## ⚡ Quick Start

### 1. Pack a File

Create an encrypted archive:

```bash
srx pack document.pdf archive.srx -p "my_secure_password"
```

### 2. View Archive Info

Inspect an archive without extracting:

```bash
srx info archive.srx -p "my_secure_password"
```

Output:
```
Filename: document.pdf
Original size: 1048576 bytes
Compressed size: 524288 bytes
Ratio: 50.0%
Chunks: 4
Compression: Zstd
Encrypted: true
```

### 3. Unpack a File

Extract the original file:

```bash
srx unpack archive.srx -p "my_secure_password"
```

---

## 🎯 Common Use Cases

### Archiving Sensitive Documents

```bash
# Maximum compression for archival
srx pack taxes_2025.pdf taxes.srx -p "$(cat ~/.secret_passphrase)" -l 19
```

### Fast Backup of Log Files

```bash
# LZ4 for speed
srx pack /var/log/app.log backup.srx -p "backup_key" -a lz4
```

### Archiving Pre-compressed Data

```bash
# Skip compression for already compressed files
srx pack video.mp4 video.srx -p "secret" -a none
```

### Secure File Transfer

```bash
# Pack
srx pack confidential.docx confidential.srx -p "transfer_key"

# Transfer the .srx file securely
scp confidential.srx user@remote:~/

# On remote: Unpack
srx unpack confidential.srx -p "transfer_key"
```

---

## 🔧 Configuration

### Environment Variables

SRX respects these environment variables:

| Variable | Description | Default |
|----------|-------------|---------|
| `SRX_CHUNK_SIZE` | Default chunk size in bytes | 262144 (256 KiB) |
| `SRX_COMPRESSION` | Default compression algorithm | `zstd` |
| `SRX_LEVEL` | Default compression level | `3` |

### Password Best Practices

#### ✅ Good Passwords

```bash
# Use a passphrase (4+ random words)
srx pack file.txt out.srx -p "correct-horse-battery-staple"

# Read from a file
srx pack file.txt out.srx -p "$(cat ~/.password)"

# Use a password manager
srx pack file.txt out.srx -p "$(pass show archives/file)"
```

#### ❌ Avoid

```bash
# Short passwords
srx pack file.txt out.srx -p "password123"  # Too weak!

# Common words
srx pack file.txt out.srx -p "hello"  # Easily guessed!
```

---

## 📁 File Organization

### Recommended Directory Structure

```
~/archives/
├── documents/
│   ├── taxes_2025.srx
│   └── contracts.srx
├── backups/
│   ├── backup_2025-02-17.srx
│   └── backup_2025-02-10.srx
└── photos/
    └── vacation.srx
```

### Naming Conventions

```bash
# Include date for backups
srx pack data/ backup_$(date +%Y-%m-%d).srx -p "key"

# Include purpose for archives
srx pack contracts/ contracts_2025.srx -p "key"
```

---

## 🔄 Integration with Shell Scripts

### Automated Backup Script

```bash
#!/bin/bash
# backup.sh - Daily backup script

DATE=$(date +%Y-%m-%d)
SOURCE="/home/user/important"
DEST="/backup/backup_$DATE.srx"
PASSWORD=$(cat ~/.backup_key)

srx pack "$SOURCE" "$DEST" -p "$PASSWORD" -l 19

echo "Backup created: $DEST"
```

### Cron Job

```bash
# Add to crontab (crontab -e)
# Daily backup at 2 AM
0 2 * * * /home/user/scripts/backup.sh
```

---

## 🐧 Platform-Specific Notes

### Linux

- Works out of the box on most distributions
- For ARM devices (Raspberry Pi), build from source

### macOS

- Requires Xcode Command Line Tools: `xcode-select --install`
- Apple Silicon (M1/M2) is fully supported

### Windows

- Use PowerShell or Command Prompt
- Path separators: use `\` or `/` (both work)
- Consider using Windows Terminal for better experience

---

## 📚 Next Steps

- Read the [CLI Reference](CLI-Reference) for all commands
- Learn about [Security](Security) best practices
- Explore the [Library API](Library-API) for Rust integration
- Check [Performance](Performance) for optimization tips

---

## ❓ Need Help?

- Check the [FAQ](FAQ)
- See [Troubleshooting](Troubleshooting) for common issues
- [Open an issue](https://github.com/Jamshed-develop/srx/issues) on GitHub