Skip to content

Commit

Permalink
Merge pull request #2 from moritztim/remote
Browse files Browse the repository at this point in the history
reorganize to support run & build scripts
  • Loading branch information
moritztim authored Nov 22, 2024
2 parents 18a4ec6 + 35e1bfd commit f7e1142
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 13 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build script and attach to release

on:
release:
types: [created]

jobs:
build-and-attach:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/[email protected]

- name: Build script
run: ./build.sh > /tmp/nixos-kexec.sh

- name: Checksum
run: sha1sum /tmp/nixos-kexec.sh > /tmp/nixos-kexec.sh.sha1

- name: Attach to release
uses: csexton/release-asset-action@v3
with:
pattern: /tmp/nixos-kexec.sh*
github-token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,39 @@ Bash script to download and install NixOS using [`kexec`](https://man7.org/linux

## Usage

### Run pre-built script
```bash
curl -sSLf https://github.com/moritztim/nixos-kexec-installer/releases/latest/download/nixos_kexec.sh | bash
```

### Run

1. Generate an installer URL
```bash
./install.sh
./run.sh
```

2. Install NixOS (requires root):
```bash
sudo ./install.sh --install
sudo ./run.sh --install
```

### Build

To build a standalone script, run:
```bash
./build.sh
```

## Configuration

The script uses two configuration files:
- [`default.env`](default.env): Default configuration
- [`default.env`](src/default.env): Default configuration
- `custom.env`: Optional custom configuration that overrides the defaults set in `default.env`

### Options

The configuration options are documented in the [default configuration file](`default.env`).
The configuration options are documented in the [default configuration file](`src/default.env`).

## Requirements

Expand Down
16 changes: 16 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Outputs a fully built script to be piped to bash, saved to a file, etc.

SOURCE="./src"
DEFAULT_CONFIGURATION_FILE="$SOURCE/default.env"

set -o pipefail -o errexit

cd "$(dirname "$0")"

echo "#! /usr/bin/env bash"
echo "# This script is GENERATED. Do not edit directly."
echo
cat "$DEFAULT_CONFIGURATION_FILE"
cat "$SOURCE/read_config.sh"
cat "$SOURCE/nixos_kexec.sh"
10 changes: 10 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
SOURCE="./src"
DEFAULT_CONFIGURATION_FILE="$SOURCE/default.env"

set -o pipefail -o errexit

cd "$(dirname "$0")"

source "$SOURCE/read_config.sh"
source "$SOURCE/nixos_kexec.sh" "$@"
File renamed without changes.
13 changes: 4 additions & 9 deletions nixos-kexec.sh → src/nixos_kexec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set -o pipefail -o errexit

cd "$(dirname "$0")"

DEFAULT_CONFIGURATION_FILE="./default.env"

show_help() {
cat << EOF
Usage: $(basename "$0") [OPTIONS]
Expand Down Expand Up @@ -39,12 +37,6 @@ get_current_arch() {
esac
}

# Function to read config file
# Adapted from: https://stackoverflow.com/a/30969768/179329
read_config() {
set -o allexport && source "$1" && set +o allexport
}

# Function to prompt for missing values
prompt_missing_values() {
if [[ -z "${SOURCE:-}" ]]; then
Expand Down Expand Up @@ -88,7 +80,10 @@ parse_args() {
}

# Load default configuration
read_config "$DEFAULT_CONFIGURATION_FILE"
if [[ -f "$DEFAULT_CONFIGURATION_FILE" ]]; then
read_config "$DEFAULT_CONFIGURATION_FILE"
fi


# Load custom configuration, overriding defaults where applicable
if [[ -f "$CONFIGURATION_FILE" ]]; then
Expand Down
7 changes: 7 additions & 0 deletions src/read_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Function to read config file
# Adapted from: https://stackoverflow.com/a/30969768/179329
read_config() {
set -o allexport && source "$1" && set +o allexport
}

0 comments on commit f7e1142

Please sign in to comment.