#!/bin/bash #set -x INPUT="$*" OUTDIR=$(mktemp -d) IMGDIR="$GITEA_WORK_DIR/custom/public/assets/img" ln -s "$INPUT" "$OUTDIR"/schematic.kicad_sch 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 mapfile -t FILES \ < <(kicad-cli sch export svg --exclude-drawing-sheet --no-background-color --output "$OUTDIR" "$OUTDIR/schematic.kicad_sch" | grep -E 'Plotted to' | sed -r "s/^[^']+'|'[^']+$//g" ) file_num=1 for FILE in "${FILES[@]}"; do FN="${IMGDIR}/${HASH}.${file_num}.svg" inkscape --actions="page-fit-to-selection" -o "$FN" "$FILE" file_num=$((file_num + 1)) break # TODO: find some way to handle related (hierarchical) schematic files, as currently only the active file is made available done shopt -s nullglob IMAGES=("${IMGDIR}"/${HASH}.*.svg) shopt -u nullglob fi for FILE in "${IMAGES[@]}"; do echo '
' # echo "bla" echo -n '' echo '
' done else # 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/schematic.kicad_sch" | grep -E 'Plotted to' | sed -r "s/^[^']+'|'[^']+$//g" ) for FILE in "${FILES[@]}"; do echo -n '
' echo -n '' echo '
' break # TODO: find some way to handle related (hierarchical) schematic files, as currently only the active file is made available done fi rm -R "$OUTDIR"