From 27f9dbc83e0473237487198afbcf322d6734b511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jir=CC=8Ci=CC=81=20Kubi=CC=81c=CC=8Cek?= Date: Sat, 23 Nov 2024 20:46:19 +0100 Subject: [PATCH] Initial commit --- .github/workflows/pi-gen.yml | 44 ++++++++++ LICENSE | 21 +++++ README | 82 +++++++++++++++++++ stage-ezui/01-install-packages/00-packages-nr | 8 ++ stage-ezui/02-nodered/00-run-chroot.sh | 66 +++++++++++++++ stage-ezui/02-nodered/00-run.sh | 4 + .../03-splash-auto-boot/00-run-chroot.sh | 7 ++ stage-ezui/EXPORT_IMAGE | 0 stage-ezui/prerun.sh | 4 + 9 files changed, 236 insertions(+) create mode 100644 .github/workflows/pi-gen.yml create mode 100644 LICENSE create mode 100644 README create mode 100644 stage-ezui/01-install-packages/00-packages-nr create mode 100755 stage-ezui/02-nodered/00-run-chroot.sh create mode 100755 stage-ezui/02-nodered/00-run.sh create mode 100755 stage-ezui/03-splash-auto-boot/00-run-chroot.sh create mode 100644 stage-ezui/EXPORT_IMAGE create mode 100755 stage-ezui/prerun.sh diff --git a/.github/workflows/pi-gen.yml b/.github/workflows/pi-gen.yml new file mode 100644 index 0000000..5612da2 --- /dev/null +++ b/.github/workflows/pi-gen.yml @@ -0,0 +1,44 @@ +name: Generate RPI Image + +on: + push: + tags: + - '*' + workflow_dispatch: + +permissions: + contents: write + +jobs: + build-rpi-image: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run pi-gen-action + uses: usimd/pi-gen-action@v1.10.0 + id: build + with: + image-name: ezui + hostname: ezui + username: ezui + password: ezui + compression: gz + compression-level: 6 + disable-first-boot-user-rename: 1 + enable-ssh: 1 + keyboard-keymap: us + locale: en_US.UTF-8 + pi-gen-version: arm64 + release: bookworm + stage-list: stage0 stage1 stage2 ./stage-ezui + timezone: Europe/Prague + verbose-output: true + + - name: Release image + uses: softprops/action-gh-release@v2 + with: + name: first + files: ${{ steps.build.outputs.image-path }} + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2fc4d7f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Jiří Kubíček, KRAXNET s.r.o. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..ef76cb2 --- /dev/null +++ b/README @@ -0,0 +1,82 @@ +# Raspberry Pi Image Builder with Node-RED and Dashboard + +This repository automates the creation of a custom Raspberry Pi image pre-installed with [Node-RED](https://nodered.org/) and its Dashboard. Using GitHub Actions, the image is built with [pi-gen](https://github.com/RPi-Distro/pi-gen) and deployed as downloadable releases. + +## Features + +- Automated image building and release using [pi-gen-action](https://github.com/usimd/pi-gen-action). +- Pre-installed [Node-RED](https://nodered.org/) and [Node-RED Dashboard](https://flows.nodered.org/node/node-red-dashboard). +- Configured to work out-of-the-box for Raspberry Pi devices. + +## Getting Started + +### Download the Image + +Head to the [Releases](https://github.com/your-username/your-repo-name/releases) section to download the latest Raspberry Pi image. Flash it to your SD card using a tool like [Raspberry Pi Imager](https://www.raspberrypi.com/software/) or [Balena Etcher](https://www.balena.io/etcher/). + +### Prerequisites + +- A Raspberry Pi (tested on models XYZ, adjust as needed). +- A microSD card (8 GB or larger recommended). +- Optional: Ethernet or Wi-Fi setup if network connectivity is required. + +### Flashing the Image + +1. Download the `.img` file from the [Releases](https://github.com/your-username/your-repo-name/releases) section. +2. Use [Raspberry Pi Imager](https://www.raspberrypi.com/software/) or [Balena Etcher](https://www.balena.io/etcher/) to flash the image to your microSD card. +3. Insert the microSD card into your Raspberry Pi and power it on. + +### Accessing Node-RED + +1. Open a web browser and navigate to `http://:1880`. +2. Customize and deploy your flows using the built-in Node-RED editor. +3. Use the Node-RED Dashboard at `http://:1880/ui` to interact with your projects. + +## How It Works + +### GitHub Actions + +This project uses [pi-gen-action](https://github.com/davestephens/pi-gen-action) to automate the build process. Upon every push to the `main` branch or when manually triggered, GitHub Actions: + +1. Clones the [pi-gen](https://github.com/RPi-Distro/pi-gen) repository. +2. Applies customizations for Node-RED and the Dashboard. +3. Builds the Raspberry Pi image. +4. Uploads the image as a release artifact. + +### Directory Structure + +- `stage-custom`: Contains customization scripts and configuration for Node-RED. +- `.github/workflows`: Defines the GitHub Actions workflows. +- `config`: Configuration files for pi-gen. + +## Development and Customization + +### Modifying Node-RED Configuration + +To customize the Node-RED environment: + +1. Update the files in the `stage-custom` directory. +2. Push changes to the repository. The new image will be built and released automatically. + +### Testing Locally + +You can build the image locally using `pi-gen`. Refer to the [pi-gen documentation](https://github.com/RPi-Distro/pi-gen) for setup instructions. + +## Contributing + +Contributions are welcome! Please open an issue or submit a pull request to suggest changes or enhancements. + +## License + +This project is licensed under the [MIT License](LICENSE). + +## Acknowledgments + +- [pi-gen](https://github.com/RPi-Distro/pi-gen) - The official Raspberry Pi image builder. +- [pi-gen-action](https://github.com/davestephens/pi-gen-action) - GitHub Action for pi-gen. +- [Node-RED](https://nodered.org/) - Low-code programming for event-driven applications. + +--- + +Make sure to replace placeholders like `your-username` and `your-repo-name` with the appropriate values from your project. Let me know if you need further adjustments! + diff --git a/stage-ezui/01-install-packages/00-packages-nr b/stage-ezui/01-install-packages/00-packages-nr new file mode 100644 index 0000000..1a2d595 --- /dev/null +++ b/stage-ezui/01-install-packages/00-packages-nr @@ -0,0 +1,8 @@ +vlc +chromium +plymouth +plymouth-themes +xinit +xserver-xorg +nodejs +npm diff --git a/stage-ezui/02-nodered/00-run-chroot.sh b/stage-ezui/02-nodered/00-run-chroot.sh new file mode 100755 index 0000000..e79c3a0 --- /dev/null +++ b/stage-ezui/02-nodered/00-run-chroot.sh @@ -0,0 +1,66 @@ +#!/bin/bash -e + +# based on https://github.com/Tknika/iombian/blob/master/stage9/05-node-red/00-run-chroot.sh + +NODERED_VERSION=4.0.5 + +NODERED_USER=$FIRST_USER_NAME +NODERED_GROUP=$FIRST_USER_NAME +NODERED_HOME=$( getent passwd "$NODERED_USER" | cut -d: -f6 ) + +# install node-red package +npm i -g --unsafe-perm --no-progress node-red@$NODERED_VERSION + +# set local folder +mkdir -p "$NODERED_HOME/.node-red/node_modules" +chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/ +pushd "$NODERED_HOME/.node-red" +npm config set update-notifier false + +# create package.json +if [ ! -f "package.json" ]; then + echo '{' > package.json + echo ' "name": "node-red-project",' >> package.json + echo ' "description": "A Node-RED Project",' >> package.json + echo ' "version": "0.0.1",' >> package.json + echo ' "dependencies": {' >> package.json + echo ' }' >> package.json + echo '}' >> package.json +fi + +# install bcryptjs library +npm i --unsafe-perm --save --no-progress bcryptjs + +# install extra Pi nodes +EXTRANODES="node-red-dashboard" +npm i --unsafe-perm --save --no-progress $EXTRANODES + +# reset permissions +popd +mkdir -p "$NODERED_HOME/.npm" +chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.npm +chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/ + +# start/stop/log scripts +mkdir -p /usr/bin +curl -sL -o /usr/bin/node-red-start https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start +curl -sL -o /usr/bin/node-red-stop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop +curl -sL -o /usr/bin/node-red-restart https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart +curl -sL -o /usr/bin/node-red-reload https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload +curl -sL -o /usr/bin/node-red-log https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log +curl -sL -o /etc/logrotate.d/nodered https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate +chmod +x /usr/bin/node-red-start +chmod +x /usr/bin/node-red-stop +chmod +x /usr/bin/node-red-restart +chmod +x /usr/bin/node-red-reload +chmod +x /usr/bin/node-red-log + +# add systemd script +curl -sL -o /lib/systemd/system/nodered.service https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service +sed -i 's#^User=pi#User='$NODERED_USER'#;s#^Group=pi#Group='$NODERED_GROUP'#;s#^WorkingDirectory=/home/pi#WorkingDirectory='$NODERED_HOME'#;' /lib/systemd/system/nodered.service + +# remove unneeded large sentiment library to save space and load time +rm -f /usr/lib/node_modules/node-red/node_modules/multilang-sentiment/build/output/build-all.json + +# enable systemd service +systemctl enable nodered.service \ No newline at end of file diff --git a/stage-ezui/02-nodered/00-run.sh b/stage-ezui/02-nodered/00-run.sh new file mode 100755 index 0000000..25c0856 --- /dev/null +++ b/stage-ezui/02-nodered/00-run.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e + +mkdir -p ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.node-red +mkdir -p ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.npm diff --git a/stage-ezui/03-splash-auto-boot/00-run-chroot.sh b/stage-ezui/03-splash-auto-boot/00-run-chroot.sh new file mode 100755 index 0000000..c3cd9b3 --- /dev/null +++ b/stage-ezui/03-splash-auto-boot/00-run-chroot.sh @@ -0,0 +1,7 @@ +raspi-config nonint do_boot_behaviour B2 +plymouth-set-default-theme --rebuild-initrd spinfinity + +echo "if [[ -z \$SSH_CONNECTION ]]; then + startx /usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:1880/ui -- -nocursor > /dev/null 2>&1 +fi" >> /home/${FIRST_USER_NAME}/.bashrc + diff --git a/stage-ezui/EXPORT_IMAGE b/stage-ezui/EXPORT_IMAGE new file mode 100644 index 0000000..e69de29 diff --git a/stage-ezui/prerun.sh b/stage-ezui/prerun.sh new file mode 100755 index 0000000..2bd18db --- /dev/null +++ b/stage-ezui/prerun.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e +if [ ! -d "${ROOTFS_DIR}" ]; then + copy_previous +fi