# n-OS-tr

n-OS-tr is an attempt to create a nostr based operating system / distro.

We are starting with a base of debian live.

Currently exploring different means to this end.

## Debian Live Build Setup and Tutorial 1 Implementation

This document covers the complete process of setting up live-build and implementing Tutorial 1 from the Debian Live Manual.

### System Requirements

Tested on Pop!_OS 22.04 LTS (Ubuntu-based system).

### Phase 1: Installing Dependencies

The following packages are required for building Debian Live images:

```bash
sudo apt update
sudo apt install debootstrap xorriso squashfs-tools syslinux-utils cpio gzip gettext
```

**Package purposes:**
- `debootstrap`: Creates minimal Debian base system
- `xorriso`: Creates ISO images
- `squashfs-tools`: Creates compressed filesystem
- `syslinux-utils`: Boot loader utilities
- `cpio`, `gzip`, `gettext`: Archive and localization utilities

### Phase 2: Setting up Live-Build from Repository

Instead of installing live-build via system packages (which may be outdated), we use the repository directly for the most current version.

#### Creating the Wrapper Script

Create `lb-wrapper.sh` for convenient access to live-build commands:

```bash
#!/bin/bash

# Set the LIVE_BUILD environment variable to point to our repository
export LIVE_BUILD="$(dirname "$0")/live-build"

# Execute the live-build frontend with all arguments passed through
"$LIVE_BUILD/frontend/lb" "$@"
```

Make it executable:
```bash
chmod +x lb-wrapper.sh
```

**Usage:** Replace all `lb` commands with `./lb-wrapper.sh` to use the repository version.

### Phase 3: Tutorial 1 - Default Image Creation

Following the Debian Live Manual Tutorial 1 to create a basic live system:

```bash
mkdir tutorial1
cd tutorial1
../lb-wrapper.sh config
```

This creates the basic configuration structure in the `config/` directory.

### Phase 4: Building the Image

**Important:** Due to keyring compatibility issues between Ubuntu/Pop!_OS and Debian, we need to bypass GPG verification for development builds.

Build the image as root with security bypass:

```bash
sudo ../lb-wrapper.sh config --apt-secure false --distribution stable
sudo ../lb-wrapper.sh build 2>&1 | tee build.log
```

### Keyring Issues and Troubleshooting

**Problem:** Pop!_OS/Ubuntu keyrings are incompatible with both Debian testing and stable distributions, causing GPG verification failures.

**Error examples:**
- Debian testing: `The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 78DBA3BC47EF2265`
- Debian stable: `The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 762F67A0B2C39DE4`

**Solution:** Use `--apt-secure false` flag to bypass GPG verification for development purposes.

**Production note:** For production builds, proper keyring setup should be implemented instead of disabling security checks.

### Expected Results

- Build time: Varies based on internet connection and system performance
- Output file: `live-image-amd64.hybrid.iso` (approximately 298MB)
- This ISO can be:
  - Tested in virtual machines (QEMU, VirtualBox)
  - Written to USB drives
  - Burned to optical media

### Command Summary

Complete sequence for Tutorial 1:

```bash
# 1. Install dependencies
sudo apt install debootstrap xorriso squashfs-tools syslinux-utils cpio gzip gettext

# 2. Create wrapper script (if not exists)
# [Create lb-wrapper.sh as shown above]
chmod +x lb-wrapper.sh

# 3. Create and configure tutorial
mkdir tutorial1
cd tutorial1
../lb-wrapper.sh config --apt-secure false --distribution stable

# 4. Build image
sudo ../lb-wrapper.sh build 2>&1 | tee build.log

# 5. Result: live-image-amd64.hybrid.iso ready for testing
```

### Notes

- The `--distribution stable` ensures we use Debian stable instead of the default testing
- Build logs are automatically saved due to the wrapper script configuration
- The `--apt-secure false` flag is a workaround for keyring issues on Ubuntu-based systems
- For clean rebuilds, use `sudo ../lb-wrapper.sh clean` before building again

## FAQ

### Q: What are the auto, config, and local directories created by `lb config` for?

**A:** When you run `lb config`, three directories are created:

1. **auto/** - Created but empty by default
   - Used for optional automation scripts that you create yourself
   - You can add `auto/config`, `auto/build`, `auto/clean` scripts that run automatically before their respective `lb` commands
   - Most basic builds (like Tutorial 1) don't need these files
   - Useful for advanced scenarios where you want reproducible builds with version control

2. **config/** - This is where the real configuration lives
   - Contains all the subdirectories for customizing your live system
   - Has the main config files (binary, bootstrap, chroot, common, source) with your build parameters
   - This is where you add package lists, custom files, hooks, etc.
   - Most important directory for customization

3. **local/** - For local customizations
   - Also typically empty unless you have custom executables or files to include
   - Used for build-time scripts and tools, not files to include in the final system

### Q: How do I add files to specific locations in the final live system?

**A:** Several directories in the config structure map directly to the final system filesystem:

**For files you want in the final live system:**

1. **config/includes.chroot/** - Maps directly to the root filesystem (`/`)
   - To put a file in `/usr/local/bin/myscript` in the final system
   - Place it at `config/includes.chroot/usr/local/bin/myscript`
   - Everything in this directory gets copied to `/` in the live system

2. **config/includes.chroot_after_packages/** - Same mapping, but copied after packages are installed
   - Use when you want to overwrite files that packages might have installed
   - Same directory mapping as above

3. **config/includes.chroot_before_packages/** - Copied before packages are installed
   - Less commonly used, but available if needed

**For files you want on the ISO/boot media itself (not in the live system):**

4. **config/includes.binary/** - Files that go on the boot media
   - These appear on the USB/CD itself, not inside the running live system
   - Useful for documentation, additional tools, etc.

**Example:** To put a custom script in `/usr/local/bin/hello` in your live system:
```bash
# 1. Create the directory structure
mkdir -p config/includes.chroot/usr/local/bin/

# 2. Put your script there
cp myscript config/includes.chroot/usr/local/bin/hello

# 3. Make it executable
chmod +x config/includes.chroot/usr/local/bin/hello
```

The build process will automatically copy it to the correct location in the live system.
