From eb18f0c9bf3294af76562a2c6b9981a914c9041d Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:26:16 +0100 Subject: [PATCH 1/7] reorganize to support run & build scripts --- build.sh | 16 ++++++++++++++++ run.sh | 10 ++++++++++ default.env => src/default.env | 0 nixos-kexec.sh => src/nixos_kexec.sh | 13 ++++--------- src/read_config.sh | 7 +++++++ 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 build.sh create mode 100755 run.sh rename default.env => src/default.env (100%) rename nixos-kexec.sh => src/nixos_kexec.sh (92%) create mode 100755 src/read_config.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..1a39691 --- /dev/null +++ b/build.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Outputs a fully built script to be piped to bash + +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" diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..a789f97 --- /dev/null +++ b/run.sh @@ -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" "$@" diff --git a/default.env b/src/default.env similarity index 100% rename from default.env rename to src/default.env diff --git a/nixos-kexec.sh b/src/nixos_kexec.sh similarity index 92% rename from nixos-kexec.sh rename to src/nixos_kexec.sh index 0a9b23c..ff2067c 100755 --- a/nixos-kexec.sh +++ b/src/nixos_kexec.sh @@ -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] @@ -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 @@ -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 diff --git a/src/read_config.sh b/src/read_config.sh new file mode 100755 index 0000000..c07abd3 --- /dev/null +++ b/src/read_config.sh @@ -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 +} From cb5475186a66b17847d463297e7389c55d7e3c13 Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:27:08 +0100 Subject: [PATCH 2/7] leave usages open --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 1a39691..c9b3cca 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Outputs a fully built script to be piped to bash +# Outputs a fully built script to be piped to bash, saved to a file, etc. SOURCE="./src" DEFAULT_CONFIGURATION_FILE="$SOURCE/default.env" From d047331583e9f274776bb6e5747f689e7a5fcbe3 Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:28:33 +0100 Subject: [PATCH 3/7] update readme to match changes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7e33cdc..244abca 100644 --- a/README.md +++ b/README.md @@ -14,23 +14,23 @@ Bash script to download and install NixOS using [`kexec`](https://man7.org/linux 1. Generate an installer URL ```bash -./install.sh +./run.sh ``` 2. Install NixOS (requires root): ```bash -sudo ./install.sh --install +sudo ./run.sh --install ``` ## 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 From 1b58120c23cb2e46164f720289ebdc677ea54b25 Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:29:11 +0100 Subject: [PATCH 4/7] Update readme to reflect usage changes --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 244abca..f416b60 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Bash script to download and install NixOS using [`kexec`](https://man7.org/linux - Generating a download URL - Booting with kexec -## Usage +## Run 1. Generate an installer URL ```bash @@ -22,6 +22,13 @@ Bash script to download and install NixOS using [`kexec`](https://man7.org/linux sudo ./run.sh --install ``` +## Build + +To build a standalone script, run: +```bash +./build.sh +``` + ## Configuration The script uses two configuration files: From 73d431cef514b30888482c523e9146e77f788c77 Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:43:50 +0100 Subject: [PATCH 5/7] chmod --- build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 From a7e0ea91d8711e6261f4c8d9677ed6759d6edd02 Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:44:04 +0100 Subject: [PATCH 6/7] add oneliner to readme --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f416b60..827e635 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,14 @@ Bash script to download and install NixOS using [`kexec`](https://man7.org/linux - Generating a download URL - Booting with kexec -## Run +## 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 @@ -22,7 +29,7 @@ Bash script to download and install NixOS using [`kexec`](https://man7.org/linux sudo ./run.sh --install ``` -## Build +### Build To build a standalone script, run: ```bash From 35e1bfdf6459512e4c4934f1b5445880a5d99b6c Mon Sep 17 00:00:00 2001 From: "Moritz Tim W." <90388353+moritztim@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:12:38 +0100 Subject: [PATCH 7/7] Create github workflow for build on release --- .github/workflows/build.release.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/build.release.yml diff --git a/.github/workflows/build.release.yml b/.github/workflows/build.release.yml new file mode 100644 index 0000000..fb3df50 --- /dev/null +++ b/.github/workflows/build.release.yml @@ -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/checkout@v4.2.2 + + - 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 }}