modified scripts/install.sh +14 -2
| @@ -39,9 +39,21 @@ home="$prefix/lib/razorbill" |
| 39 | 39 | launcher="$prefix/bin/rzb" |
| 40 | 40 | marker="# razorbill launcher (scripts/install.sh)" |
| 41 | 41 | |
| 42 | | -# Runs a command with sudo only when the prefix cannot be written as the current user. |
| 42 | +# True when the current user can create, replace and remove everything the install touches: |
| 43 | +# each target (or its nearest existing parent) is writable, and nothing inside an installed |
| 44 | +# razorbill folder belongs to someone else (e.g. root, after an install run with sudo). |
| 45 | +writable_as_user() { |
| 46 | + local path |
| 47 | + for path in "$prefix/lib" "$prefix/bin" "$home" "$launcher"; do |
| 48 | + while [[ ! -e "$path" ]]; do path=$(dirname "$path"); done |
| 49 | + [[ -w "$path" ]] || return 1 |
| 50 | + done |
| 51 | + [[ ! -d "$home" || -z "$(find "$home" ! -user "$(id -u)" -print -quit)" ]] |
| 52 | +} |
| 53 | + |
| 54 | +# Runs a command with sudo only when the current user cannot do it (sudo asks for the password). |
| 43 | 55 | as_owner() { |
| 44 | | - if mkdir -p "$prefix" 2>/dev/null && [[ -w "$prefix" ]]; then "$@"; else sudo "$@"; fi |
| 56 | + if writable_as_user; then "$@"; else sudo "$@"; fi |
| 45 | 57 | } |
| 46 | 58 | |
| 47 | 59 | # Refuses to overwrite or remove an rzb this script did not install. |
| @@ -39,9 +39,21 @@ home="$prefix/lib/razorbill" |
| 39 | launcher="$prefix/bin/rzb" | 39 | launcher="$prefix/bin/rzb" |
| 40 | marker="# razorbill launcher (scripts/install.sh)" | 40 | marker="# razorbill launcher (scripts/install.sh)" |
| 41 | | 41 | |
| 42 | -# Runs a command with sudo only when the prefix cannot be written as the current user. | 42 | +# True when the current user can create, replace and remove everything the install touches: |
| | 43 | +# each target (or its nearest existing parent) is writable, and nothing inside an installed |
| | 44 | +# razorbill folder belongs to someone else (e.g. root, after an install run with sudo). |
| | 45 | +writable_as_user() { |
| | 46 | + local path |
| | 47 | + for path in "$prefix/lib" "$prefix/bin" "$home" "$launcher"; do |
| | 48 | + while [[ ! -e "$path" ]]; do path=$(dirname "$path"); done |
| | 49 | + [[ -w "$path" ]] || return 1 |
| | 50 | + done |
| | 51 | + [[ ! -d "$home" || -z "$(find "$home" ! -user "$(id -u)" -print -quit)" ]] |
| | 52 | +} |
| | 53 | + |
| | 54 | +# Runs a command with sudo only when the current user cannot do it (sudo asks for the password). |
| 43 | as_owner() { | 55 | as_owner() { |
| 44 | - if mkdir -p "$prefix" 2>/dev/null && [[ -w "$prefix" ]]; then "$@"; else sudo "$@"; fi | 56 | + if writable_as_user; then "$@"; else sudo "$@"; fi |
| 45 | } | 57 | } |
| 46 | | 58 | |
| 47 | # Refuses to overwrite or remove an rzb this script did not install. | 59 | # Refuses to overwrite or remove an rzb this script did not install. |