#!/bin/sh # Installs Woolshed, or updates it: # # curl -fsSL https://woolshed.dev/releases/app/install.sh | sh # # Linux: the app into ~/.local/share/woolshed, `woolshed` in ~/.local/bin, # a launcher entry and icon. macOS: Woolshed.app into ~/Applications, keeping # its release signature intact (ad hoc for unsigned/dev builds). The core # (Woolshed Core) comes inside the app: when Woolshed opens, it installs the # core from there (`hc` in ~/.local/bin), with no second download, and keeps # it current with each app update. Running this again updates the app. # WOOLSHED_CHANNEL=beta installs the newest beta (to keep getting betas, pick # Beta in Settings > Updates > Channel). WOOLSHED_RELEASES_URL points the download # elsewhere (tests). set -eu releases=${WOOLSHED_RELEASES_URL:-https://woolshed.dev/releases} # Hatchify's Apple team: a Mac app signed by any other Developer ID is refused. team=3QUCG7B9B4 bin="$HOME/.local/bin" say() { printf '%s\n' "$*"; } fail() { say "woolshed: $*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || fail "needs $1"; } need curl need tar case "$(uname -s)" in Linux) os=linux ;; Darwin) os=macos ;; MINGW* | MSYS* | CYGWIN*) fail "this installer is for Linux and macOS; on Windows, run this in PowerShell: irm $releases/app/install.ps1 | iex" ;; *) fail "no build for $(uname -s)" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=x86_64 ;; arm64 | aarch64) arch=aarch64 ;; *) fail "no build for $(uname -m)" ;; esac if [ "$os" = macos ] && [ "$arch" = x86_64 ]; then # Rosetta reports x86_64 even on Apple Silicon: that Mac gets the native build. if [ "$(sysctl -n hw.optional.arm64 2>/dev/null || true)" = 1 ] || [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || true)" = 1 ]; then arch=aarch64 fi fi target="$os-$arch" sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 else shasum -a 256 "$1" | cut -d' ' -f1; fi } tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT feed=latest.json case ${WOOLSHED_CHANNEL:-stable} in stable) ;; beta) feed=beta.json ;; *) fail "WOOLSHED_CHANNEL is stable or beta" ;; esac # No beta out yet: the newest stable release is the newest of all. if [ "$feed" = beta.json ] && curl -fsSL "$releases/app/beta.json" -o "$tmp/latest.json" 2>/dev/null; then : else curl -fsSL "$releases/app/latest.json" -o "$tmp/latest.json" || fail "cannot reach $releases" fi # Read without jq: the manifest is flat enough for sed once spaces are gone. entry=$(tr -d '\n ' < "$tmp/latest.json" | sed -n "s/.*\"$target\":{\([^}]*\)}.*/\1/p") url=$(printf '%s' "$entry" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p') want=$(printf '%s' "$entry" | sed -n 's/.*"sha256":"\([^"]*\)".*/\1/p') version=$(tr -d '\n ' < "$tmp/latest.json" | sed -n 's/^{"version":"\([^"]*\)".*/\1/p') [ -n "$url" ] && [ -n "$want" ] || fail "no build for $target yet" # Tells the release server's download counter a new install from a reinstall; # the file is the same either way. Only plain URLs on the release server in # use are marked: one with a query or fragment (a mirror's signed URL) is # fetched exactly as the manifest gives it. src=install for have in "${XDG_DATA_HOME:-$HOME/.local/share}/woolshed" "$HOME/Applications/Woolshed.app" /Applications/Woolshed.app; do if [ -e "$have" ]; then src=reinstall; fi done case $url in *[?#]*) download=$url ;; "$releases"/*) download="$url?src=$src" ;; *) download=$url ;; esac say "Installing Woolshed ${version:-} for $target..." curl -fsSL "$download" -o "$tmp/app.tar.gz" || fail "download failed" [ "$(sha256 "$tmp/app.tar.gz")" = "$want" ] || fail "download is damaged (checksum mismatch); try again" tar -xzf "$tmp/app.tar.gz" -C "$tmp" mkdir -p "$bin" if [ "$os" = linux ]; then data=${XDG_DATA_HOME:-$HOME/.local/share} home="$data/woolshed" mkdir -p "$data" rm -rf "$home.new" mv "$tmp/woolshed" "$home.new" rm -rf "$home" mv "$home.new" "$home" ln -sfn "$home/woolshed" "$bin/woolshed" mkdir -p "$data/applications" "$data/icons/hicolor/scalable/apps" cp "$home/woolshed.svg" "$data/icons/hicolor/scalable/apps/woolshed.svg" cat > "$data/applications/woolshed.desktop" </dev/null 2>&1 && update-desktop-database "$data/applications" 2>/dev/null || true [ -f "$data/icons/hicolor/icon-theme.cache" ] && gtk-update-icon-cache -f -t "$data/icons/hicolor" >/dev/null 2>&1 || true else apps="$HOME/Applications" app="$apps/Woolshed.app" mkdir -p "$apps" # Prepared in the temp folder, so Spotlight never indexes a half-made # bundle under a temporary name in Applications. # Never change a certificate-signed bundle: macOS permissions follow its # signing identity. Only unsigned/ad-hoc development builds need this PATH. signed=false if signature=$(/usr/bin/codesign -dvv "$tmp/Woolshed.app" 2>&1); then if printf '%s\n' "$signature" | grep -q '^Authority=Developer ID Application:'; then printf '%s\n' "$signature" | grep -qx "TeamIdentifier=$team" && printf '%s\n' "$signature" | grep -q "^Authority=Developer ID Application: .*($team)\$" || fail "the app isn't signed by Woolshed's publisher: $signature" signed=true elif ! printf '%s\n' "$signature" | grep -qx 'Signature=adhoc'; then fail "cannot determine app signature: $signature" fi elif ! printf '%s\n' "$signature" | grep -q ': code object is not signed at all$'; then fail "cannot determine app signature: $signature" fi if [ "$signed" = true ]; then /usr/bin/codesign --verify --deep --strict "$tmp/Woolshed.app" || fail "invalid app signature" else /usr/libexec/PlistBuddy -c "Add :LSEnvironment:PATH string $bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin" "$tmp/Woolshed.app/Contents/Info.plist" /usr/bin/codesign --force --sign - "$tmp/Woolshed.app" >/dev/null 2>&1 fi rm -rf "$app" mv "$tmp/Woolshed.app" "$app" ln -sfn "$app/Contents/MacOS/Woolshed" "$bin/woolshed" /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$app" 2>/dev/null || true fi say "Woolshed is installed. Open it from your apps, or run: woolshed" case ":$PATH:" in *":$bin:"*) ;; *) say "Add $bin to your PATH to use woolshed and hc from a terminal." ;; esac