#!/usr/bin/env sh # EDAUtils installer - fetches one tool bundle and puts its bin/ on PATH. # # curl -fsSL https://edautils.com/install.sh | sh -s -- verilog2ipxact # curl -fsSL https://edautils.com/install.sh | sh -s -- baya-shell ipxact-shell # curl -fsSL https://edautils.com/install.sh | sh -s -- --list # # Tools are Java (8+) applications packaged as tar.gz with a bin/ directory # and a setup_env script. This installer unpacks into $EDAUTILS_HOME # (default ~/.edautils) and prints the PATH line to add. # # Sources are tried in order; set EDAUTILS_SOURCE to force one: # edautils https://edautilsonline.com/download/files// # github https://github.com/edautils//releases/latest/download/.tar.gz # sourceforge https://sourceforge.net/projects/edautils-converters/files/.tar.gz/download set -eu EDAUTILS_HOME="${EDAUTILS_HOME:-$HOME/.edautils}" EDAUTILS_SOURCE="${EDAUTILS_SOURCE:-}" CATALOG="${EDAUTILS_CATALOG:-https://edautilsonline.com/api/tools.json}" GH_ORG="${EDAUTILS_GH_ORG:-edautils}" SF_PROJECT="${EDAUTILS_SF_PROJECT:-edautils-converters}" say() { printf '%s\n' "$*" >&2; } die() { say "install.sh: $*"; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || die "needs '$1' on PATH"; } need tar if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL --retry 2 -o "$2" "$1"; } fetch_stdout() { curl -fsSL --retry 2 "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q -O "$2" "$1"; } fetch_stdout() { wget -q -O - "$1"; } else die "needs curl or wget" fi # tool name (as used on the site) -> catalog key on edautilsonline.com key_for() { case "$1" in baya-shell) echo BayaShell ;; ipxact-shell) echo IpxactShell ;; designplayer-shell) echo DesignplayerShell ;; designplayer-gui-linux) echo DesignplayerGuiLinux ;; designplayer-gui-windows) echo DesignplayerGuiWindows ;; ip-xact-gui-linux) echo IpXactGuiLinux ;; ip-xact-gui-windows) echo IpXactGuiWindows ;; parseverilog) echo ParseverilogSystemverilog ;; upf-shell) echo UpfShell ;; fecadflow) echo FECADFlowBinaries ;; [A-Z]*) echo "$1" ;; # already a catalog id *) # createhierarchy -> Createhierarchy, verilog2ipxact -> Verilog2Ipxact printf '%s' "$1" | awk -F2 '{ for (i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2) } 1' OFS=2 ;; esac } list_tools() { say "Fetching catalog: $CATALOG" # one JSON object per line, then id + name fetch_stdout "$CATALOG" | tr -d '\n' | grep -o '{[^{}]*}' \ | sed -n 's/.*"id": *"\([^"]*\)".*"name": *"\([^"]*\)".*/\1\t\2/p' } # Resolve the newest archive for a tool from edautilsonline's catalog. # tools.json lists releases newest-first when the deploy has published any. edautils_url() { key=$(key_for "$1") fetch_stdout "$CATALOG" 2>/dev/null | tr -d '\n' | grep -o '{[^{}]*}' \ | grep "\"id\": *\"$key\"" \ | sed -n 's/.*"download_url": *"\([^"]*\)".*/\1/p' | head -1 } github_url() { echo "https://github.com/$GH_ORG/$1/releases/latest/download/$1.tar.gz"; } sourceforge_url() { echo "https://sourceforge.net/projects/$SF_PROJECT/files/$1.tar.gz/download"; } install_one() { tool="$1" dest="$EDAUTILS_HOME/$tool" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT ok="" for src in ${EDAUTILS_SOURCE:-edautils github sourceforge}; do case "$src" in edautils) url=$(edautils_url "$tool" || true) ;; github) url=$(github_url "$tool") ;; sourceforge) url=$(sourceforge_url "$tool") ;; *) die "unknown EDAUTILS_SOURCE '$src'" ;; esac [ -n "$url" ] || continue say "Trying $src: $url" case "$url" in *.zip) ext=zip ;; *) ext=tar.gz ;; esac if fetch "$url" "$tmp/$tool.$ext"; then if [ "$ext" = zip ]; then unzip -tq "$tmp/$tool.$ext" >/dev/null 2>&1 && { ok="$src"; break; } else tar tzf "$tmp/$tool.$ext" >/dev/null 2>&1 && { ok="$src"; break; }; fi fi done [ -n "$ok" ] || die "no source had a bundle for '$tool' (tried: ${EDAUTILS_SOURCE:-edautils github sourceforge})" mkdir -p "$dest" if [ "$ext" = zip ]; then unzip -oq "$tmp/$tool.zip" -d "$dest" else tar xzf "$tmp/$tool.tar.gz" -C "$dest" --strip-components=1 2>/dev/null \ || tar xzf "$tmp/$tool.tar.gz" -C "$dest" fi say "Installed $tool -> $dest (from $ok)" bindir=$(find "$dest" -maxdepth 2 -type d -name bin | head -1) [ -n "$bindir" ] && echo "export PATH=\"$bindir:\$PATH\"" } [ $# -gt 0 ] || die "usage: install.sh [...] | --list" command -v java >/dev/null 2>&1 || say "warning: java not found on PATH; the tools need Java 8 or newer" if [ "$1" = "--list" ]; then list_tools; exit 0; fi say "Add the printed export line(s) to your shell profile:" for t in "$@"; do install_one "$t"; done