Skip to content

Commit

Permalink
fs-dequarantine, setup-util-brew: fix peculiarities
Browse files Browse the repository at this point in the history
- fs-dequarantine: no longer uses complex fallback method, and checks for approprite method first
- setup-util-brew: add debugging for unexpected environment configuration

```
xattr: /Users/runner/.local/bin/bash: No such xattr: com.apple.quarantine
The [bash] required utility was not upgraded via [download]
/Users/runner/.local/share/dorothy/commands/setup-util-brew: line 55: HOMEBREW_ARCH: unbound variable
```

> https://github.com/bevry/dorothy/actions/runs/7499530414/job/20416492860#step:3:32
  • Loading branch information
balupton committed Jan 12, 2024
1 parent ec31e38 commit 36790f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
24 changes: 13 additions & 11 deletions commands/fs-dequarantine
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ function fs_dequaratine() (
fi

function disable_quarantine_on_path {
local path="$1" output status cmd=('xattr')
# https://apple.stackexchange.com/a/436677/15131
# note that the -r option doesn't exist, will return [option -r not recognized] on Ventura and Sonoma
cmd+=('-d' 'com.apple.quarantine' "$path")
eval_capture --outputvar=output --statusvar=status -- "${cmd[@]}"
if test "$status" -eq 0 -o "$output" = 'No such xattr: com.apple.quarantine'; then
return 0
# cannot just -d directly, as will get a [No such xattr: com.apple.quarantine] error, so check for it first, this induces no errors
local path="$1"
if test -r "$path"; then
if xattr -l "$path" | grep --quiet --fixed-strings --regexp='com.apple.quarantine'; then
xattr -d com.apple.quarantine "$path" >/dev/stderr
return
fi
elif sudo-helper -- test -r "$path"; then
if sudo-helper -- xattr -l "$path" | grep --quiet --fixed-strings --regexp='com.apple.quarantine'; then
sudo-helper -- xattr -d com.apple.quarantine "$path" >/dev/stderr
return
fi
fi
eval_capture --outputvar=output --statusvar=status -- sudo-helper -- "${cmd[@]}"
if test "$status" -eq 0 -o "$output" = 'No such xattr: com.apple.quarantine'; then
return 0
fi
print_line "$output" >/dev/stderr
return "$status"
return 0
}

local path
Expand Down
20 changes: 12 additions & 8 deletions commands/setup-util-brew
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ function setup_util_brew() (
return 0
fi

# environment provides:
# HOMEBREW_ARCH, HOMEBREW_PREFIX
if test -z "${HOMEBREW_ARCH-}" -o -z "${HOMEBREW_PREFIX-}"; then
echo-error 'HOMEBREW_ARCH and HOMEBREW_PREFIX are missing, cannot setup brew, for some reason this was executed before the Dorothy environment was configured'
uname -a
uname -s
env >&2
return 6 # ENXIO 6 Device not configured
fi

# enable EVAL_INSTALL, etc
source "$(type -P setup-util)"

# uninstall brew, and adapt the system accordingly
function brew_uninstall {
# environment provides:
# HOMEBREW_ARCH, HOMEBREW_PREFIX
if test -z "${HOMEBREW_PREFIX-}"; then
echo-error 'HOMEBREW_PREFIX is not defined, cannot uninstall brew.'
return 6 # ENXIO 6 Device not configured
fi
local remove removals=(
"${HOMEBREW_PREFIX}/"*
/usr/local/*
Expand All @@ -37,7 +41,7 @@ function setup_util_brew() (

# uninstall brew
if is-brew; then
arch -"${HOMEBREW_ARCH}" /bin/bash -c "$(fetch https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force
arch "-${HOMEBREW_ARCH}" /bin/bash -c "$(fetch https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force
fi

# remove any leftover directories
Expand All @@ -53,7 +57,7 @@ function setup_util_brew() (
# https://github.com/balupton/dotfiles/commit/69dbbe81bf30f9e0d9a1dd1d00eca3f3c88b943b
function brew_install {
env HOMEBREW_NO_AUTO_UPDATE=1 \
arch -"${HOMEBREW_ARCH}" /bin/bash -c "$(fetch https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch "-${HOMEBREW_ARCH}" /bin/bash -c "$(fetch https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
source "$DOROTHY/sources/environment.sh" # child processes will also inherit these changes
}

Expand Down

0 comments on commit 36790f9

Please sign in to comment.