Mouser "Library Loader" linux script

Hi all, here is a small ugly bash script but works for me, so maybe someone elese finds a use for it or improve it. I use it with a project-lib in 7.0. Use at you own risk. Its self-explanatory but in any case:

  • You need bash, unzip, sleep and sed
  • Create klll.sh file whith the contents and make it executble
  • Set the correct paths on top of the script, to your symbol library file, 3d folder and footprint folder
  • Put the script in an empty folder and run in a dedicated xterm or similar (not daemon)
  • Download from mouser a samacsys zip file containing the mentioned 3 kicad files and put it in the folder
  • Script extracts 3 kicad files, copies the 3d (.stp) and footprint files to the folders you have set, and appends the symbol data on your symbol library file (beware that if something breaks, this might mess your whole lib file so best to work on a copy of it). Then moves the .zip to .zip_archived
  • You probably still need to fix the paths inside kicad for the symbol-footprint assosiation and also footprint-3d (or ad some sed lines in the script to do that !)
#! /bin/bash

# 3D lib folder path
lib3dPath="./3d"

# footprint folder path
libFpPath="./fp"

# Schematic lib file path
libSch="prj_sym_lib.kicad_sym"

# Loop Delay
loopDelay=5


# Case insensitive
shopt -s nocaseglob

# Loop start
while true; do

sourcefile=$(ls *.zip)
tempdir=temp

# Case sensitive
# shopt -u nocaseglob


# Unzip any found .zip file and archive
if [[ -e "$sourcefile" ]]; then

    unzip "$sourcefile" -d "$tempdir" >/dev/null
    echo "klll: $sourcefile unzipped"

    mv "$sourcefile" "$sourcefile""_archived"
    wait
    echo "klll: $sourcefile archived"

    # Copy 3d file if found
    file3d=$(find ./"$tempdir" -name '*.stp')

    if [[ -e "$file3d" ]]; then

        cp -i "$file3d" "$lib3dPath"
        wait
        echo "klll: 3D STEP file $file3d copied to $lib3dPath"

    else
        echo "klll: No 3D STEP file found"
    fi


    # Copy footprint file if found
    filefp=$(find ./"$tempdir" -name '*.kicad_mod')

    if [[ -e "$filefp" ]]; then

        cp -i "$filefp" "$libFpPath"
        wait
        echo "klll: Footprint file $filefp copied to $libFpPath"

    else
        echo "klll: No Footprint (.kicad_mod) file found"
    fi

    # Copy part text if found and append to libSch
    fileSch=$(find ./"$tempdir" -name '*.kicad_sym')

    if [[ -e "$fileSch" ]]; then

        sed "2,\$w tempfile" "$fileSch"
        wait
        sed -i '$d' tempfile
        wait
        sed -i '1r tempfile' "$libSch"
        wait
        sed -i 's/\r//g' "$libSch"
        wait

        echo "klll: Symbol file $fileSch added to $libSch"

    else
        echo "klll: No Symbol (.kicad_sym) file found"
    fi
   
    # Delete extracted and temp files
    rm -r "$tempdir"
    wait
    rm tempfile
    wait

fi


# Wait X sec
sleep "$loopDelay"

# Loop end
done

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.