#!/bin/bash #set -x INPUT="$*" OUTDIR=$(mktemp -d) IMGDIR="$GITEA_WORK_DIR/custom/public/assets/img" KIOPTS=( # --subtract-soldermask --mode-single --exclude-drawing-sheet --page-size-mode 2 --sketch-pads-on-fab-layers ) ln -s "$INPUT" "$OUTDIR"/pcb.kicad_pcb if [[ -d "$IMGDIR" && -w "$IMGDIR" ]]; then # We can use caching HASH=$(sha256sum "$INPUT" | cut -c1-64) shopt -s nullglob IMAGES=("${IMGDIR}"/${HASH}.*.svg) shopt -u nullglob if [ ${#IMAGES[@]} -le 0 ]; then kicad-cli pcb export svg "${KIOPTS[@]}" --layers Edge.Cuts,F.Cu,F.Mask,F.Silkscreen,F.Adhesive,F.Paste --output "${OUTDIR}/${HASH}.1.svg" "$OUTDIR"/pcb.kicad_pcb >/dev/null kicad-cli pcb export svg "${KIOPTS[@]}" --mirror --layers Edge.Cuts,B.Cu,B.Mask,B.Silkscreen,B.Adhesive,B.Paste --output "${OUTDIR}/${HASH}.2.svg" "$OUTDIR"/pcb.kicad_pcb >/dev/null inkscape --actions="page-fit-to-selection" -o "${IMGDIR}/${HASH}.1.svg" "${OUTDIR}/${HASH}.1.svg" inkscape --actions="page-fit-to-selection" -o "${IMGDIR}/${HASH}.2.svg" "${OUTDIR}/${HASH}.2.svg" shopt -s nullglob IMAGES=("${IMGDIR}"/${HASH}.*.svg) shopt -u nullglob fi echo '
' for IMG in "${IMAGES[@]}"; do echo '
' # echo "bla" echo -n '' echo '
' done echo '
' else echo "

Error: Unable to write to $IMGDIR. Please check permissions.

" # TODO: Implement base64 method # We'll be generating the images on the fly, including them as base64 # mapfile -t FILES \ # < <(kicad-cli sch export svg --exclude-drawing-sheet --no-background-color --output "$OUTDIR" "$OUTDIR/pcb.kicad_pcb" | grep -E 'Plotted to' | sed -r "s/^[^']+'|'[^']+$//g" ) # for FILE in "${FILES[@]}"; do # echo -n '
' # echo -n '' # echo '
' # done fi rm -R "$OUTDIR"