Skip to content

Commit b3a52da

Browse files
Merge pull request #79 from richardkoehler/fix/install-sh-linux-executable
Fix: install of sh linux executable
2 parents 195191e + f072784 commit b3a52da

3 files changed

Lines changed: 41 additions & 47 deletions

File tree

newsfragments/79.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `scripts/install.sh` for POSIX `sh` and Linux launcher paths (`bin/`, `dbs_annotator`).

scripts/install.sh

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
#!/usr/bin/env bash
2-
# Install DBSAnnotator from GitHub Releases (Linux x86_64 or macOS).
3-
# Prefer official raw .tar.gz; else .deb (Linux) or .dmg (macOS).
4-
#
5-
# curl -LsSf https://raw.githubusercontent.com/Brain-Modulation-Lab/DBSAnnotator/main/scripts/install.sh | sh
6-
# wget -qO- https://raw.githubusercontent.com/Brain-Modulation-Lab/DBSAnnotator/main/scripts/install.sh | sh
7-
# DBS_ANNOTATOR_VERSION=v0.4.0a1 sh install.sh
8-
#
9-
# Env: DBS_ANNOTATOR_INSTALL_REPO (default Brain-Modulation-Lab/DBSAnnotator)
10-
# GITHUB_TOKEN (optional) for higher API rate limit
11-
12-
set -euo pipefail
1+
#!/bin/sh
2+
set -eu
133

144
REPO="${DBS_ANNOTATOR_INSTALL_REPO:-Brain-Modulation-Lab/DBSAnnotator}"
155
UA="DBSAnnotator-Unix-Install/1.0 (+https://github.com/${REPO})"
@@ -59,9 +49,7 @@ download() {
5949
fi
6050
}
6151

62-
# Prints two lines: KIND (tar|deb|dmg) and URL
6352
resolve_asset() {
64-
# shellcheck disable=SC2016
6553
VER_TAG="${VER_TAG:-}" python3 <<'PY'
6654
import os, re, sys, urllib.request, urllib.parse
6755
@@ -137,13 +125,35 @@ main()
137125
PY
138126
}
139127

128+
linux_pick_exe() {
129+
_p=$1
130+
for _n in dbs-annotator dbs_annotator DBSAnnotator; do
131+
for _d in "$_p/src" "$_p/bin" "$_p"; do
132+
_c="$_d/$_n"
133+
if [ -f "$_c" ] || [ -L "$_c" ]; then
134+
[ -x "$_c" ] || chmod u+x "$_c" 2>/dev/null || true
135+
if [ -x "$_c" ]; then
136+
echo "$_c"
137+
return 0
138+
fi
139+
fi
140+
done
141+
done
142+
_f=$(find "$_p" -type f \( -name dbs-annotator -o -name dbs_annotator -o -name DBSAnnotator \) 2>/dev/null | head -n 1) || true
143+
if [ -n "$_f" ]; then
144+
[ -x "$_f" ] || chmod u+x "$_f" 2>/dev/null || true
145+
fi
146+
if [ -n "$_f" ] && [ -x "$_f" ]; then
147+
echo "$_f"
148+
fi
149+
return 0
150+
}
151+
140152
install_mac_tar() {
141-
local archive=$1
142153
work=$(mktemp -d)
143-
# shellcheck disable=SC2064
144-
trap "rm -rf $work" EXIT
145-
tar -xzf "$archive" -C "$work"
146-
app=$(find "$work" -name "DBSAnnotator.app" -type d | head -1)
154+
trap 'rm -rf -- "$work"' EXIT
155+
tar -xzf "$1" -C "$work"
156+
app=$(find "$work" -name "DBSAnnotator.app" -type d | head -n 1)
147157
if [ -z "$app" ]; then
148158
echo "DBSAnnotator.app not in archive" >&2; exit 1
149159
fi
@@ -164,10 +174,9 @@ install_mac_tar() {
164174
}
165175

166176
install_mac_dmg() {
167-
local dmg=$1
168177
mp=$(mktemp -d "${TMPDIR:-/tmp}/dbs-dmg-XXXXXX")
169-
hdiutil attach -nobrowse -mountpoint "$mp" "$dmg"
170-
a=$(find "$mp" -name "DBSAnnotator.app" -type d -maxdepth 5 | head -1)
178+
hdiutil attach -nobrowse -mountpoint "$mp" "$1"
179+
a=$(find "$mp" -name "DBSAnnotator.app" -type d -maxdepth 5 | head -n 1)
171180
if [ -z "$a" ]; then
172181
hdiutil detach "$mp" 2>/dev/null || true
173182
echo "DBSAnnotator.app not in DMG" >&2; exit 1
@@ -185,16 +194,14 @@ install_mac_dmg() {
185194
}
186195

187196
install_linux_tar() {
188-
local archive=$1
189197
prefix=${INSTALL_PREFIX:-"$HOME/.local/lib/dbs-annotator"}
190198
work=$(mktemp -d)
191-
# shellcheck disable=SC2064
192-
trap "rm -rf $work" EXIT
193-
tar -xzf "$archive" -C "$work"
199+
trap 'rm -rf -- "$work"' EXIT
200+
tar -xzf "$1" -C "$work"
194201
if [ -d "$work/app" ]; then
195202
src="$work/app"
196203
else
197-
src=$(find "$work" -type d -name app | head -1)
204+
src=$(find "$work" -type d -name app | head -n 1)
198205
fi
199206
if [ -z "$src" ] || [ ! -d "$src" ]; then
200207
echo "Expected app/ tree in archive" >&2; exit 1
@@ -204,13 +211,7 @@ install_linux_tar() {
204211
mv "$src" "$prefix"
205212
bin_dir="${HOME}/.local/bin"
206213
mkdir -p "$bin_dir"
207-
exe=
208-
for n in dbs-annotator DBSAnnotator; do
209-
if [ -f "$prefix/src/$n" ]; then exe="$prefix/src/$n"; break; fi
210-
done
211-
if [ -z "$exe" ]; then
212-
exe=$(find "$prefix" -type f \( -name dbs-annotator -o -name DBSAnnotator \) -perm -u+x 2>/dev/null | head -1) || true
213-
fi
214+
exe=$(linux_pick_exe "$prefix")
214215
if [ -z "$exe" ] || [ ! -x "$exe" ]; then
215216
echo "Could not find executable under $prefix" >&2; exit 1
216217
fi
@@ -223,14 +224,13 @@ install_linux_tar() {
223224
}
224225

225226
install_linux_deb() {
226-
local deb=$1
227227
if [ "$(id -u)" = 0 ]; then
228-
dpkg -i "$deb" || apt-get install -f -y
228+
dpkg -i "$1" || apt-get install -f -y
229229
else
230230
if ! command -v sudo >/dev/null 2>&1; then
231231
echo "Need root or sudo to install .deb" >&2; exit 1
232232
fi
233-
sudo dpkg -i "$deb" || sudo apt-get install -f -y
233+
sudo dpkg -i "$1" || sudo apt-get install -f -y
234234
fi
235235
echo "Installed system package from .deb"
236236
}
@@ -239,8 +239,8 @@ main() {
239239
if ! out=$(resolve_asset); then
240240
exit 1
241241
fi
242-
_kind=$(printf '%s' "$out" | head -n1)
243-
_url=$(printf '%s' "$out" | tail -n1)
242+
_kind=$(printf '%s' "$out" | head -n 1)
243+
_url=$(printf '%s' "$out" | tail -n 1)
244244

245245
if [ "$DRY_RUN" = 1 ]; then
246246
echo "Would install: kind=$_kind"
@@ -269,4 +269,4 @@ main() {
269269
esac
270270
rm -f "$tmp"
271271
}
272-
main
272+
main

settings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)