Movatterモバイル変換


[0]ホーム

URL:


Beyond Technology
beyond the visible world

Prusa Mini: programmatically upload files via curl bash script

http api ethernet 3d printing prusa mini+

Thanks to the recentv4.4.1 BuddyBoard firmware the http file api works as desired: you can easily upload files to a usb stick attached to the printer. To perform bulk updates of your printer farm it’s much easier to write a simple bash script which deploys the print jobs:

#!/usr/bin/env bashset -e# printer settingsPRINTER_HOST="192.168.1.123"API_KEY="ToEn8eDlR7kWIiUpVPJg"FILENAME=myfile.gcode# capture command stdout - http status code will be written to stdout# progress bar on stderr# http response (json) stored in /tmp/.upload-responseCURL_HTTP_STATUS=$(curl \    --header "X-Api-Key: ${API_KEY}" \    -F "file=@${FILENAME}" \    -F "path=" \    -X POST \    -o /tmp/.upload-response \    --write-out "%{http_code}" \    http://${PRINTER_HOST}/api/files/local)# get resultCURL_EXITCODE=$?CURL_RESPONSE=$(cat /tmp/.upload-response)# success ?if [ ${CURL_EXITCODE} -ne 0 ] || [ "${CURL_HTTP_STATUS}" -ne "201" ]; then    echo "error: upload failed (${CURL_HTTP_STATUS})"else    echo "upload succeed"fi
February 26, 2023 - This entry was posted in:3D Printing,Code Snippet,Hardware

cURL HowTo upload multiple files with checksums

Uploading multiple files and checksums via http can be achieved with cURL and a few lines bash scripting. This might replacescp in most cases.

# array of files (and checksums) provided as cURL optionsUPLOAD_FILES=()# get all files within myUploadDir dir and calculate checksumswhile read -r FILEdo    # get sha256 checksum    CHECKSUM=$(sha256sum ${FILE} | awk '{print $1}' )    echo $FILE    echo $CHECKSUM    # extract filename    FILENAME=$(basename ${FILE})    # append file and checksum to curl upload args    UPLOAD_FILES+=("-F" "file=@${FILE}")     UPLOAD_FILES+=("-F" "${FILENAME}=${CHECKSUM}")# get all files within myUploadDirdone <<<$(find myUploadDir/* -type f | sort)# uploadcurl \     -X PUT -H "Content-Type: multipart/form-data" \     "${UPLOAD_FILES[@]}" \     https://httpbin.org/put
May 21, 2022 - This entry was posted in:bash,Code Snippet

OpenWrt on Ubiquiti EdgeRouter X SFP with working SFP module

ER-X-SFP OpenWRT21 DSA Distributed Network Switch

The EdgeRouter X-SFP is a quite powerful dualcore (880Mhz, 256MB RAM, 256MB flash) device powered by a MediaTek MT7621AT SoC. OpenWrt 21 (snapshot) comes with support for the SFP slot (attached to the switch port eth5 via RGMII). Note: it won’t work with OpenWrt 19! Custom build# As of April 2021 it requires a custom […]

April 5, 2021 - This entry was posted in:Hardware,Linux,Networking,OpenWrt,Routing

MikroTik CRS112 Basic switching setup

CRS112-8G-4S-IN CRS112-8P-4S-IN

The MikroTik CRS switches are absolutely awesome! You get a full featured, managed, wire speed switch combined with a SoC running RouterOS.But on the “downside” the configuration can be very complex and requires some deeper knowledge about switching and linux networking in general – as a linux user you will love it ;) Step 1 […]

July 5, 2020 - This entry was posted in:Uncategorized

Hetzner Cloud: Predictable Network Interface Names

ens3 ens10 ens11 ens12 enp1s0 enp7s0 enp8s0 enp9s0

With the release of the new AMD EPYC based cloud servers (CPX), Hetzner has applied some changes to their virtualization platform (QEMU). The network interface names have changed due to the modern virtio_net network adapter 0x1041 including different pcie bus addresses. All Hetzner standard images are now using the net.ifnames=0 setting to enforce the kernel […]

May 16, 2020 - This entry was posted in:Cloud,Code Snippet,Linux,systemd

GPG: encrypt files with a public keyfile without using a global keyring

one way backup encryption

gnugp is very useful to encrypt files using a public key – this allows you to create backups without sharing a keyfile. But it’s a bit tricky to explicitly use a public-keyfile instead of the global keyring via fingerprint. Directory Structure# This script creates a custom .gnupg directory (gpg home) in the current working directory […]

February 21, 2020 - This entry was posted in:cryptography,gpg,Linux,Tweaks

Protected: testpost EJS

There is no excerpt because this is a protected post.

January 4, 2020 - This entry was posted in:Uncategorized

Traefik: tls private key does not match public key

self signed certificates, combined pem

In case you’re using self-signed x509 certificates you may see this error message within the traefik logs – the solution is quite easy: the first certificate of your combined pem file (ca+intermediate+server) has to be the server certificate!

November 2, 2019 - This entry was posted in:Code Snippet,Docker,HowTo,Linux,ssl,Traefik,x509

iPXE: static ipv6 configuration

These days, some cloud hosting environments still didn’t offer dhcp6 services (for example Hetzner Cloud) – therefore it’s impossible to use an automated ipv6 configuration with iPXE. But a static configuration can still be used: File: config.ipxe#

October 27, 2019 - This entry was posted in:Linux,Networking

BusyBox: fancy cli color prompt via PS1

busybox ps1 profile colors

PS1 magic# The default prompt of BusyBox ash shell looks a bit old fashioned . But thanks to nearly full support of the PS1 environment variable you can customize the prompt to match your needs. Customizing the PS1 variable is quite simple: just add /etc/profile which is read automatically by ash when it’s used as […]

October 20, 2019 - This entry was posted in:Docker,Linux,Tweaks

[8]ページ先頭

©2009-2025 Movatter.jp