diff --git a/install.sh b/install.sh index 0859220..79cbed3 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ # SPDX-License-Identifier: BSD-3-Clause # # This script installs the Brave browser using the OS's package manager -# Requires: coreutils, grep, sh, sudo/doas (except macOS) +# Requires: coreutils, grep, sh, sudo/doas # Source: https://github.com/brave/install.sh # Browser requirements @@ -36,7 +36,7 @@ main() { ## Find and/or install the necessary tools - if [ "$(id -u)" = 0 ] || [ "$os" = Darwin ]; then + if am_admin; then sudo="" elif available sudo; then sudo="sudo" @@ -111,19 +111,12 @@ main() { fi elif [ "$os" = Darwin ]; then - if available brew; then - NONINTERACTIVE=1 show brew install --cask brave-browser - echo "Installation complete! Start Brave by typing: open -a Brave\ Browser" - else - if available curl || available wget; then - dmg="$(mktemp ~/Downloads/Brave-Browser-XXXXXXXX.dmg)" - show $curl -L https://laptop-updates.brave.com/latest/osx >"${dmg:?}" - show open "$dmg" - else - show open https://laptop-updates.brave.com/latest/osx - fi - echo "Please follow the usual installation steps with the downloaded Brave-Browser.dmg" - fi + trap '[ -d /Volumes/Brave\ Browser ] && $sudo hdiutil detach -force -quiet /Volumes/Brave\ Browser' EXIT + show $sudo hdiutil attach -quiet https://laptop-updates.brave.com/latest/osx + show $sudo rsync -a --del /Volumes/Brave\ Browser/Brave\ Browser.app /Applications/ + show $sudo hdiutil detach -force -quiet /Volumes/Brave\ Browser || true + echo "Installation complete! Start Brave by typing: open -a Brave\ Browser" + exit else error "Could not find a supported package manager. Only apt, dnf, eopkg, paru/pikaur/yay, yum and zypper are supported." "" \ @@ -133,13 +126,12 @@ main() { "$(cat /etc/os-release || true)" fi - if [ "$os" != Darwin ]; then - printf "Installation complete! Start Brave by typing: " - basename "$(command -v brave-browser || command -v brave)" - fi + printf "Installation complete! Start Brave by typing: " + basename "$(command -v brave-browser || command -v brave)" } # Helpers +am_admin() { [ "$(id -u)" = 0 ] || ( [ "$os" = Darwin ] && id -Gn|grep -Fwq admin ); } available() { command -v "${1:?}" >/dev/null; } error() { exec >&2; printf "Error: "; printf "%s\n" "${@:?}"; exit 1; } newer() { [ "$(printf "%s\n%s" "$1" "$2"|sort -V|head -n1)" = "${2:?}" ]; }