diff --git a/.github/workflows/BuildImages.yml b/.github/workflows/BuildImages.yml index c2fe4853a..9d8d8019a 100644 --- a/.github/workflows/BuildImages.yml +++ b/.github/workflows/BuildImages.yml @@ -54,8 +54,8 @@ jobs: with: config: ${{ matrix.config }} - - name: Copy output - id: copy-image + - name: Rename image file + id: move-image if: always() shell: bash run: | @@ -63,7 +63,11 @@ jobs: NOW="$(date +"%Y-%m-%d")" IMAGE="${NOW}-${DIST_NAME}-${DIST_VERSION}-${{ steps.build.outputs.type }}-${{ steps.build.outputs.sbc }}" - cp repository/src/workspace/*.img $IMAGE.img + WORKSPACE=$(echo ${{ github.workspace }}) + sudo chown -R $USER:$USER $WORKSPACE/repository/src/workspace || true + sudo chmod 0775 -R $WORKSPACE/repository/src/workspace || true + + mv repository/src/workspace/*.img $IMAGE.img echo "image=${IMAGE}" >> $GITHUB_OUTPUT @@ -71,7 +75,7 @@ jobs: if: failure() uses: actions/upload-artifact@v3 with: - name: failed-${{ steps.copy-image.outputs.image }}.log + name: failed-${{ steps.move-image.outputs.image }}.log path: repository/src/build.log - name: Compressing Image @@ -79,28 +83,28 @@ jobs: run: | CPU_COUNT="$(nproc)" echo -e "\e[32mUsing ${CPU_COUNT} Cores for compression...\e[0m" - xz -efkvz9T"${CPU_COUNT}" ${{ steps.copy-image.outputs.image }}.img + xz -efkvz9T"${CPU_COUNT}" ${{ steps.move-image.outputs.image }}.img || true - name: Calculating checksums shell: bash run: | - sha256sum ${{ steps.copy-image.outputs.image }}.img > ${{ steps.copy-image.outputs.image }}.img.sha256 - sha256sum ${{ steps.copy-image.outputs.image }}.img.xz > ${{ steps.copy-image.outputs.image }}.img.xz.sha256 + sha256sum ${{ steps.move-image.outputs.image }}.img > ${{ steps.move-image.outputs.image }}.img.sha256 + sha256sum ${{ steps.move-image.outputs.image }}.img.xz > ${{ steps.move-image.outputs.image }}.img.xz.sha256 - name: Upload Compressed Image uses: actions/upload-artifact@v3 with: - name: ${{ steps.copy-image.outputs.image }}.img.xz - path: ${{ steps.copy-image.outputs.image }}.img.xz + name: ${{ steps.move-image.outputs.image }}.img.xz + path: ${{ steps.move-image.outputs.image }}.img.xz - name: Upload Compressed Image Checksum uses: actions/upload-artifact@v3 with: - name: ${{ steps.copy-image.outputs.image }}.img.xz.sha256 - path: ${{ steps.copy-image.outputs.image }}.img.xz.sha256 + name: ${{ steps.move-image.outputs.image }}.img.xz.sha256 + path: ${{ steps.move-image.outputs.image }}.img.xz.sha256 - name: Upload Image Checksum uses: actions/upload-artifact@v3 with: - name: ${{ steps.copy-image.outputs.image }}.img.sha256 - path: ${{ steps.copy-image.outputs.image }}.img.sha256 + name: ${{ steps.move-image.outputs.image }}.img.sha256 + path: ${{ steps.move-image.outputs.image }}.img.sha256 diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 948c4ad14..1504003f4 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -120,7 +120,7 @@ jobs: needs: [ release, matrix ] runs-on: ubuntu-latest outputs: - base_name: ${{ steps.copy-image.outputs.base_name }} + base_name: ${{ steps.move-image.outputs.base_name }} strategy: fail-fast: false matrix: @@ -133,35 +133,35 @@ jobs: config: ${{ matrix.config }} build-ref: master - - name: Copy output - id: copy-image - if: always() + - name: Upload failed Logfile + if: failure() + uses: actions/upload-artifact@v3 + with: + name: failed-${{ steps.move-image.outputs.image }}.log + path: repository/src/build.log + + - name: Rename image file + id: move-image shell: bash run: | + WORKSPACE=$(echo ${{ github.workspace }}) + sudo chown -R $USER:$USER $WORKSPACE/repository/src/workspace || true + sudo chmod 0775 -R $WORKSPACE/repository/src/workspace || true + source repository/src/config base_name="${{ needs.release.outputs.date }}-${DIST_NAME}-${DIST_VERSION}" image="${base_name}-${{ steps.build.outputs.type }}-${{ steps.build.outputs.sbc }}" - cp repository/src/workspace/*.img $image.img + mv repository/src/workspace/*.img $image.img echo "base_name=${base_name}" >> $GITHUB_OUTPUT echo "image=${image}" >> $GITHUB_OUTPUT - - name: Upload failed Logfile - if: failure() - uses: actions/upload-artifact@v3 - with: - name: failed-${{ steps.copy-image.outputs.image }}.log - path: repository/src/build.log - - - name: Debug output - run: echo ${{ steps.copy-image.outputs.image }} - - name: Compressing Image shell: bash run: | CPU_COUNT="$(nproc)" echo -e "\e[32mUsing ${CPU_COUNT} Cores for compression...\e[0m" - xz -efkvz9T"${CPU_COUNT}" ${{ steps.copy-image.outputs.image }}.img + xz -efkvz9T"${CPU_COUNT}" ${{ steps.move-image.outputs.image }}.img || true - name: Upload Compressing Image if: success() @@ -170,18 +170,18 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ needs.release.outputs.id }} - file: ${{ steps.copy-image.outputs.image }}.img.xz + file: ${{ steps.move-image.outputs.image }}.img.xz - name: Calculating checksums id: checksums shell: bash run: | - sha256sum ${{ steps.copy-image.outputs.image }}.img > ${{ steps.copy-image.outputs.image }}.img.sha256 - image_checksum=`cat ${{ steps.copy-image.outputs.image }}.img.sha256 | awk '{ print $1 }'` + sha256sum ${{ steps.move-image.outputs.image }}.img > ${{ steps.move-image.outputs.image }}.img.sha256 + image_checksum=`cat ${{ steps.move-image.outputs.image }}.img.sha256 | awk '{ print $1 }'` echo "image=${image_checksum}" >> $GITHUB_OUTPUT - sha256sum ${{ steps.copy-image.outputs.image }}.img.xz > ${{ steps.copy-image.outputs.image }}.img.xz.sha256 - zip_checksum=`cat ${{ steps.copy-image.outputs.image }}.img.xz.sha256 | awk '{ print $1 }'` + sha256sum ${{ steps.move-image.outputs.image }}.img.xz > ${{ steps.move-image.outputs.image }}.img.xz.sha256 + zip_checksum=`cat ${{ steps.move-image.outputs.image }}.img.xz.sha256 | awk '{ print $1 }'` echo "zip=${zip_checksum}" >> $GITHUB_OUTPUT - name: Upload Checksums @@ -191,65 +191,74 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ needs.release.outputs.id }} - file: ${{ steps.copy-image.outputs.image }}.img.sha256;${{ steps.copy-image.outputs.image }}.img.xz.sha256 + file: ${{ steps.move-image.outputs.image }}.img.sha256;${{ steps.move-image.outputs.image }}.img.xz.sha256 - name: Calculating filesizes id: filesizes shell: bash run: | - image_filesize=`wc -c ${{ steps.copy-image.outputs.image }}.img | awk '{print $1}'` + image_filesize=`wc -c ${{ steps.move-image.outputs.image }}.img | awk '{print $1}'` echo "image=${image_filesize}" >> $GITHUB_OUTPUT - zip_filesize=`wc -c ${{ steps.copy-image.outputs.image }}.img.xz | awk '{print $1}'` + zip_filesize=`wc -c ${{ steps.move-image.outputs.image }}.img.xz | awk '{print $1}'` echo "zip=${zip_filesize}" >> $GITHUB_OUTPUT - name: Debug output run: | - echo ${{ needs.release.outputs.id }} - echo ${{ needs.release.outputs.version }} + echo "release-id: ${{ needs.release.outputs.id }}" + echo "release-version: ${{ needs.release.outputs.version }}" - echo ${{ steps.copy-image.outputs.image }} + echo "image-name: ${{ steps.move-image.outputs.image }}" - echo ${{ steps.checksums.outputs.image }} - echo ${{ steps.checksums.outputs.zip }} + echo "checksum image: ${{ steps.checksums.outputs.image }}" + echo "checksum zip: ${{ steps.checksums.outputs.zip }}" - echo ${{ steps.filesizes.outputs.image }} - echo ${{ steps.filesizes.outputs.zip }} + echo "filesize-image: ${{ steps.filesizes.outputs.image }}" + echo "filesize-zip: ${{ steps.filesizes.outputs.zip }}" - name: Generate JSON id: json uses: actions/github-script@v6 env: - name: '"Mainsail OS ${{ github.event.inputs.version }}"' - description: '"Type: ${{ steps.build.outputs.type }}, SBC: ${{ steps.build.outputs.sbc }}"' - url: '"https://github.com/mainsail-crew/MainsailOS/releases/download/${{ github.event.inputs.version }}/${{ steps.copy-image.outputs.image }}.img.xz"' - icon: '"https://os.mainsail.xyz/rpi-imager.png"' - init_format: '"systemd"' - release_date: '"${{ needs.release.outputs.date }}"' + name: "Mainsail OS ${{ github.event.inputs.version }}" + description: "Type: ${{ steps.build.outputs.type }}, SBC: ${{ steps.build.outputs.sbc }}" + type: "${{ steps.build.outputs.type }}" + sbc: "${{ steps.build.outputs.sbc }}" + url: "https://github.com/mainsail-crew/MainsailOS/releases/download/${{ github.event.inputs.version }}/${{ steps.move-image.outputs.image }}.img.xz" + icon: "https://os.mainsail.xyz/rpi-imager.png" + init_format: "systemd" + release_date: "${{ needs.release.outputs.date }}" extract_size: ${{ steps.filesizes.outputs.image }} - extract_sha256: '"${{ steps.checksums.outputs.image }}"' + extract_sha256: "${{ steps.checksums.outputs.image }}" image_download_size: ${{ steps.filesizes.outputs.zip }} - image_download_sha256: '"${{ steps.checksums.outputs.zip }}"' + image_download_sha256: "${{ steps.checksums.outputs.zip }}" with: result-encoding: string script: | - const { name, description, url, icon, init_format, release_date, extract_size, extract_sha256, image_download_size, image_download_sha256 } = process.env + const fs = require('fs') + let { name, description, type, sbc, url, icon, init_format, release_date, extract_size, extract_sha256, image_download_size, image_download_sha256 } = process.env + if (sbc === 'rpi32') name += ' 32-Bit (recommend)' + else if (sbc === 'rpi64') name += ' 64-Bit' - return JSON.stringify({ + const json = JSON.stringify({ name, description, url, icon, init_format, release_date, - extract_size, + extract_size: parseInt(extract_size), extract_sha256, - image_download_size, + image_download_size: parseInt(image_download_size), image_download_sha256 }) - - name: Write JSON - run: echo "${{steps.json.outputs.result}}" > "./${{ steps.copy-image.outputs.image }}.json" + fs.writeFileSync("./${{ steps.move-image.outputs.image }}.json", json) + + - name: Debug output + shell: bash + run: | + cat "./${{ steps.move-image.outputs.image }}.json" - name: Upload JSON if: success() @@ -258,7 +267,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ needs.release.outputs.id }} - file: ${{ steps.copy-image.outputs.image }}.json + file: ${{ steps.move-image.outputs.image }}.json finish: name: Finish Release @@ -284,34 +293,27 @@ jobs: fileName: "${{ needs.build.outputs.base_name }}-raspberry-*.json" out-file-path: "downloads" - - name: Debug - run: | - ls ./downloads/* - touch rpi-imager.json - - - name: setup python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Run script - uses: jannekem/run-python-script-action@v1 + - name: Combine JSON + id: json + uses: actions/github-script@v6 with: + result-encoding: string script: | - import os, json, shutil - with open("rpi-imager.json", "r+") as t: - t.truncate(0) - t.write('{ "os_list": [') - for filename in os.scandir('downloads'): - print(filename) - with open(filename, "r") as f: - content = f.read() - t.write(content) - t.write(',') - t.write('] }') - barak = open("rpi-imager.json", "r+") - contentb = barak.read() - print(contentb) + const downloadFolder = './downloads/' + const fs = require('fs') + const os_list = [] + + fs.readdirSync(downloadFolder).forEach(file => { + const raw = fs.readFileSync('./downloads/' + file, {encoding:'utf8', flag:'r'}) + try { + os_list.push(JSON.parse(raw)) + } catch (err) { + console.log("Error parsing JSON string:", err) + } + }) + + const json = JSON.stringify({os_list}) + fs.writeFileSync('rpi-imager.json', json) - name: Upload JSON if: success() diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2d8dedf..3810531fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,12 +19,16 @@ All notable changes to Mainsail will be documented in this file. - Add python3-serial CanBoot dependency (#129) | [1f59f0f](1f59f0f0db4ef653dafec0e04f18b3b08b639606) - Add postrename module (#128) | [942896c](942896c8c9899763f64f6e58c00570584ab528e0) - Add timelapse module (#130) | [7b99d1f](7b99d1f02fdab98a3a314cb090c1f3de6c02a203) +- Enable I2C by default (#196) | [9cebd0c](9cebd0c8545fa41a826112658dfe401b4306a2bd) +- Add Orange Pi 3 and 4 LTS (#186) | [2f556c3](2f556c3232b3d01ac48d30e08ae230cd5fda13fe) +- Add orange pi zero2 (#189) | [df2aa35](df2aa3528142f144b1c9928f90458c3a6d6c78c7) ### Bug Fixes and Improvements - **build**: Updated download paths (#65) | [0622a2f](0622a2f60a8e39237c1fd213d67932ae6c986e08) - **build**: Fixes error in Makefile (#76) | [0ff09b5](0ff09b5ac0503e8cee0c35a298a41a26344b57c8) - **build**: Updated torrent download url (#90) | [a16126c](a16126c08733f96f6db7b067e7fa12d12324569b) +- **build**: Fix mv of image file (#204) | [dc8c588](dc8c588df649fd3dff86602d13d3ae3fbea31b66) - **config.txt**: Fix configuration errors with attached screens (#119) | [81c335e](81c335eb6cb7d54de2b5433611f13dfefff2f5d7) - **crowsnest**: Fix install of crowsnest (#111) | [e8eee5f](e8eee5fc07df000cebf3ff7379454a3efce0042b) - **lint**: Should fix shellcheck warnings (#160) | [2569dd2](2569dd25db5c719c3e55d299062c5664c3c038b0) @@ -43,6 +47,17 @@ All notable changes to Mainsail will be documented in this file. - Add otg_mode=1 for CM4 in config.txt (#167) | [cb0bf60](cb0bf600e8526a79ae534a64e9fccd584eb20388) - Fix SC2086 in armbian module (#173) | [2f4f8b1](2f4f8b13737b3f95582b9c8b824136413e9884eb) - Fixes error setting link to macro (#175) | [d1ad3f8](d1ad3f8006ad7c9b84a9a34acc4798f15ab605e4) +- Fix shellcheck errors (#185) | [efe1b68](efe1b68d0a8cd5ccf3238d280c83ae523c331688) +- Fix syntax error in net module (#191) | [cb890af](cb890afafaa1ab6dc68fbfdc103ceca61432e064) +- Fix compress step (#205) | [fec2432](fec24320ea4bdcf51c9430e89443035b4ade70f1) +- Fix rpi-image.json workflow in Release.yml (#206) | [a03626a](a03626a54a21b1fa1175b458665ae14e9b755037) +- Remove enduser support msg from zero2 images (#209) | [4231216](42312164336966b8fabf72618f60216b6a797f04) +- Fix rpi-imager json value format for extract_size & image_download_size (#212) | [b82137c](b82137c14ea09f784478687d32a042c825af8262) +- Fix firstboot issue (#214) | [fae8b3f](fae8b3fd1f9f2b2cf2ca53e737f3862eddd62a36) +- Load `i2c-dev` modules (#217) | [6846f82](6846f82ff311299928824c8bceb606b1db13a444) +- Fix broken udev package (#224) | [b07d7a1](b07d7a103a2aad81045c26dc7223c26369ee1322) +- Fix udev for version 'rp1+deb11u2' (#226) | [b0343d5](b0343d55ddb9db0126f4fb9759e050d5fbcbb10e) +- Remove legacy cam stack (#227) | [8c65ad7](8c65ad7045bf2ada360b0f1307f599aea73d7d4f) ### Refactor @@ -53,6 +68,8 @@ All notable changes to Mainsail will be documented in this file. - Add `enable_auto_refresh: True` (#133) | [1b78efb](1b78efb963537a3a6dad5910ff201ba19cee2103) - Deactivate IPv6 in nginx per default (#157) | [40b3719](40b37192608e13b4f5e97b295840715a42974fb6) - Change behavior of piconfig module (#180) | [825af74](825af74061c48043c1ae8390c0825d2220bd623f) +- Use mv to move the image from the workspace to the root (#203) | [b7acb1e](b7acb1e49c02d2d9f50dfdc3541c10f4f2b2becc) +- Drop armbian_pkgupgrade (#210) | [799a919](799a919c2c4f2f8bf46971de88a79ab7d0bea137) ### Documentation @@ -102,4 +119,7 @@ All notable changes to Mainsail will be documented in this file. - Add "not-on-Github" bot for issues (#179) | [68520ce](68520ce40659e223d8c79820a7eda4923d9ae02d) - Fix changelog in release workflow (#182) | [32f9429](32f9429d49671e5657c7ed5143ca63e88046f364) - Removes fkms overlays (#183) | [999183b](999183bef6b290efcd8d4f2c8d708354152d411c) +- Remove unattended-upgrades service (#215) | [9f09363](9f093631d22b4cb00cc57601ed55bc51e23e40e0) +- Revert firstboot fix (#219) | [02e0100](02e01006c7d1d84efcaee6fb7a64045084ed8667) +- Update crowsnest module (#221) | [726239c](726239ca7db82c3867af3c28785cae0ca7b2e3eb) diff --git a/README.md b/README.md index 1eccb7e80..cf070d152 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ Learn more about: ## How to install MainsailOS ? -You can find detailed instructions in our [documentation](https://docs.mainsail.xyz/setup/mainsail-os). +You can find detailed instructions in our [documentation](https://docs-os.mainsail.xyz). -We recommend the installation via [Raspberry Pi Imager](https://docs.mainsail.xyz/setup/mainsailos/pi-imager). +We recommend the installation via [Raspberry Pi Imager](https://docs-os.mainsail.xyz/getting-started/raspberry-pi-os-based). ## How to get help? @@ -34,9 +34,9 @@ Also see the [FAQ](#faq) section. Here a list of included and preinstalled Software: -- [Klipper (3D Printer Firmware)](https://github.com/KevinOConnor/klipper) +- [Klipper (3D Printer Firmware)](https://github.com/Klipper3d/klipper) - [Moonraker (API Web Server for Klipper)](https://github.com/Arksine/moonraker) -- [Mainsail (Web interface for Klipper/Moonraker)](https://github.com/meteyou/mainsail) +- [Mainsail (Web interface for Klipper/Moonraker)](https://github.com/mainsail-crew/mainsail) - [Crowsnest (Webcam streaming)](https://github.com/mainsail-crew/crowsnest) - [Sonar (Keepalive daemon)](https://github.com/mainsail-crew/sonar) - [Nginx (Webserver & Proxy)](https://nginx.org/en/) diff --git a/config/armbian/default b/config/armbian/default index 4748088c7..bd7d28436 100644 --- a/config/armbian/default +++ b/config/armbian/default @@ -1,10 +1,39 @@ -export BASE_APT_CACHE=no -export OCTOPI_INCLUDE_WIRINGPI=no -export BASE_DISTRO=armbian -export BASE_ROOT_PARTITION=2 -export BASE_IMAGE_RESIZEROOT=500 -export BASE_IMAGE_RASPBIAN=no -export BASE_IMAGE_ENLARGEROOT=1000 -export BASE_ARCH=arm64 - -export MODULES="base,pkgupgrade" +#!/usr/bin/env bash +# Shebang for better file detection + +# Declare Variables before exporting. +# See https://www.shellcheck.net/wiki/SC2155 + +# Download Base Url +DOWNLOAD_BASE_URL="https://github.com/mainsail-crew/armbian-builds/releases/latest/download" + +# Base User +BASE_ADD_USER="yes" +BASE_USER="pi" +BASE_USER_PASSWORD="armbian" + +# Needed while building for non rpi sbc +BASE_DISTRO="armbian" +BASE_IMAGE_RASPBIAN="no" + +# partition resizing +BASE_ROOT_PARTITION="2" +BASE_IMAGE_ENLARGEROOT=2500 +BASE_IMAGE_RESIZEROOT=600 +# Compress not needed due compression done in workflow +BASE_RELEASE_COMPRESS=no +# Modules are valid for 32bit and 64bit images +MODULES="base,pkgupgrade,udev_fix,armbian(armbian_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar)" + +# export Variables +export DOWNLOAD_BASE_URL +export BASE_ADD_USER +export BASE_USER +export BASE_USER_PASSWORD +export BASE_DISTRO +export BASE_IMAGE_RASPBIAN +export BASE_ROOT_PARTITION +export BASE_IMAGE_ENLARGEROOT +export BASE_IMAGE_RESIZEROOT +export BASE_RELEASE_COMPRESS +export MODULES diff --git a/config/armbian/orangepi3lts b/config/armbian/orangepi3lts new file mode 100644 index 000000000..8fd06d0a1 --- /dev/null +++ b/config/armbian/orangepi3lts @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Shebang for better file detection +# shellcheck enable=require-variable-braces + +BASE_ARCH="arm64" + +# Image source +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi3_lts_bullseye.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi3_lts_bullseye.img.xz" + +# export Variables +export BASE_ARCH +export DOWNLOAD_URL_CHECKSUM +export DOWNLOAD_URL_IMAGE diff --git a/config/armbian/orangepi4lts b/config/armbian/orangepi4lts new file mode 100644 index 000000000..5b0a312c8 --- /dev/null +++ b/config/armbian/orangepi4lts @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Shebang for better file detection +# shellcheck enable=require-variable-braces + +BASE_ARCH="arm64" + +# Image source +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi4_lts_bullseye.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi4_lts_bullseye.img.xz" + +# export Variables +export BASE_ARCH +export DOWNLOAD_URL_CHECKSUM +export DOWNLOAD_URL_IMAGE diff --git a/config/orangepi/default b/config/orangepi/default new file mode 100644 index 000000000..8cfe3ad87 --- /dev/null +++ b/config/orangepi/default @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Shebang for better file detection + +# Declare Variables before exporting. +# See https://www.shellcheck.net/wiki/SC2155 + +# Download Base Url +DOWNLOAD_BASE_URL="https://github.com/mainsail-crew/armbian-builds/releases/latest/download" + +# Base User +BASE_ADD_USER="yes" +BASE_USER="pi" +BASE_USER_PASSWORD="armbian" + +# Needed while building for non rpi sbc +BASE_DISTRO="armbian" +BASE_IMAGE_RASPBIAN="no" + +# partition resizing +BASE_ROOT_PARTITION="2" +BASE_IMAGE_ENLARGEROOT=2500 +BASE_IMAGE_RESIZEROOT=600 +# Compress not needed due compression done in workflow +BASE_RELEASE_COMPRESS=no +# Modules are valid for 32bit and 64bit images +MODULES="base,pkgupgrade,udev_fix,orangepi(orangepi_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar)" + +# export Variables +export DOWNLOAD_BASE_URL +export BASE_ADD_USER +export BASE_USER +export BASE_USER_PASSWORD +export BASE_DISTRO +export BASE_IMAGE_RASPBIAN +export BASE_ROOT_PARTITION +export BASE_IMAGE_ENLARGEROOT +export BASE_IMAGE_RESIZEROOT +export BASE_RELEASE_COMPRESS +export MODULES diff --git a/config/orangepi/orangepi_zero2 b/config/orangepi/orangepi_zero2 new file mode 100644 index 000000000..c149d83f2 --- /dev/null +++ b/config/orangepi/orangepi_zero2 @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Shebang for better file detection +# shellcheck enable=require-variable-braces + +BASE_ARCH="arm64" + +# Image source +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/orangepi-orangepi_zero2_bullseye.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/orangepi-orangepi_zero2_bullseye.img.xz" + +# export Variables +export BASE_ARCH +export DOWNLOAD_URL_CHECKSUM +export DOWNLOAD_URL_IMAGE diff --git a/config/raspberry/default b/config/raspberry/default index 65d8dd99e..7ec32ad79 100644 --- a/config/raspberry/default +++ b/config/raspberry/default @@ -4,12 +4,12 @@ # Declare Variables before exporting. # See https://www.shellcheck.net/wiki/SC2155 -BASE_IMAGE_ENLARGEROOT=3000 +BASE_IMAGE_ENLARGEROOT=4500 BASE_IMAGE_RESIZEROOT=600 # Compress not needed due compression done in workflow BASE_RELEASE_COMPRESS=no # Modules are valid for 32bit and 64bit images -MODULES="base,pkgupgrade,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename" +MODULES="base,pkgupgrade,udev_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename" # export Variables export BASE_IMAGE_ENLARGEROOT diff --git a/config/raspberry/rpi32 b/config/raspberry/rpi32 index f01873e19..ab7d9f6d4 100644 --- a/config/raspberry/rpi32 +++ b/config/raspberry/rpi32 @@ -4,8 +4,13 @@ # Declare Variables before exporting. # See https://www.shellcheck.net/wiki/SC2155 -DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_armhf_latest.sha256" -DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_armhf_latest.torrent" +# Keep for Bookworm template +# DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_armhf_latest.sha256" +# DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_armhf_latest.torrent" + +# New locations after Bullseye turned into 'oldstable' +DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.com/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-10-10/2023-05-03-raspios-bullseye-armhf-lite.img.xz.sha256" +DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.com/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-10-10/2023-05-03-raspios-bullseye-armhf-lite.img.xz.torrent" export DOWNLOAD_URL_CHECKSUM export DOWNLOAD_URL_IMAGE diff --git a/config/raspberry/rpi64 b/config/raspberry/rpi64 index e58c6a460..7cee4dd60 100644 --- a/config/raspberry/rpi64 +++ b/config/raspberry/rpi64 @@ -6,9 +6,13 @@ BASE_ARCH="arm64" -DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.sha256" -DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.torrent" +# Keep for Bookworm template +# DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.sha256" +# DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.torrent" +# New locations after Bullseye turned into 'oldstable' +DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.com/raspios_oldstable_lite_arm64/images/raspios_oldstable_lite_arm64-2023-10-10/2023-05-03-raspios-bullseye-arm64-lite.img.xz.sha256" +DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.com/raspios_oldstable_lite_arm64/images/raspios_oldstable_lite_arm64-2023-10-10/2023-05-03-raspios-bullseye-arm64-lite.img.xz.torrent" # export variables diff --git a/patches/Readme.md b/patches/Readme.md new file mode 100644 index 000000000..b50cda1d8 --- /dev/null +++ b/patches/Readme.md @@ -0,0 +1,49 @@ +# Patches + +This Folder contains a script to patch MainsailOS to latest changes. + +## patch101.sh + +This is intended to patch MainsailOS version 1.0.0 to 1.0.1 +This fixes an error with WiFi powersave rules. +_**DO NOT RUN THIS ON LATER VERSIONS!!!**_ + +### Usage: + +`curl -sSL https://raw.githubusercontent.com/mainsail-crew/MainsailOS/develop/patches/patch101.sh | bash` + +This will ask you for sudo password! + +In most cases a reboot is required! + +## udev-fix.sh + +This is intended to patch udev rules which has a Bug in udev package (version: 247.3-7+deb11u2 or 247.3-7+rpi1+deb11u2). +Which does not create `/dev/serial/by-id` symlinks for your MCU.\ +For further details see: + +https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094 + +This is fixed by: +https://github.com/systemd/systemd/pull/25246 + +What we do: + +- Running `apt-get update` +- Running `apt-get upgrade --yes` +- `curl`ing the patched rule file from systemd repo +- Copying to desired location in `/etc/udev/rules.d/60-serial.rules` + +This overwrites behaviour in the default configuration. +Since this is the version of the master branch of systemd/udev there is no further +need to intervention even on updates. + +_**NOTE: DO NOT RUN THIS PATCH IF YOU ARE PRINTING!!!**_ + +### Usage: + +`curl -sSL https://raw.githubusercontent.com/mainsail-crew/MainsailOS/develop/patches/udev-fix.sh | bash` + +This will ask you for sudo password! + +A reboot is essential! diff --git a/patches/patch101.sh b/patches/patch101.sh new file mode 100755 index 000000000..8c5c671d6 --- /dev/null +++ b/patches/patch101.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env bash + +#### Patch Script +#### This will patch MainsailOS to the Latest Changes +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2021 +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# Error Handling +set -eo pipefail + +# Debug +# set -x + +### Variables +# shellcheck disable=SC2034 +DEBIAN_FRONTEND="noninteractive" + +# Global Vars +MAINSAILOS_VER="1.0.1" + +TITLE="\e[31mMainsailOS Patcher\e[0m - Patch OS to latest changes (MainsailOS ${MAINSAILOS_VER})" +RELEASE_FILE="/etc/mainsailos-release" +BASE_DL_URL="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/develop" + +# Message Vars +MP_OK="\e[32mOK\e[0m" +MP_SK="\e[33mSKIPPED\e[0m" + +## Helper funcs + +## Message Funcs + +echo_green(){ + echo -e "\e[32m${1}\e[0m" +} + +echo_red(){ + echo -e "\e[31m${1}\e[0m" +} + +echo_blue(){ + echo -e "\e[34m${1}\e[0m" +} + +echo_yellow(){ + echo -e "\e[33m${1}\e[0m" +} + +print_header(){ + echo -e "${TITLE}\n" + echo_blue "Ahoi!" + echo -e "Please be patient, this might take a while ..." + echo_red "\tYou'll be prompted for sudo password!\n" + # Dirty hack to grant root priviledges + sudo echo -e "\n" + echo -e "Trying to patch your system ..." +} + +print_footer(){ + echo -e "\nThank you for being patient ..." + echo_red "Reboot as soon as possible!\n" +} + +# Helper Funcs + +## CHeck Version +check_version(){ + local version + version="$(grep "1\.[0-9]\.[0-9]" "${RELEASE_FILE}" 2> /dev/null || true)" + if [[ -z "${version}" ]]; then + echo_red "Minimum required MainsailOS Version is 1.0.0! ... [Exiting]" + exit 1 + fi +} + +# Patch Funcs + +# patch mainsailos-release file +patch_release_file(){ + sudo sed -i 's|[0-9]\.[0-9]\.[0-9]|'"${MAINSAILOS_VER}"'|' "${RELEASE_FILE}" +} + +## This patches udev rules error +## See https://github.com/mainsail-crew/MainsailOS/issues/190 +## Keep function naming convention for patches! +## For ex: patch from 1.0.0 to 1.0.1 is named patch_101 + +patch_101(){ + local dl_file + dl_file="${BASE_DL_URL}/src/modules/net/filesystem/usr/local/bin/pwrsave-udev" + echo_blue "Running Wifi Powersave Patch ..." + echo -e "Search for pwrsave-udev script ..." + if [[ ! -f "/usr/local/bin/powersave-udev" ]]; then + echo -e "Script not found! Installing ..." + sudo wget -O "/usr/local/bin/pwrsave-udev" "${dl_file}" + sudo chmod +x "/usr/local/bin/pwrsave-udev" + echo -e "Script not found! Installing ... \t${MP_OK}" + else + echo -e "Script found! ... \t${MP_SK}" + fi + + echo -e "Search for udev Rule file ..." + if [[ ! -f "/etc/udev/rules.d/070-wifi-powersave.rules" ]]; then + echo -e "udev rule not found! Installing ..." + sudo bash -c '/usr/local/bin/pwrsave-udev create' + sudo bash -c '/usr/local/bin/pwrsave-udev off' + echo -e "udev rule not found! Installing ...\t${MP_OK}" + else + echo -e "udev Rule found! ... \t${MP_SK}" + fi + echo_blue "Running Wifi Powersave Patch ... ${MP_OK}" +} + + +### Main + +# Step 1: Print Header +print_header + +# Step 2: Check Version requirement +check_version + +# Step 3: Apply patches +patch_101 + +# Step 4: Patch release file to match versions +patch_release_file + +# Step 5: Print footer +print_footer diff --git a/patches/udev-fix.sh b/patches/udev-fix.sh new file mode 100755 index 000000000..2084d9756 --- /dev/null +++ b/patches/udev-fix.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash + +#### Patch Script +#### This will patch MainsailOS udev rule +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2021 +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +#### This should fix error in udev not creating symlinks fpr serial devices. +#### For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094 +#### This is fixed by: https://github.com/systemd/systemd/pull/25246 +#### To fix this error in MainsailOS we implement that file as 'user rule'. + +# shellcheck disable=SC2034 + +# Error Handling +set -eo pipefail + +# Debug +# set -x + +### Variables +DEBIAN_FRONTEND="noninteractive" +TITLE="\e[31mMainsailOS Patcher\e[0m - udev rule fix" +UDEV_FIX_RAW_RULE_FILE="https://raw.githubusercontent.com/systemd/systemd/main/rules.d/60-serial.rules" +UDEV_FIX_TMP_FILE="/tmp/60-serial.rules" +UDEV_FIX_OUTPUT_FILE="/etc/udev/rules.d/60-serial.rules" + +# Message Vars +MP_OK="\e[32mOK\e[0m" +MP_SK="\e[33mSKIPPED\e[0m" + +## Helper funcs + +## Message Funcs + +echo_green(){ + echo -e "\e[32m${1}\e[0m" +} + +echo_red(){ + echo -e "\e[31m${1}\e[0m" +} + +echo_blue(){ + echo -e "\e[34m${1}\e[0m" +} + +echo_yellow(){ + echo -e "\e[33m${1}\e[0m" +} + +print_header(){ + echo -e "${TITLE}\n" + echo_blue "Ahoi!" + echo -e "Please be patient, this might take a while ..." + echo_yellow "HINT: This should also work for any other Debian/Armbian based Distribution\n" + echo_red "\tYou'll be prompted for sudo password!\n" + # Dirty hack to grant root priviledges + sudo echo -e "\n" + echo -e "Trying to patch your system ..." +} + +print_footer(){ + echo -e "\nThank you for being patient ..." + echo_red "Reboot as soon as possible!\n" +} + +# Patch Funcs + +patch_udev(){ + local udev_pkg_version + udev_pkg_version="$(dpkg-query -s udev | grep "Version" | sed 's/Version\: //')" + + if [[ -n "${udev_pkg_version}" ]] && [[ "${udev_pkg_version}" =~ "deb11u2" ]]; then + echo_red "'udev' version: ${udev_pkg_version}, is affected by bug ..." + echo_green "Install patched udev rule from systemd git repository ..." + curl -sSL "${UDEV_FIX_RAW_RULE_FILE}" > "${UDEV_FIX_TMP_FILE}" + sudo cp "${UDEV_FIX_TMP_FILE}" "${UDEV_FIX_OUTPUT_FILE}" + rm -f "${UDEV_FIX_TMP_FILE}" + else + echo_green "'udev' version: ${udev_pkg_version}, is NOT affected by bug ... [SKIPPED]" + fi +} + +### Main +# Step 1: Print Header +print_header + +# Step 2: Run apt-get update +sudo apt-get update + +# Step 3: Run apt-get upgrade +sudo apt-get upgrade --yes + +# Step 4: Apply patches +patch_udev + +# Step 5: Print footer +print_footer + +exit 0 diff --git a/src/modules/armbian/config b/src/modules/armbian/config index c74f954ca..c36fa8a01 100644 --- a/src/modules/armbian/config +++ b/src/modules/armbian/config @@ -1,5 +1,18 @@ -#!/bin/bash +#!/usr/bin/env bash +# Shebang for better file detection +#### MainsailOS Specific Tweaks for armbian images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + # shellcheck disable=all -[ -n "$ARMBIAN_DEPS" ] || ARMBIAN_DEPS="armbian-config avahi-daemon iptables \ +[[ -n "$ARMBIAN_DEPS" ]] || ARMBIAN_DEPS="armbian-config avahi-daemon iptables \ bash-completion" +[[ -n "$ARMBIAN_CONFIG_TXT_FILE" ]] || ARMBIAN_CONFIG_TXT_FILE="/boot/armbianEnv.txt" +[[ -n "$ARMBIAN_CONFIG_BAK_FILE" ]] || ARMBIAN_CONFIG_BAK_FILE="/boot/armbianEnv.txt.backup" +[[ -n "$ARMBIAN_MODULES_FILE" ]] || ARMBIAN_MODULES_FILE="/etc/modules" diff --git a/src/modules/armbian/end_chroot_script b/src/modules/armbian/end_chroot_script index 04d93f693..21a50cc6f 100644 --- a/src/modules/armbian/end_chroot_script +++ b/src/modules/armbian/end_chroot_script @@ -1,31 +1,49 @@ #!/usr/bin/env bash -# MainsailOS Specific Tweaks for armbian images -# written by Stephan Wendel aka KwadFan -# -# GPL V3 -######## +#### MainsailOS Specific Tweaks for armbian images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### -## functions +# shellcheck enable=require-variable-braces +# Source error handling, leave this in place +set -Ee + +# Source CustomPIOS common.sh +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + +## Helper functions gen_root_pw() { tr -dc "[:alnum:]" < /dev/urandom | head -c 50 } -# Clean up -# Remove autologin and lock root account -if [ -f "/etc/systemd/system/getty@.service.d/override.conf" ]; then +## Clean up +## Step 1: Remove autologin and lock root account +if [[ -f "/etc/systemd/system/getty@.service.d/override.conf" ]]; then rm -f /etc/systemd/system/getty@.service.d/override.conf fi +## END -# Disable autologin on serial console -if [ -f "/etc/systemd/system/serial-getty@.service.d/override.conf" ]; then +## Step 2: Disable autologin on serial console +if [[ -f "/etc/systemd/system/serial-getty@.service.d/override.conf" ]]; then sed -i 's/--autologin root //' /etc/systemd/system/serial-getty@.service.d/override.conf fi +## END -# Generate random root passwd -yes "$(gen_root_pw)" | passwd root +## Step 3: Delete root passwd +### Deleting root passwd doesn't let you unlock the account +sudo passwd -d root +## END -# lock root account -sudo -u "${BASE_USER}" passwd -l root +## Step 4: Lock root account +sudo passwd -l root +## END -# Remove passwdless sudo +## Step 5: Remove passwdless sudo sed -i '/'"${BASE_USER}"' ALL=(ALL:ALL) NOPASSWD:ALL/d' /etc/sudoers +## END diff --git a/src/modules/armbian/filesystem/root/etc/udev/rules.d/97-gpio.rules b/src/modules/armbian/filesystem/root/etc/udev/rules.d/97-gpio.rules new file mode 100644 index 000000000..a1adb0b51 --- /dev/null +++ b/src/modules/armbian/filesystem/root/etc/udev/rules.d/97-gpio.rules @@ -0,0 +1 @@ +SUBSYSTEM=="gpio", KERNEL=="gpiochip[0-4]", GROUP="gpio", MODE="0660" diff --git a/src/modules/armbian/filesystem/root/etc/update-motd.d/10-mainsailos b/src/modules/armbian/filesystem/root/etc/update-motd.d/10-mainsailos index 5c976f3c0..127314f74 100755 --- a/src/modules/armbian/filesystem/root/etc/update-motd.d/10-mainsailos +++ b/src/modules/armbian/filesystem/root/etc/update-motd.d/10-mainsailos @@ -23,7 +23,6 @@ if [[ -f /etc/armbian-distribution-status ]]; then [[ -f /etc/lsb-release ]] && DISTRIBUTION_CODENAME=$(grep CODENAME /etc/lsb-release | cut -d"=" -f2) [[ -z "${DISTRIBUTION_CODENAME}" && -f /etc/os-release ]] && DISTRIBUTION_CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d"=" -f2) [[ -z "${DISTRIBUTION_CODENAME}" && -x /usr/bin/lsb_release ]] && DISTRIBUTION_CODENAME=$(/usr/bin/lsb_release -c | cut -d":" -f2 | tr -d "\t") - DISTRIBUTION_STATUS=$(grep "${DISTRIBUTION_CODENAME}" /etc/armbian-distribution-status | cut -d"=" -f2) fi [[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd @@ -44,23 +43,3 @@ echo -e "Version $(cut -d ' ' -f3 /etc/mainsailos-release), based on \ \e[34mArmbian ${VERSION} ${DISTRIBUTION_CODENAME^}\e[0m $([[ ${BRANCH} == edge ]])" echo -e "Running on \e[34m$(echo "${BOARD_NAME}" | sed 's/Orange Pi/OPi/' | \ sed 's/NanoPi/NPi/' | sed 's/Banana Pi/BPi/')\e[0m with \e[34mLinux ${KERNELID}\e[0m\n" - -# displaying status warnings - -if [[ "${IMAGE_TYPE}" != "stable" ]]; then - [[ "${IMAGE_TYPE}" == "user-built" ]] && UNSUPPORTED_TEXT="built from trunk" - [[ "${IMAGE_TYPE}" == "nightly" ]] && UNSUPPORTED_TEXT="untested automated build" -else - [[ "${BOARD_TYPE}" == "csc" || "${BOARD_TYPE}" == "tvb" ]] && UNSUPPORTED_TEXT="community creations" - [[ "${BOARD_TYPE}" == "wip" ]] && UNSUPPORTED_TEXT="work in progress" - [[ "${BOARD_TYPE}" == "eos" ]] && UNSUPPORTED_TEXT="end of life" -fi - -if [[ -n ${DISTRIBUTION_STATUS} && ${DISTRIBUTION_STATUS} != supported ]]; then - [[ -n ${UNSUPPORTED_TEXT} ]] && UNSUPPORTED_TEXT+=" & " - UNSUPPORTED_TEXT+="unsupported (${DISTRIBUTION_CODENAME}) userspace!" -fi - -if [[ -n ${UNSUPPORTED_TEXT} ]]; then - echo -e "\e[0;91mNo end-user support: \x1B[0m${UNSUPPORTED_TEXT}\n" -fi diff --git a/src/modules/armbian/start_chroot_script b/src/modules/armbian/start_chroot_script index 0a2aa965b..8a8235846 100644 --- a/src/modules/armbian/start_chroot_script +++ b/src/modules/armbian/start_chroot_script @@ -1,26 +1,32 @@ #!/usr/bin/env bash -# MainsailOS Specific Tweaks for armbian images -# written by Stephan Wendel aka KwadFan -# -# GPL V3 -######## +#### MainsailOS Specific Tweaks for armbian images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### +# shellcheck enable=require-variable-braces # Source error handling, leave this in place -set -xe +set -Ee # Source CustomPIOS common.sh # shellcheck disable=SC1091 source /common.sh install_cleanup_trap -# Install armbian specific packages -apt update -# shellcheck disable=SC2086 -check_install_pkgs ${ARMBIAN_DEPS} - -# passwordless sudo during install -# Will be removed in cleanup -echo "${BASE_USER} ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers +### Helper func +is_board_type() { + local board releasefile + board="" + releasefile="/etc/armbian-release" + if [[ -f "${releasefile}" ]]; then + board="$(grep "BOARD=" "${releasefile}" | cut -d'=' -f2)" + fi + echo "${board}" +} # Base User groups # Shameless "stolen" from @@ -33,26 +39,77 @@ if_group_exists_run() { fi } -# set groups +# passwordless sudo during install +# Will be removed in cleanup +echo "${BASE_USER} ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers + +## Step 1: Install armbian specific packages +apt update +# shellcheck disable=SC2086 +check_install_pkgs ${ARMBIAN_DEPS} +## END Step 1 + + +## Step 2: Manage groups +### Substep 1: Create group for gpio usage +sudo groupadd gpio +### END Substep 1 + +### Substep 2: Set default groups if_group_exists_run i2c usermod -aG i2c "${BASE_USER}" -usermod -aG video,audio,plugdev,games,netdev,sudo "${BASE_USER}" +usermod -aG video,audio,plugdev,games,netdev,sudo,systemd-journal,gpio "${BASE_USER}" +### END Substep 2 +## END Step 2 -# Patch sshd_config +## Step 3: patch sshd_config sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sed -i 's/^X11Forwarding/#X11Forwarding/' /etc/ssh/sshd_config sed -i 's/^#MaxAuthTries 6/MaxAuthTries 3/' /etc/ssh/sshd_config +## END Step 3 -# Try patching first login in build stage -if [ -f "/root/.not_logged_in_yet" ]; then +## Step 4: Try patching first login in build stage +if [[ -f "/root/.not_logged_in_yet" ]]; then rm -f /root/.not_logged_in_yet fi +## END Step 4 -# Move armbian-release to display mainsailos-release -mv /etc/armbian-release /etc/armbian-release-info.txt - -# update motd +## Step 5: Patch dynamic motd +echo_green "Patch dynamic motd ..." unpack /filesystem/root / chmod +x /etc/update-motd.d/* -if [ -f "/etc/default/armbian-motd" ]; then +if [[ -f "/etc/default/armbian-motd" ]]; then sed -i 's/MOTD_DISABLE=""/MOTD_DISABLE="header"/' /etc/default/armbian-motd fi +## END Step 5 + +## Step 6: Enable SPI interface by default +echo_green "Enable SPI interface on Orange Pi SBC's ..." + +### Substep 1: Copy default config to backup file +cp "${ARMBIAN_CONFIG_TXT_FILE}" "${ARMBIAN_CONFIG_BAK_FILE}" +### END Substep 1 + +### Substep 2: Enable SPI in armbianEnv.txt depending on device +#### OrangePi 3 LTS +if [[ "$(is_board_type)" == "orangepi3-lts" ]]; then + echo "overlays=spi-spidev1" >> "${ARMBIAN_CONFIG_TXT_FILE}" +fi + +#### OrangePi 4 LTS +if [[ "$(is_board_type)" == "orangepi4-lts" ]]; then + echo "overlays=spi-spidev" >> "${ARMBIAN_CONFIG_TXT_FILE}" + echo "param_spidev_spi_bus=1" >> "${ARMBIAN_CONFIG_TXT_FILE}" +fi +### END Substep 2: + +### Substep 3: add spi-dev module to /etc/modules +echo "spi-dev" >> "${ARMBIAN_MODULES_FILE}" +### END Substep 3 + +echo_green "Enable SPI interface on Orange Pi SBC's ... DONE!" +## END Step 6 + +## Step 7: Remove unattended-upgrades +echo_green "Remove 'unattended-upgrades' service ..." +sudo apt-get remove --purge --yes unattended-upgrades +## END Step 7 diff --git a/src/modules/armbian_net/config b/src/modules/armbian_net/config new file mode 100644 index 000000000..d2b005768 --- /dev/null +++ b/src/modules/armbian_net/config @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Shebang for better file detection +#### MainsailOS network configurator for armbian images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck disable=all + +[[ -n "$ARMBIAN_NET_FIRSTRUN_FILE" ]] || ARMBIAN_NET_FIRSTRUN_FILE="/boot/armbian_first_run.txt.template" +[[ -n "$ARMBIAN_NET_FIRSTRUN_SCRIPT" ]] || ARMBIAN_NET_FIRSTRUN_SCRIPT="/usr/lib/armbian/armbian-firstrun-config" +[[ -n "$ARMBIAN_NET_NC_PATH" ]] || ARMBIAN_NET_NC_PATH="/usr/local/bin/network-configurator" +[[ -n "$ARMBIAN_NET_DEPS" ]] || ARMBIAN_NET_DEPS="net-tools" diff --git a/src/modules/armbian_net/filesystem/root/boot/network_config.txt.template b/src/modules/armbian_net/filesystem/root/boot/network_config.txt.template new file mode 100644 index 000000000..1ee72d296 --- /dev/null +++ b/src/modules/armbian_net/filesystem/root/boot/network_config.txt.template @@ -0,0 +1,49 @@ +#----------------------------------------------------------------- +# +# MainsailOS (armbian edition) Network Configuration +# Set optional end user configuration +# - Rename this file from /boot/network_config.txt.template to /boot/network_config.txt +# - Settings below will be applied every time you reboot your machine. +# Be aware, old configurations will be deleted! +# +# This file is based on work of the armbian developer team +# https://github.com/armbian/build/blob/master/packages/bsp/armbian_first_run.txt.template +#----------------------------------------------------------------- + +#----------------------------------------------------------------- +# General: +# 1 = delete this file, after first run setup is completed. + +NC_general_delete_this_file_after_completion=1 + +#----------------------------------------------------------------- +#Networking: +# Change default network settings +# Set to 1 to apply any network related settings below + +NC_net_change_defaults=0 + +# Enable WiFi or Ethernet. +# NB: If both are enabled, WiFi will take priority and Ethernet will be disabled. + +NC_net_ethernet_enabled=1 +NC_net_wifi_enabled=0 + +#Enter your WiFi creds +# SECURITY WARN: Your wifi keys will be stored in plaintext, no encryption. + +NC_net_wifi_ssid='MySSID' +NC_net_wifi_key='MyWiFiKEY' + +# Country code to enable power ratings and channels for your country. eg: GB US DE | https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + +NC_net_wifi_countrycode='GB' + +# If you want to use a static ip, set it here + +NC_net_use_static=0 +NC_net_static_ip='192.168.0.100' +NC_net_static_mask='255.255.255.0' +NC_net_static_gateway='192.168.0.1' +NC_net_static_dns='8.8.8.8 8.8.4.4' # Two entries max, seperated by a space. +#----------------------------------------------------------------- diff --git a/src/modules/armbian_net/filesystem/root/etc/systemd/system/network-configurator.service b/src/modules/armbian_net/filesystem/root/etc/systemd/system/network-configurator.service new file mode 100644 index 000000000..6568ee6d4 --- /dev/null +++ b/src/modules/armbian_net/filesystem/root/etc/systemd/system/network-configurator.service @@ -0,0 +1,20 @@ +# MainsailOS network-configurator +# This service will run in parallel with other services +# This is based on +# https://github.com/armbian/build/blob/master/packages/bsp/common/lib/systemd/system/armbian-firstrun-config.service + + +[Unit] +Description=MainsailOS network configurator +Wants=network-online.target +After=network.target network-online.target +ConditionPathExists=/boot/network_config.txt + +[Service] +Type=idle +RemainAfterExit=yes +ExecStart=/usr/local/bin/network-configurator +TimeoutStartSec=2min + +[Install] +WantedBy=multi-user.target diff --git a/src/modules/armbian_net/start_chroot_script b/src/modules/armbian_net/start_chroot_script new file mode 100644 index 000000000..7a3a152f0 --- /dev/null +++ b/src/modules/armbian_net/start_chroot_script @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +#### MainsailOS network configurator for armbian images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck enable=require-variable-braces + +# Description: +# This file installs a service based on armbians armbian_firstrun_config +# The original work is done by the armbian developer's team +# sources of files can be found here: https://github.com/armbian/build + +# Source error handling, leave this in place +set -Ee + +# Source CustomPIOS common.sh +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + + +## Step 1: Install files +unpack filesystem/root / root +## END + +## Step 1.1: Install Depedencies +### Needed to patch 'network_configurator' +# shellcheck disable=SC2086 +check_install_pkgs ${ARMBIAN_NET_DEPS} + +## Step 2: remove original template +if [[ -f "${ARMBIAN_NET_FIRSTRUN_FILE}" ]]; then + sudo rm -rf "${ARMBIAN_NET_FIRSTRUN_FILE}" +fi +## END + +## Step 3: Disable first run service +systemctl_if_exists disable armbian-firstrun-config.service +## END + +## Step 4: Copy original script to /usr/local/bin/network-configurator +if [[ -f "${ARMBIAN_NET_FIRSTRUN_SCRIPT}" ]]; then + sudo cp -p "${ARMBIAN_NET_FIRSTRUN_SCRIPT}" "${ARMBIAN_NET_NC_PATH}" +fi +## END + +## Step 5: patch /usr/local/bin/network-configurator +if [[ -f "${ARMBIAN_NET_NC_PATH}" ]]; then + ### Substep 1: replace any amrbian_first_run.txt with network_config.txt + sed -i 's|armbian_first_run.txt|network_config.txt|g' "${ARMBIAN_NET_NC_PATH}" + ### Substep 2: replace any FR* Variable name with NC* + sed -i 's|FR|NC|g' "${ARMBIAN_NET_NC_PATH}" + ### Supstep 3: Rename function + sed -i 's|do_firstrun_automated_user_configuration|do_network_configuration|g' "${ARMBIAN_NET_NC_PATH}" + ### Substep 4: Add a patch note + sed -i '8 i \\n\# This is a patched version of armbian-firstrun-config for MainsailOS' "${ARMBIAN_NET_NC_PATH}" + sed -i '10 i # Original located at /usr/lib/armbian/armbian-firstrun-config' "${ARMBIAN_NET_NC_PATH}" + sed -i '11 i # Changes made by https:\/\/github.com/mainsail-crew' "${ARMBIAN_NET_NC_PATH}" +fi +## END + +## Step 6: Enable systemd service +systemctl_if_exists enable network-configurator.service +## END diff --git a/src/modules/crowsnest/config b/src/modules/crowsnest/config index ba0afbf64..85b096a1e 100644 --- a/src/modules/crowsnest/config +++ b/src/modules/crowsnest/config @@ -2,7 +2,7 @@ #### crowsnest - A webcam Service for multiple Cams and Stream Services. #### #### Written by Stephan Wendel aka KwadFan -#### Copyright 2021 - 2022 +#### Copyright 2021 - till today #### https://github.com/mainsail-crew/crowsnest #### #### This File is distributed under GPLv3 @@ -18,7 +18,6 @@ [[ -n "$CROWSNEST_CONFIG_PATH" ]] || CROWSNEST_CONFIG_PATH="/home/${BASE_USER}/printer_data/config" [[ -n "$CROWSNEST_LOG_PATH" ]] || CROWSNEST_LOG_PATH="/home/${BASE_USER}/printer_data/logs" [[ -n "$CROWSNEST_ENV_PATH" ]] || CROWSNEST_ENV_PATH="/home/${BASE_USER}/printer_data/systemd" -[[ -n "$CROWSNEST_RASPICAMFIX" ]] || CROWSNEST_RASPICAMFIX="1" [[ -n "$CROWSNEST_ADD_CROWSNEST_MOONRAKER" ]] || CROWSNEST_ADD_CROWSNEST_MOONRAKER="1" [[ -n "$CROWSNEST_MOONRAKER_CONF_PATH" ]] || CROWSNEST_MOONRAKER_CONF_PATH="/home/${BASE_USER}/printer_data/config/moonraker.conf" @@ -27,6 +26,10 @@ [[ -n "$CROWSNEST_USTREAMER_REPO_SHIP" ]] || CROWSNEST_USTREAMER_REPO_SHIP="https://github.com/pikvm/ustreamer.git" [[ -n "$CROWSNEST_USTREAMER_REPO_BRANCH" ]] || CROWSNEST_USTREAMER_REPO_BRANCH="master" +# camera-streamer +[[ -n "$CROWSNEST_CAMERA_STREAMER_REPO_SHIP" ]] || CROWSNEST_CAMERA_STREAMER_REPO_SHIP="https://github.com/ayufan/camera-streamer.git" +[[ -n "$CROWSNEST_CAMERA_STREAMER_REPO_BRANCH" ]] || CROWSNEST_CAMERA_STREAMER_REPO_BRANCH="master" + ########################################################################### ### DO NOT EDIT BELOW THIS LINE, UNLESS YOU KNOW EXACTLY WHAT HAPPENDS! ### ########################################################################### diff --git a/src/modules/crowsnest/start_chroot_script b/src/modules/crowsnest/start_chroot_script index 9631f7e81..7da29599c 100644 --- a/src/modules/crowsnest/start_chroot_script +++ b/src/modules/crowsnest/start_chroot_script @@ -20,7 +20,25 @@ install_cleanup_trap # Module only Variables CN_BUILD_PACKAGE_FILE="/tmp/cn_packages.lst" -CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/install.sh" + +# Helper Func +is_raspbian() { + if [[ -f /boot/config.txt ]] && [[ -f /etc/rpi-issue ]]; then + echo "1" + else + echo "0" + fi +} + +get_pkglist() { + if [[ "$(is_raspbian)" = "1" ]]; then + CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/libs/pkglist-rpi.sh" + fi + if [[ "$(is_raspbian)" = "0" ]]; then + CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/libs/pkglist-generic.sh" + fi +} + echo_green "Installing crowsnest ..." @@ -38,6 +56,7 @@ gitclone CROWSNEST_REPO crowsnest ## Step 3: grep PKGLIST from install.sh for dependencies echo_green "Generating packages file ..." +get_pkglist grep "PKGLIST=" "${CN_BUILD_INSTALL_SH}" >> "${CN_BUILD_PACKAGE_FILE}" ## Step 4: Rename PKGLIST to Module usable Var diff --git a/src/modules/is_req_preinstall/config b/src/modules/is_req_preinstall/config index 1ea69c1bb..eca97bb2a 100644 --- a/src/modules/is_req_preinstall/config +++ b/src/modules/is_req_preinstall/config @@ -4,4 +4,4 @@ [ -n "$IS_REQ_PREINSTALL_DEPS" ] || IS_REQ_PREINSTALL_DEPS="python3-numpy python3-matplotlib \ libatlas3-base libatlas-base-dev libgfortran5" [ -n "$IS_REQ_PREINSTALL_PIP" ] || IS_REQ_PREINSTALL_PIP="numpy<=1.23.4" -[ -n "$IS_REQ_PREINSTALL_CFG_FILE" ] || IS_REQ_PREINSTALL_CFG_FILE="/boot/config.txt" + diff --git a/src/modules/klipper/config b/src/modules/klipper/config index 8bf45fb9f..ac6a5acb4 100644 --- a/src/modules/klipper/config +++ b/src/modules/klipper/config @@ -21,7 +21,7 @@ [ -n "$KLIPPER_DEPS" ] || KLIPPER_DEPS="git virtualenv python3-dev \ python3-matplotlib libffi-dev build-essential libncurses-dev libusb-dev \ avrdude gcc-avr binutils-avr avr-libc stm32flash dfu-util libnewlib-arm-none-eabi \ -gcc-arm-none-eabi binutils-arm-none-eabi libusb-1.0-0 libusb-1.0-0-dev" +gcc-arm-none-eabi binutils-arm-none-eabi libusb-1.0-0 libusb-1.0-0-dev pkg-config" [ -n "$KLIPPER_USER_GROUPS" ] || KLIPPER_USER_GROUPS="tty,dialout" diff --git a/src/modules/mainsailos/start_chroot_script b/src/modules/mainsailos/start_chroot_script index 4ef5114d1..97e7d3494 100644 --- a/src/modules/mainsailos/start_chroot_script +++ b/src/modules/mainsailos/start_chroot_script @@ -22,7 +22,7 @@ fi source /common.sh install_cleanup_trap -# Create mainsailos release file +## Step 1: Create mainsailos release file if [ -f "/etc/mainsailos_version" ]; then sudo rm -f /etc/mainsailos_version fi @@ -31,8 +31,30 @@ function get_parent { } echo "${DIST_NAME} release ${DIST_VERSION} ($(get_parent))" > /etc/"${DIST_NAME,,}"-release +## END Step 1 -### Install CANBoot Dependency -apt update +## Step 2: Fake release file +### NOTE: Turns out that the 'distro' python package, +### which is used by moonraker, uses the first file after sorting. +### Therefore we need a hacky solution, because armbian relies, on upgrades +### on the original armbian-release file. +### To get around that, we simple symlink mainsailos-release to +### aaaa-release, which is directly read by moonraker. +### Substep 1: Do for armbian releases +if [[ -f "/etc/armbian-release" ]]; then + echo_green "Apply release file workaround (armbian based image) ..." + ln -s /etc/"${DIST_NAME,,}"-release /etc/aaaa-release +fi +### END Substep 1 +### Substep 2: Apply same for OrangePI bsed Images +if [[ -f "/etc/orangepi-release" ]]; then + echo_green "Apply release file workaround (orangepi based image) ..." + ln -s /etc/"${DIST_NAME,,}"-release /etc/aaaa-release +fi +## END Step 2 + +## Step 3: Install CANBoot Dependency +apt-get update --allow-releaseinfo-change # shellcheck disable=SC2086 check_install_pkgs ${MAINSAILOS_DEPS} +## END Step 3 diff --git a/src/modules/net/config b/src/modules/net/config index 3b5df77d8..1cf106409 100755 --- a/src/modules/net/config +++ b/src/modules/net/config @@ -2,7 +2,7 @@ # shellcheck disable=all # Use disable power save for wifi module -[ -n "$NETWORK_DISABLE_PWRSAVE" ] || NETWORK_DISABLE_PWRSAVE=yes +[ -n "$NET_DISABLE_PWRSAVE" ] || NET_DISABLE_PWRSAVE=yes # Type of power save rclocal/service/udev # rclocal - backwards compatibility, runs via rc.local @@ -10,4 +10,4 @@ # on reboots # udev - creates a udev rules that should affect all wifi devices. -[ -n "$NETWORK_PWRSAVE_TYPE" ] || NETWORK_PWRSAVE_TYPE=udev +[ -n "$NET_PWRSAVE_TYPE" ] || NET_PWRSAVE_TYPE=udev diff --git a/src/modules/net/start_chroot_script b/src/modules/net/start_chroot_script index c9982e04b..762816c31 100755 --- a/src/modules/net/start_chroot_script +++ b/src/modules/net/start_chroot_script @@ -9,8 +9,7 @@ # Last modification: August/2022 # ######## -set -x -set -e +set -Ee export LC_ALL=C @@ -56,13 +55,13 @@ echo '/sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j T echo 'exit 0' >> /etc/rc.local # Install powersave option -if [ "$NETWORK_DISABLE_PWRSAVE" == "yes" ]; then +if [ "$NET_DISABLE_PWRSAVE" == "yes" ]; then # Copy pwrsave script unpack filesystem/usr/local/bin /usr/local/bin root # Use rc.local - if [ "$NETWORK_PWRSAVE_TYPE" == "rclocal" ]; then + if [ "$NET_PWRSAVE_TYPE" == "rclocal" ]; then echo_green "Modifying /etc/rc.local ..." sed -i 's@exit 0@@' /etc/rc.local (echo "# Disable WiFi Power Management"; \ @@ -70,18 +69,18 @@ if [ "$NETWORK_DISABLE_PWRSAVE" == "yes" ]; then echo "/usr/local/bin/pwrsave off"; echo "exit 0") >> /etc/rc.local fi # Use service - if [ "$NETWORK_PWRSAVE_TYPE" == "service" ]; then + if [ "$NET_PWRSAVE_TYPE" == "service" ]; then echo_green "Installing disable-wifi-pwr-mgmt service ..." unpack filesystem/etc/systemd/system /etc/systemd/system root systemctl_if_exists enable disable-wifi-pwr-mgmt.service fi # Use udev rule - if [ "$NETWORK_PWRSAVE_TYPE" == "udev" ]; then + if [ "$NET_PWRSAVE_TYPE" == "udev" ]; then echo_green "Installing WiFi Power Management udev rule ..." unpack filesystem/etc/udev/rules.d /etc/udev/rules.d root fi # strip out unneeded script, depending on choose - if [ "$NETWORK_PWRSAVE_TYPE" != "udev" ]; then + if [ "$NET_PWRSAVE_TYPE" != "udev" ]; then rm -f /usr/local/bin/pwrsave-udev else rm -f /usr/local/bin/pwrsave diff --git a/src/modules/orangepi/config b/src/modules/orangepi/config new file mode 100644 index 000000000..dab971308 --- /dev/null +++ b/src/modules/orangepi/config @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Shebang for better file detection +#### MainsailOS Specific Tweaks for orangepi images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck disable=all + +## General module configuration +[[ -n "$ORANGEPI_DEPS" ]] || ORANGEPI_DEPS="avahi-daemon iptables unzip \ +bash-completion" +[[ -n "$ORANGEPI_CONFIG_TXT_FILE" ]] || ORANGEPI_CONFIG_TXT_FILE="/boot/orangepiEnv.txt" +[[ -n "$ORANGEPI_CONFIG_BAK_FILE" ]] || ORANGEPI_CONFIG_BAK_FILE="/boot/orangepiEnv.txt.backup" +[[ -n "$ORANGEPI_MODULES_FILE" ]] || ORANGEPI_MODULES_FILE="/etc/modules" + +## Orange Pi Zero 2 additional configuration +[[ -n "$ORANGEPI_ENABLE_OVERLAYS_OPIZ2" ]] || ORANGEPI_ENABLE_OVERLAYS_OPIZ2="true" +[[ -n "$ORANGEPI_ADD_OVERLAYS_OPIZ2" ]] || ORANGEPI_ADD_OVERLAYS_OPIZ2="i2c3 uart5 spi-spidev" +[[ -n "$ORANGEPI_ADD_OVERLAYS_OPIZ2_PARAMS" ]] || ORANGEPI_ADD_OVERLAYS_OPIZ2_PARAMS="param_spidev_spi_bus=1 param_spidev_spi_cs=1" + +## Disable Autologin on gettys +[[ -n "$ORANGEPI_DISABLE_GETTY_AUTOLOGIN" ]] || ORANGEPI_DISABLE_GETTY_AUTOLOGIN="1" + +### EXPERIMENTAL: Install orangepi-config from source git repo +[[ -n "$ORANGEPI_INSTALL_OPI_CONFIG" ]] || ORANGEPI_INSTALL_OPI_CONFIG="true" +[[ -n "$ORANGEPI_OPI_CONFIG_URL" ]] || ORANGEPI_OPI_CONFIG_URL="https://raw.githubusercontent.com/orangepi-xunlong/orangepi-build/next/external/cache/sources/orangepi-config/" +[[ -n "$ORANGEPI_OPI_CONFIG_FILES" ]] || ORANGEPI_OPI_CONFIG_FILES="debian-config debian-config-functions debian-config-functions-network debian-config-jobs debian-config-submenu" diff --git a/src/modules/orangepi/end_chroot_script b/src/modules/orangepi/end_chroot_script new file mode 100644 index 000000000..8ae4e7609 --- /dev/null +++ b/src/modules/orangepi/end_chroot_script @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +#### MainsailOS Specific Tweaks for orangepi images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck enable=require-variable-braces +# Source error handling, leave this in place +set -Ee + +# Source CustomPIOS common.sh +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + +## Clean up +## Step 1: Delete root passwd (disables root login) +### Deleting root passwd doesn't let you unlock the account +sudo passwd -d root +## END Step 1 + +## Step 2: Lock root account (disables root login) +sudo passwd -l root +## END Step 2 + +## Step 3: Remove passwdless sudo +sed -i '/'"${BASE_USER}"' ALL=(ALL:ALL) NOPASSWD:ALL/d' /etc/sudoers +## END Step 3 diff --git a/src/modules/orangepi/filesystem/root/etc/udev/rules.d/97-gpio.rules b/src/modules/orangepi/filesystem/root/etc/udev/rules.d/97-gpio.rules new file mode 100644 index 000000000..a1adb0b51 --- /dev/null +++ b/src/modules/orangepi/filesystem/root/etc/udev/rules.d/97-gpio.rules @@ -0,0 +1 @@ +SUBSYSTEM=="gpio", KERNEL=="gpiochip[0-4]", GROUP="gpio", MODE="0660" diff --git a/src/modules/orangepi/filesystem/root/etc/update-motd.d/10-mainsailos b/src/modules/orangepi/filesystem/root/etc/update-motd.d/10-mainsailos new file mode 100755 index 000000000..6d062fcd0 --- /dev/null +++ b/src/modules/orangepi/filesystem/root/etc/update-motd.d/10-mainsailos @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Based on: +# https://github.com/armbian/build/blob/master/packages/bsp/common/etc/update-motd.d/10-armbian-header + +# Copyright (c) Authors: https://www.armbian.com/authors +# +# This file is licensed under the terms of the GNU General Public +# License version 2. This program is licensed "as is" without any +# warranty of any kind, whether express or implied. + +# Modified by Stephan Wendel aka KwadFan +# All changes made are public at +# https://github.com/mainsail-crew/MainsailOS + +# shellcheck enable=require-variable-braces + +# shellcheck disable=SC1091 +[[ -f /etc/orangepi-release-info.txt ]] && . /etc/orangepi-release-info.txt + +if [[ -f /etc/orangepi-distribution-status ]]; then + . /etc/orangepi-distribution-status + [[ -f /etc/lsb-release ]] && DISTRIBUTION_CODENAME=$(grep CODENAME /etc/lsb-release | cut -d"=" -f2) + [[ -z "${DISTRIBUTION_CODENAME}" && -f /etc/os-release ]] && DISTRIBUTION_CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d"=" -f2) + [[ -z "${DISTRIBUTION_CODENAME}" && -x /usr/bin/lsb_release ]] && DISTRIBUTION_CODENAME=$(/usr/bin/lsb_release -c | cut -d":" -f2 | tr -d "\t") +fi +[[ -f /etc/default/orangepi-motd ]] && . /etc/default/orangepi-motd + +for f in ${MOTD_DISABLE}; do + [[ "${f}" == "${THIS_SCRIPT}" ]] && exit 0 +done + + +KERNELID=$(uname -r) + +# Odroid N2 exception +ODROID_EXCEPTION="$(tr -d '\000' < /proc/device-tree/model | grep ODROID | grep Plus)" +[[ -f /proc/device-tree/model ]] && [[ -n "${ODROID_EXCEPTION}" ]] && BOARD_NAME+="+" + + +echo -e "\e[31m$(toilet -f big MainsailOS)\e[0m" +echo -e "Version $(cut -d ' ' -f3 /etc/mainsailos-release), based on \ +\e[34mOrange Pi OS ${VERSION} ${DISTRIBUTION_CODENAME^}\e[0m $([[ ${BRANCH} == edge ]])" +echo -e "Running on \e[34m$(echo "${BOARD_NAME}" | sed 's/Orange Pi/OPi/' | \ +sed 's/NanoPi/NPi/' | sed 's/Banana Pi/BPi/')\e[0m with \e[34mLinux ${KERNELID}\e[0m\n" diff --git a/src/modules/orangepi/start_chroot_script b/src/modules/orangepi/start_chroot_script new file mode 100644 index 000000000..7e5d05544 --- /dev/null +++ b/src/modules/orangepi/start_chroot_script @@ -0,0 +1,216 @@ +#!/usr/bin/env bash +#### MainsailOS Specific Tweaks for orangepi images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +#### NOTE: udev rules file is applied in Step 6! +#### This is based on https://github.com/Arksine/moonraker/issues/562 + + +# shellcheck enable=require-variable-braces +# Source error handling, leave this in place +set -Ee + +## Uncomment for deeper debugging +# set -x + +# Source CustomPIOS common.sh +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + +# Helper func +is_board_type() { + local board releasefile + board="" + releasefile="/etc/orangepi-release" + if [[ -f "${releasefile}" ]]; then + board="$(grep "BOARD=" "${releasefile}" | cut -d'=' -f2)" + fi + echo "${board}" +} + +get_gettyconf_dirs() { + find "${1}" -type d -name "*getty@*" +} + +# Base User groups +# Shameless "stolen" from +# https://github.com/guysoft/CustomPiOS/blob/devel/src/variants/armbian/pre_chroot_script + +if_group_exists_run() { + group=$1 + if grep -q "${group}" /etc/group; then + "${@:2}" + fi +} + +# passwordless sudo during install +# Will be removed in cleanup +echo "${BASE_USER} ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers + +## Step 1: Install armbian specific packages +apt update +# shellcheck disable=SC2086 +check_install_pkgs ${ORANGEPI_DEPS} +## END Step 1 + +## Step 2: Manage groups and default user + +### Substep 1: Create group for gpio usage +sudo groupadd gpio +### END Substep 1 + +### Substep 2: Set default groups +if_group_exists_run i2c usermod -aG i2c "${BASE_USER}" +usermod -aG video,audio,plugdev,games,netdev,sudo,systemd-journal,gpio "${BASE_USER}" +### END Substep 2 + +### Substep 3: Remove user "orangepi" +sudo userdel orangepi +sudo rm -rf /home/orangepi +### END Substep 3 +## END Step 2 + +## Step 3: Patch sshd_config (Limit retrys, disable root login via ssh) +sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config +sed -i 's/^X11Forwarding/#X11Forwarding/' /etc/ssh/sshd_config +sed -i 's/^#MaxAuthTries 6/MaxAuthTries 3/' /etc/ssh/sshd_config +## END Step 3 + +## Step 4: Try patching first login in build stage +if [ -f "/root/.not_logged_in_yet" ]; then + rm -f /root/.not_logged_in_yet +fi +## END Step 4 + +## Step 5: Patch dynamic motd +echo_green "Patch dynamic motd ..." +unpack /filesystem/root / +chmod +x /etc/update-motd.d/* +if [ -f "/etc/default/orangepi-motd" ]; then + sed -i 's/^MOTD_DISABLE=""/MOTD_DISABLE="header tips"/' /etc/default/orangepi-motd +fi +## END Step 5 + +## Step 6: Enable SPI interface by default +echo_green "Enable interfaces on Orange Pi SBC's ..." + +### Substep 1: Copy default config to backup file +cp "${ORANGEPI_CONFIG_TXT_FILE}" "${ORANGEPI_CONFIG_BAK_FILE}" +### END Substep 1 + +### Substep 2: Enable SPI in armbianEnv.txt depending on device + +#### Orangepi Zero2 +if [[ "$(is_board_type)" == "orangepizero2" ]] && +[[ "${ORANGEPI_ENABLE_OVERLAYS_OPIZ2}" == "true" ]]; then + + if [[ -n "${ORANGEPI_ADD_OVERLAYS_OPIZ2}" ]]; then + echo_green "Adding overlays '${ORANGEPI_ADD_OVERLAYS_OPIZ2}' to ${ORANGEPI_CONFIG_TXT_FILE} ..." + echo "overlays=${ORANGEPI_ADD_OVERLAYS_OPIZ2}" >> "${ORANGEPI_CONFIG_TXT_FILE}" + fi + + if [[ -n "${ORANGEPI_ADD_OVERLAYS_OPIZ2_PARAMS}" ]]; then + for param in ${ORANGEPI_ADD_OVERLAYS_OPIZ2_PARAMS}; do + echo_green "Add ${param} to ${ORANGEPI_CONFIG_TXT_FILE} ..." + echo "${param}" >> "${ORANGEPI_CONFIG_TXT_FILE}" + done + fi +fi +#### END + +### END Substep 2 + +# Substep 3: add spi-dev module to /etc/modules +echo "spi-dev" >> "${ORANGEPI_MODULES_FILE}" + +echo_green "Enable SPI interface on Orange Pi SBC's ... DONE!" +## END Step 6 + +## Step 7: Install orangepi-config from git source repository +if [[ "${ORANGEPI_INSTALL_OPI_CONFIG}" == "true" ]]; then + echo_green "Install orangepi-config from git sources ..." + + ### Substep 1: Create temporary dir 'src/workspace/opi-config-src' + ORANGEPI_OPI_CONFIG_TEMP="src/workspace/opi-config-src" + if [[ ! -d "${ORANGEPI_OPI_CONFIG_TEMP}" ]]; then + mkdir -p "${ORANGEPI_OPI_CONFIG_TEMP}" + fi + ### END Substep 1 + + ### Substep 2: Create array from ORANGEPI_OPI_CONFIG_FILES + for name in ${ORANGEPI_OPI_CONFIG_FILES}; do + ORANGEPI_OPI_CONFIG_FILES_ARR+=("${name}") + done + ### END Substep 2 + + ### Substep 3: curl sources from git repo to src/workspace/opi-config + for file in "${ORANGEPI_OPI_CONFIG_FILES_ARR[@]}"; do + curl -sL "${ORANGEPI_OPI_CONFIG_URL}"/"${file}" --output "${ORANGEPI_OPI_CONFIG_TEMP}"/"${file}" + done + ### END Substep 3 + + ### Substep 4: Create subdir 'orangepi-config' in /usr/lib/ + if [[ ! -d "/usr/lib/orangepi-config" ]]; then + mkdir -p "/usr/lib/orangepi-config" + fi + ### END Substep 4 + + ### Substep 5: Copy main script to /usr/sbin (orangepi-config) + cp -f "src/workspace/opi-config-src/${ORANGEPI_OPI_CONFIG_FILES_ARR[*]:0:1}" "/usr/sbin/orangepi-config" + ### END Substep 5 + + ### Substep 6: Add executable flag + if [[ ! -x "/usr/sbin/orangepi-config" ]]; then + chmod +x "/usr/sbin/orangepi-config" + fi + ### END Substep 6 + + ### Substep 7: Link main script to /usr/bin/orangepi-config + ln -sf "/usr/sbin/orangepi-config" "/usr/bin/orangepi-config" + ### END Substep 7 + + ### Substep 7: Install script librarys to /usr/lib/orangepi-config + for i in "${ORANGEPI_OPI_CONFIG_FILES_ARR[@]:1}"; do + stripped="${i##debian-config-}" + cp -f "${ORANGEPI_OPI_CONFIG_TEMP}/${i}" "/usr/lib/orangepi-config/${stripped}.sh" + done + ### END Substep 7 + +else + echo_red "WARN: orangepi-config install not configured ... [SKIPPED]" +fi +## END Step 7 + +## Step 8: Fix tty and serial-tty autologin +### NOTE: Since OrangePI OS uses for its getty override.conf files +### the location of '/lib/systemd/system/[serial-]getty@.service.d' +### instead the appropriate location in etc, we have to fix that. +if [[ "${ORANGEPI_DISABLE_GETTY_AUTOLOGIN}" = "1" ]]; then + echo_green "Disable 'getty' autologin ..." + + ### Substep 1: copy '/lib/systemd/system/[serial-]getty@.service.d' + for dir in $(get_gettyconf_dirs /usr/lib/systemd/system); do + cp -R "${dir}" /etc/systemd/system + done + ### End Substep 1 + + ### Substep 2: Modify 'override.conf', delete autologin + for conf in $(get_gettyconf_dirs /etc/systemd/system); do + if [[ -f "${conf}/override.conf" ]]; then + echo_green "Found '${conf}/override.conf', trying to modify ..." + sed -i 's/--autologin orangepi //' "${conf}/override.conf" + else + echo_green "No '${conf}/override.conf' found, modifying skipped!" + fi + done + ### END Substep 2 + echo_green "Disable 'getty' autologin ... DONE!" +fi +## END Step 8 diff --git a/src/modules/orangepi_net/config b/src/modules/orangepi_net/config new file mode 100644 index 000000000..3bd31bb1f --- /dev/null +++ b/src/modules/orangepi_net/config @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Shebang for better file detection +#### MainsailOS network configurator for orange images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck disable=all + +[[ -n "$ORANGEPI_NET_FIRSTRUN_FILE" ]] || ORANGEPI_NET_FIRSTRUN_FILE="/boot/orangepi_first_run.txt.template" +[[ -n "$ORANGEPI_NET_FIRSTRUN_SCRIPT" ]] || ORANGEPI_NET_FIRSTRUN_SCRIPT="/usr/lib/orangepi/orangepi-firstrun-config" +[[ -n "$ORANGEPI_NET_NC_PATH" ]] || ORANGEPI_NET_NC_PATH="/usr/local/bin/network-configurator" diff --git a/src/modules/orangepi_net/filesystem/root/boot/network_config.txt.template b/src/modules/orangepi_net/filesystem/root/boot/network_config.txt.template new file mode 100644 index 000000000..f3173c054 --- /dev/null +++ b/src/modules/orangepi_net/filesystem/root/boot/network_config.txt.template @@ -0,0 +1,49 @@ +#----------------------------------------------------------------- +# +# MainsailOS (orangepi edition) Network Configuration +# Set optional end user configuration +# - Rename this file from /boot/network_config.txt.template to /boot/network_config.txt +# - Settings below will be applied every time you reboot your machine. +# Be aware, old configurations will be deleted! +# +# This file is based on work of the armbian developer team +# https://github.com/armbian/build/blob/master/packages/bsp/armbian_first_run.txt.template +#----------------------------------------------------------------- + +#----------------------------------------------------------------- +# General: +# 1 = delete this file, after first run setup is completed. + +NC_general_delete_this_file_after_completion=1 + +#----------------------------------------------------------------- +#Networking: +# Change default network settings +# Set to 1 to apply any network related settings below + +NC_net_change_defaults=0 + +# Enable WiFi or Ethernet. +# NB: If both are enabled, WiFi will take priority and Ethernet will be disabled. + +NC_net_ethernet_enabled=1 +NC_net_wifi_enabled=0 + +#Enter your WiFi creds +# SECURITY WARN: Your wifi keys will be stored in plaintext, no encryption. + +NC_net_wifi_ssid='MySSID' +NC_net_wifi_key='MyWiFiKEY' + +# Country code to enable power ratings and channels for your country. eg: GB US DE | https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + +NC_net_wifi_countrycode='GB' + +# If you want to use a static ip, set it here + +NC_net_use_static=0 +NC_net_static_ip='192.168.0.100' +NC_net_static_mask='255.255.255.0' +NC_net_static_gateway='192.168.0.1' +NC_net_static_dns='8.8.8.8 8.8.4.4' # Two entries max, seperated by a space. +#----------------------------------------------------------------- diff --git a/src/modules/orangepi_net/filesystem/root/etc/systemd/system/network-configurator.service b/src/modules/orangepi_net/filesystem/root/etc/systemd/system/network-configurator.service new file mode 100644 index 000000000..6568ee6d4 --- /dev/null +++ b/src/modules/orangepi_net/filesystem/root/etc/systemd/system/network-configurator.service @@ -0,0 +1,20 @@ +# MainsailOS network-configurator +# This service will run in parallel with other services +# This is based on +# https://github.com/armbian/build/blob/master/packages/bsp/common/lib/systemd/system/armbian-firstrun-config.service + + +[Unit] +Description=MainsailOS network configurator +Wants=network-online.target +After=network.target network-online.target +ConditionPathExists=/boot/network_config.txt + +[Service] +Type=idle +RemainAfterExit=yes +ExecStart=/usr/local/bin/network-configurator +TimeoutStartSec=2min + +[Install] +WantedBy=multi-user.target diff --git a/src/modules/orangepi_net/start_chroot_script b/src/modules/orangepi_net/start_chroot_script new file mode 100644 index 000000000..792754a58 --- /dev/null +++ b/src/modules/orangepi_net/start_chroot_script @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +#### MainsailOS network configurator for orange images +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck enable=require-variable-braces + +# Description: +# This file installs a service based on armbians armbian_firstrun_config +# The original work is done by the armbian developer's team +# sources of files can be found here: https://github.com/armbian/build + +# Source error handling, leave this in place +set -Ee + +# Source CustomPIOS common.sh +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + + +## Step 1: Install files +unpack filesystem/root / root +## END + +## Step 2: remove original template +if [[ -f "${ORANGEPI_NET_FIRSTRUN_FILE}" ]]; then + sudo rm -rf "${ORANGEPI_NET_FIRSTRUN_FILE}" +fi +## END + +## Step 3: Disable first run service +systemctl_if_exists disable orangepi-firstrun-config.service +## END + +## Step 4: Copy original script to /usr/local/bin/network-configurator +if [[ -f "${ORANGEPI_NET_FIRSTRUN_SCRIPT}" ]]; then + sudo cp -p "${ORANGEPI_NET_FIRSTRUN_SCRIPT}" "${ORANGEPI_NET_NC_PATH}" +fi +## END + +## Step 5: patch /usr/local/bin/network-configurator +if [[ -f "${ORANGEPI_NET_NC_PATH}" ]]; then + ### Substep 1: replace any orangepi_first_run.txt with network_config.txt + sed -i 's|orangepi_first_run.txt|network_config.txt|g' "${ORANGEPI_NET_NC_PATH}" + ### Substep 2: replace any FR* Variable name with NC* + sed -i 's|FR|NC|g' "${ORANGEPI_NET_NC_PATH}" + ### Supstep 3: Rename function + sed -i 's|do_firstrun_automated_user_configuration|do_network_configuration|g' "${ORANGEPI_NET_NC_PATH}" + ### Substep 4: Add a patch note + sed -i '8 i \\n\# This is a patched version of orangepi-firstrun-config for MainsailOS' "${ORANGEPI_NET_NC_PATH}" + sed -i '10 i # Original located at /usr/lib/orangepi/orangepi-firstrun-config' "${ORANGEPI_NET_NC_PATH}" + sed -i '11 i # Changes made by https:\/\/github.com/mainsail-crew' "${ORANGEPI_NET_NC_PATH}" +fi +## END + +## Step 6: Enable systemd service +systemctl_if_exists enable network-configurator.service +## END diff --git a/src/modules/piconfig/filesystem/tmp/msos_config.txt b/src/modules/piconfig/filesystem/tmp/msos_config.txt index dfc17571e..f21e3e879 100644 --- a/src/modules/piconfig/filesystem/tmp/msos_config.txt +++ b/src/modules/piconfig/filesystem/tmp/msos_config.txt @@ -44,12 +44,13 @@ dtparam=spi=on enable_uart=1 dtoverlay=disable-bt - -## Disable libcamera (interferes with ustreamer, when using raspicams) -camera_auto_detect=0 - -## Enable VideoCore at boot, needed for Crowsnest (Raspicams and DSI devices). -start_x=1 +## Enable I2C by default. +## This is used by Klipper's Host MCU +## See https://www.klipper3d.org/RPi_microcontroller.html#optional-enabling-i2c +## for destails. +## For MPU Accelrometer please use +## dtparam=i2c_arm=on,i2c_arm_baudrate=400000 +dtparam=i2c_arm=on ### EXPERIMENTAL - Enable 64bit Kernel diff --git a/src/modules/piconfig/start_chroot_script b/src/modules/piconfig/start_chroot_script index 7283b474e..483f8adf8 100644 --- a/src/modules/piconfig/start_chroot_script +++ b/src/modules/piconfig/start_chroot_script @@ -32,7 +32,7 @@ cp "${PICONFIG_CONFIG_TXT_FILE}" /tmp mv "${PICONFIG_CONFIG_TXT_FILE}" "${PICONFIG_CONFIG_BAK_FILE}" # Step 4: Concatenate files to config -cat /tmp/config.txt /tmp/msos_config.txt > /tmp/config.new +cat /tmp/config.txt /tmp/msos_config.txt >/tmp/config.new # Step 5: Copy new config to "/boot/config.txt" cp /tmp/config.new "${PICONFIG_CONFIG_TXT_FILE}" @@ -47,13 +47,26 @@ cp "${PICONFIG_CMDLINE_TXT_FILE}" "${PICONFIG_CMDLINE_BAK_FILE}" echo_green "Disable Serial Linux console ..." sed -i 's/console=serial0,115200 //' "${PICONFIG_CMDLINE_TXT_FILE}" -# Step 9: Disable bluetooth and related services +# Step 9: Enable i2c modules +# Also needs corresponding bits in config.txt (see #196) +echo_green "Enabling i2c-dev" +# Enable i2c_bcm2708 is disabled +[[ -f /etc/modprobe.d/raspi-blacklist.conf ]] && sed /etc/modprobe.d/raspi-blacklist.conf -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/" +[[ -f /etc/modules ]] || touch /etc/modules +sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/" # Uncomment i2c_dev +if ! grep -q "^i2c[-_]dev" /etc/modules; then # Add if doesn't exist + printf "i2c-dev\n" >>/etc/modules +fi +# install common i2c helpers +check_install_pkgs i2c-tools + +# Step 10: Disable bluetooth and related services echo_green "Disabling Bluetooth related services..." systemctl_if_exists disable hciuart.service systemctl_if_exists disable bluetooth.service systemctl_if_exists disable bluealsa.service -# Step 10: Increase swapfile size +# Step 11: Increase swapfile size if [[ -f "${PICONFIG_SWAP_CONF_FILE}" ]]; then echo_green "Increasing swap file size to ${PICONFIG_SWAP_SIZE} Mb. Limit to ${PICONFIG_SWAP_MAX} Mb" sed -i 's/^CONF_SWAPSIZE.*/'CONF_SWAPSIZE="${PICONFIG_SWAP_SIZE}"'/' "${PICONFIG_SWAP_CONF_FILE}" diff --git a/src/modules/postrename/filesystem/root/postrename b/src/modules/postrename/filesystem/root/postrename index daae2f64e..8c3631887 100644 --- a/src/modules/postrename/filesystem/root/postrename +++ b/src/modules/postrename/filesystem/root/postrename @@ -64,7 +64,6 @@ change_www_root() { " } - ### change username in service files change_service_user() { ### Filter nginx service first! @@ -119,6 +118,13 @@ patch_polkit_rules() { fi } +patch_cn_logpath() { + bash -c " + sed -i 's|/home/pi/printer_data/logs/crowsnest.log|/home/${DEFAULT_USER}/printer_data/logs/crowsnest.log|g' \ + /home/${DEFAULT_USER}/printer_data/config/crowsnest.conf + " +} + patch_cn_logrotate() { if [[ -f "/etc/logrotate.d/crowsnest" ]]; then sed -i 's/pi/'"${DEFAULT_USER}"'/g' "/etc/logrotate.d/crowsnest" @@ -169,6 +175,13 @@ fix_kiauh_links() { } +fix_cn_links() { + local tools_dir + tools_dir="/home/${DEFAULT_USER}/crowsnest/tools" + sudo -u "${DEFAULT_USER}" \ + ln -sf "${tools_dir}/libs/pkglist-rpi.sh" "${tools_dir}/pkglist.sh" +} + main() { local cmdltxt cmdltxt="/boot/cmdline.txt" @@ -214,6 +227,10 @@ echo -e "${WHITE}Trying to relocate venv's ...${NOC}[${GRE}OK${NOC}]" echo -e "${WHITE}Patching moonraker's polkit rules ...${NOC}" patch_polkit_rules echo -e "${WHITE}Patching moonraker's polkit rules ...${NOC}[${GRE}OK${NOC}]" +## patch crownsnest log path +echo -en "${WHITE}Patching crowsnest logpath ...${NOC}\r" +patch_cn_logpath +echo -e "${WHITE}Patching crowsnest logpath ...${NOC}[${GRE}OK${NOC}]" ## patch crowsnest logrotate echo -e "${WHITE}Patching crowsnest logrotate ...${NOC}" patch_cn_logrotate @@ -223,10 +240,14 @@ echo -en "${WHITE}Fix broken symlinks ...${NOC}\r" fix_broken_links fix_timelapse_links fix_mainsailcfg_links +<<<<<<< HEAD # Optional if kiauh module is used if [[ -d "/home/${DEFAULT_USER}/kiauh" ]]; then fix_kiauh_links fi +======= +fix_cn_links +>>>>>>> develop echo -e "${WHITE}Fix broken symlinks ...${NOC}[${GRE}OK${NOC}]" ## do a short break sleep 2 diff --git a/src/modules/udev_fix/config b/src/modules/udev_fix/config new file mode 100644 index 000000000..1be59fb30 --- /dev/null +++ b/src/modules/udev_fix/config @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +#### MainsailOS udev_fix +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +#### This should fix error in udev not creating symlinks fpr serial devices. +#### For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094 +#### This is fixed by: https://github.com/systemd/systemd/pull/25246 +#### To fix this error in MainsailOS we implement that file as 'user rule'. + +#shellcheck disable=all + +[[ -n "${UDEV_FIX_RAW_RULE_FILE}" ]] || UDEV_FIX_RAW_RULE_FILE="https://raw.githubusercontent.com/systemd/systemd/main/rules.d/60-serial.rules" +[[ -n "${UDEV_FIX_OUTPUT_FILE}" ]] || UDEV_FIX_OUTPUT_FILE="/etc/udev/rules.d/60-serial.rules" +[[ -n "${UDEV_FIX_PKGS}" ]] || UDEV_FIX_PKGS="systemd udev" diff --git a/src/modules/udev_fix/start_chroot_script b/src/modules/udev_fix/start_chroot_script new file mode 100644 index 000000000..83e762581 --- /dev/null +++ b/src/modules/udev_fix/start_chroot_script @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +#### MainsailOS MainsailOS udev_fix +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2023 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +#### This should fix error in udev not creating symlinks fpr serial devices. +#### For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094 +#### This is fixed by: https://github.com/systemd/systemd/pull/25246 +#### To fix this error in MainsailOS we implement that file as 'user rule'. + +# shellcheck enable=require-variable-braces +# Source error handling, leave this in place +set -Ee + +# Source CustomPIOS common.sh +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + + +echo_green "Running 'udev' fix ..." + +# Step 1: Ensure systemd, udev are up to date (armbian workaround) +if [[ -f /etc/armbian.txt ]]; then + echo_green "Armbian base image detected ..." + echo_green "Updating ${UDEV_FIX_PKGS} first ..." + apt-get update + # Disable shellcheck here, because we need 'word splitting' + # shellcheck disable=SC2086 + apt-get --yes install --only-upgrade ${UDEV_FIX_PKGS} +fi + +# Step 2: Fix broken udev (remove after debian releases patch) +UDEV_PKG_VERSION="$(dpkg-query -s udev | grep "Version" | sed 's/Version\: //')" + +if [[ -n "${UDEV_PKG_VERSION}" ]] && [[ "${UDEV_PKG_VERSION}" =~ "deb11u2" ]]; then + echo_red "'udev' version: ${UDEV_PKG_VERSION}, is affected by bug ..." + echo_green "Install patched udev rule from systemd git repository ..." + curl -sSL "${UDEV_FIX_RAW_RULE_FILE}" > "${UDEV_FIX_OUTPUT_FILE}" +else + echo_green "'udev' version: ${UDEV_PKG_VERSION}, is NOT affected by bug ... [SKIPPED]" +fi diff --git a/src/version b/src/version index 3eefcb9dd..6085e9465 100644 --- a/src/version +++ b/src/version @@ -1 +1 @@ -1.0.0 +1.2.1