From b7f4256696d87faead88f6657ce15e934efe925f Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 6 May 2025 13:18:42 +0300 Subject: [PATCH 1/6] Update GitHub Actions to latest versions Update all GitHub Actions to their latest stable versions, including: - actions/checkout@v4 - actions/github-script@v7 - actions/upload-artifact@v4 - softprops/action-gh-release@v2 - Replace deprecated SFTP action with wangyucode/sftp-upload-action@v2.0.2 - Fix conditional syntax in workflow --- .github/workflows/build.yml | 42 +++++++++++-------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a8d776..6156c39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Build Image -on: +on: push: branches: - '*' @@ -18,26 +18,23 @@ jobs: runs-on: ubuntu-latest steps: - name: "⬇ Checkout" - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: "🔎 Determine OctoPi version" - uses: actions/github-script@v4 + uses: actions/github-script@v7 with: script: | let release = null; - let version = ''; - if (context.eventName === "respository_dispatch" && context.action === "octopi_release") { + if (context.eventName === "repository_dispatch" && context.action === "octopi_release") { version = context.payload.client_payload.version; console.log(`Version from repository dispatch: ${version}`); } else if (context.eventName === "workflow_dispatch") { version = context.payload.inputs.octopi_version; console.log(`Version from workflow dispatch: ${version}`); } - if (version) { console.log(`Fetching release of ${version}`); - const query = `query { repository(owner: "guysoft", name: "Octopi") { release(tagName:"${version}") { @@ -51,15 +48,11 @@ jobs: } } }`; - const result = await github.graphql(query); console.log({result}); - release = result.repository.release; - } else { console.log("Fetching latest release"); - const query = `query { repository(owner:"guysoft", name:"OctoPi") { latestRelease { @@ -73,17 +66,12 @@ jobs: } } }`; - const result = await github.graphql(query); console.log({result}); - release = result.repository.latestRelease; } - if (!release || !release.tagName || !release.releaseAssets || !release.releaseAssets.nodes) core.setFailed("Could not find OctoPi release"); - const octopiVersion = release.tagName; - let octopiUrl = null; for (const asset of release.releaseAssets.nodes) { if (asset.name.startsWith("octopi-") && asset.name.endsWith(".zip")) { @@ -91,12 +79,9 @@ jobs: break; } } - if (!octopiUrl) core.setFailed("Could not find OctoPi download URL"); - console.log(`OctoPi version: ${octopiVersion}`) console.log(`OctoPi download URL: ${octopiUrl}`) - core.exportVariable("OCTOPI_VERSION", octopiVersion) core.exportVariable("OCTOPI_URL", octopiUrl) @@ -109,7 +94,6 @@ jobs: unzip octopi.zip rm octopi.zip - IMAGE=$(ls *.img | head -n 1) mv $IMAGE input.img @@ -118,7 +102,7 @@ jobs: with: workspace: "${{ github.workspace }}/build" scripts: "${{ github.workspace }}/src/scripts" - config: "${{ github.workspace }}/src/config" + config: "${{ github.workspace }}/src/config" - name: "✏ Rename image" run: | @@ -128,7 +112,6 @@ jobs: IMAGE="octopi-$OCTOPI_VERSION-klipper-$NOW" echo "IMAGE=$IMAGE" >> $GITHUB_ENV echo "NOW=$NOW" >> $GITHUB_ENV - cd build mv output.img $IMAGE.img @@ -137,13 +120,10 @@ jobs: run: | RELEASE_NAME="OctoPi ${{ env.OCTOPI_VERSION }} with latest Klipper" echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV - RELEASE_TAG="${{ env.OCTOPI_VERSION }}.klipper.${{ env.NOW }}" echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV - RELEASE_BODY="" (git rev-parse $RELEASE_TAG >/dev/null 2>&1) || RELEASE_BODY="Created with [CustoPiZer](https://github.com/OctoPrint/CustoPiZer)" - echo "RELEASE_BODY=$RELEASE_BODY" >> $GITHUB_ENV - name: "📦 Package the image" @@ -169,7 +149,7 @@ jobs: - name: "🔖 Create release & attach assets" if: github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: name: "${{ env.RELEASE_NAME }}" tag_name: "${{ env.RELEASE_TAG }}" @@ -185,11 +165,12 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: "⬆ Upload build artifact" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: github.event_name == 'push' with: name: ${{ env.IMAGE }} path: build/${{ env.IMAGE }}.img + - name: "🔖 Generate rpi-imager json" uses: OctoPrint/actions/rpi-imager-json@main with: @@ -199,14 +180,15 @@ jobs: output: ./rpi-imager.json nameStable: "OctoPi-Klipper (stable)" namePrerelease: "OctoPi-Klipper (prerelease)" + - name: "⬆ Publish Files To rpi-imager" if: github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' id: upload - uses: Creepios/sftp-action@v1.0.3 + uses: wangyucode/sftp-upload-action@v2.0.2 with: host: ${{ secrets.FTP_HOST }} port: 22 username: ${{ secrets.FTP_USERNAME }} password: ${{ secrets.FTP_PASSWORD }} - localPath: './rpi-imager.json' - remotePath: '/rpi-imager/rpi-imager-octoklipperpi.json' + localDir: './rpi-imager.json' + remoteDir: '/rpi-imager/rpi-imager-octoklipperpi.json' From 7a5611bb9299f4fb2fb4d89e174711eaac236ded Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 6 May 2025 13:26:46 +0300 Subject: [PATCH 2/6] Fix so only armf version is downloaded --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6156c39..3c421e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,9 +74,12 @@ jobs: const octopiVersion = release.tagName; let octopiUrl = null; for (const asset of release.releaseAssets.nodes) { - if (asset.name.startsWith("octopi-") && asset.name.endsWith(".zip")) { - octopiUrl = asset.downloadUrl; - break; + if (asset.name.startsWith("octopi-") && + asset.name.endsWith(".zip") && + !asset.name.includes("arm64") && + (asset.name.includes("armhf") || !asset.name.includes("arm"))) { + octopiUrl = asset.downloadUrl; + break; } } if (!octopiUrl) core.setFailed("Could not find OctoPi download URL"); From ba9895ed8494195c5d82f7db20aecd3baf92b833 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 6 May 2025 15:45:52 +0300 Subject: [PATCH 3/6] Use python3 for klipper --- src/scripts/03-install-klipper | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/03-install-klipper b/src/scripts/03-install-klipper index 7779a6a..326b489 100644 --- a/src/scripts/03-install-klipper +++ b/src/scripts/03-install-klipper @@ -25,12 +25,12 @@ install_cleanup_trap [ -n "$KLIPPER_OCTOKLIPPER_URL" ] || KLIPPER_OCTOKLIPPER_URL="https://github.com/thelastWallE/OctoprintKlipperPlugin/archive/master.zip" # Install Klipper -apt-get -y --allow-downgrades --allow-remove-essential --allow-change-held-packages install virtualenv python-dev 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 +apt-get -y --allow-downgrades --allow-remove-essential --allow-change-held-packages install virtualenv python3 python3-dev 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 pushd /home/pi # Mostly taken from klipper/scripts/install-octopi.sh sudo -u pi git clone -b "$KLIPPER_BRANCH" --depth $KLIPPER_DEPTH "$KLIPPER_REPO" klipper - sudo -u pi virtualenv -p python2 klippy-env + sudo -u pi virtualenv -p python3 klippy-env sudo -u pi klippy-env/bin/pip install -r klipper/scripts/klippy-requirements.txt cp klipper/scripts/klipper-start.sh /etc/init.d/klipper From f300ffa7d71b6d3a99daa81d4c26a126482ed0e2 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 6 May 2025 15:56:16 +0300 Subject: [PATCH 4/6] Enlarge root to 3000MB --- src/config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config b/src/config index ef6edc2..b297972 100644 --- a/src/config +++ b/src/config @@ -1,5 +1,5 @@ -# enlarge image by 100MB prior to customization -EDITBASE_IMAGE_ENLARGEROOT=2000 +# enlarge image by 3000MB prior to customization +EDITBASE_IMAGE_ENLARGEROOT=3000 # shrink image to minimum size plus 20MB after customization EDITBASE_IMAGE_RESIZEROOT=20 From 9d0dd2d5cad2dd85656517c5ec4c14168bcf0fb5 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 6 May 2025 16:14:40 +0300 Subject: [PATCH 5/6] Remove user fix script, its now part of OctoPi --- src/scripts/90-install-user-fix | 17 ---------- src/scripts/files/user-fix | 52 ------------------------------ src/scripts/files/user-fix.service | 17 ---------- 3 files changed, 86 deletions(-) delete mode 100644 src/scripts/90-install-user-fix delete mode 100644 src/scripts/files/user-fix delete mode 100644 src/scripts/files/user-fix.service diff --git a/src/scripts/90-install-user-fix b/src/scripts/90-install-user-fix deleted file mode 100644 index 79f4945..0000000 --- a/src/scripts/90-install-user-fix +++ /dev/null @@ -1,17 +0,0 @@ -set -x -set -e - -export LC_ALL=C - -source /common.sh -install_cleanup_trap - -# we need to install virtualenv-tools3, so let's get pip and that -apt install -y python3-pip -sudo -u pi pip3 install --user virtualenv-tools3 - -cp /files/user-fix /root/bin/user-fix -chmod +x /root/bin/user-fix - -cp /files/user-fix.service /etc/systemd/system/user-fix.service -systemctl enable user-fix.service diff --git a/src/scripts/files/user-fix b/src/scripts/files/user-fix deleted file mode 100644 index 815a42b..0000000 --- a/src/scripts/files/user-fix +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -set -e - -USERID=1000 -FIRSTUSER=`getent passwd $USERID | cut -d: -f1` -FIRSTUSERHOME=`getent passwd $USERID | cut -d: -f6` - -CURRENT=`grep User= /etc/systemd/system/octoprint.service | cut -d= -f2` - -if [ "$CURRENT" = "pi" -a "$FIRSTUSER" != "pi" ]; then - # if we get here it means that the first user was renamed but we haven't yet - # updated all of OctoPi's files that depend on that name, so let's do that now - - # first we need to figure out if we can use the new user name in systemd files - # directly or if we need to use the UID - we do that by checking if the - # escaped name differes from the plain name, if so something is non ASCII - # and the UID is the safer bet - FIRSTUSERESC=`systemd-escape "$FIRSTUSER"` - if [ "$FIRSTUSER" != "$FIRSTUSERESC" ]; then - SERVICEUSER=$USERID - else - SERVICEUSER=$FIRSTUSER - fi - - # fix OctoPrint service file - echo "Fixing service file" - sed -i "s!User=pi!User=$SERVICEUSER!g" /etc/systemd/system/octoprint.service - sed -i "s!ExecStart=/home/pi/!ExecStart=$FIRSTUSERHOME/!g" /etc/systemd/system/octoprint.service - systemctl daemon-reload - - # fix sudoers files - echo "Fixing sudoers" - sed -i "s!^pi!$FIRSTUSER!g" /etc/sudoers.d/octoprint-service - sed -i "s!^pi!$FIRSTUSER!g" /etc/sudoers.d/octoprint-shutdown - - # fix scripts - echo "Fixing scripts" - sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" $FIRSTUSERHOME/scripts/add-octoprint-checkout - sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" $FIRSTUSERHOME/scripts/welcome - sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" $FIRSTUSERHOME/.bashrc - sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" /root/bin/webcamd - - # fix virtualenv - echo "Fixing paths in virtual environment" - cd $FIRSTUSERHOME/oprint - sudo -u $FIRSTUSER $FIRSTUSERHOME/.local/bin/virtualenv-tools --update-path $FIRSTUSERHOME/oprint - - # finally, reboot for all of this to actually take affect - echo "Adjusted scripts to new user, restarting services..." - systemctl reboot -fi diff --git a/src/scripts/files/user-fix.service b/src/scripts/files/user-fix.service deleted file mode 100644 index 6f8026f..0000000 --- a/src/scripts/files/user-fix.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Ensure that user name changes are applied as needed - -DefaultDependencies=no - -Before=network-pre.target -Wants=network-pre.target - -After=local-fs.target -Wants=local-fs.target - -[Service] -Type=oneshot -ExecStart=/root/bin/user-fix - -[Install] -WantedBy=multi-user.target From ddf1516ace2ddcffab4135997cef80d2a4c9efb0 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 6 May 2025 17:07:42 +0300 Subject: [PATCH 6/6] Update OctoPrint install path to /opt/octopi --- src/scripts/01-update-octoprint | 5 ++++- src/scripts/03-install-klipper | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/scripts/01-update-octoprint b/src/scripts/01-update-octoprint index ff5dcba..b83a56c 100644 --- a/src/scripts/01-update-octoprint +++ b/src/scripts/01-update-octoprint @@ -6,4 +6,7 @@ export LC_ALL=C source /common.sh install_cleanup_trap -sudo -u pi /home/pi/oprint/bin/pip install -U OctoPrint +OCTOPI_OPT_FOLDER=/opt/octopi +OCTOPI_OCTOPRINT_FOLDER="${OCTOPI_OPT_FOLDER}"/oprint +PIP="${OCTOPI_OCTOPRINT_FOLDER}"/bin/pip +sudo -u pi "${PIP}" install -U OctoPrint diff --git a/src/scripts/03-install-klipper b/src/scripts/03-install-klipper index 326b489..fcccfe6 100644 --- a/src/scripts/03-install-klipper +++ b/src/scripts/03-install-klipper @@ -27,7 +27,13 @@ install_cleanup_trap # Install Klipper apt-get -y --allow-downgrades --allow-remove-essential --allow-change-held-packages install virtualenv python3 python3-dev 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 -pushd /home/pi +OCTOPI_OPT_FOLDER=/opt/octopi +OCTOPI_OCTOPRINT_FOLDER="${OCTOPI_OPT_FOLDER}"/oprint +PIP="${OCTOPI_OCTOPRINT_FOLDER}"/bin/pip +chown pi:pi "${OCTOPI_OPT_FOLDER}" +chmod g+s /opt/octopi "${OCTOPI_OPT_FOLDER}" +chmod u+s /opt/octopi "${OCTOPI_OPT_FOLDER}" +pushd "${OCTOPI_OPT_FOLDER}" # Mostly taken from klipper/scripts/install-octopi.sh sudo -u pi git clone -b "$KLIPPER_BRANCH" --depth $KLIPPER_DEPTH "$KLIPPER_REPO" klipper sudo -u pi virtualenv -p python3 klippy-env @@ -46,7 +52,7 @@ cp /files/klipper/default /etc/default/klipper chmod 644 /etc/default/klipper # Install plugin -sudo -u pi /home/pi/oprint/bin/pip install "${KLIPPER_OCTOKLIPPER_URL}" +sudo -u pi "${PIP}" install "${KLIPPER_OCTOKLIPPER_URL}" # Merge config -sudo -u pi /home/pi/oprint/bin/python /files/merge-settings.py /files/octoprint/config.yaml /home/pi/.octoprint/config.yaml +sudo -u pi "${OCTOPI_OCTOPRINT_FOLDER}"/bin/python /files/merge-settings.py /files/octoprint/config.yaml /home/pi/.octoprint/config.yaml