Skip to content

Commit

Permalink
change all chmod/chown calls to fs-own
Browse files Browse the repository at this point in the history
this solves cross-os compatibility differences, such as macos not supporting `--`, or `root:admin` being used when that is platform specific and `--root` or `--admin` is better
- /ref https://github.com/bevry/dorothy/actions/runs/13093354709

this commit also includes:
- fix `--code-notice` failures, replaced it with appropriate styles that do exit
- fix `setup-bin` crashing on permission failures, instead report them and continue
  • Loading branch information
balupton committed Feb 2, 2025
1 parent ab1205b commit f27c015
Show file tree
Hide file tree
Showing 28 changed files with 263 additions and 245 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Now that the prerequisites are installed, Dorothy's intelligent dependency manag
- [`grep`](https://release-monitoring.org/project/1251/), [`git`](https://git-scm.com/downloads), [`awk`](https://release-monitoring.org/project/868/): required for installation
- [`jq`](https://jqlang.github.io/jq/download/), [`deno`](https://deno.com/#installation): required for advanced configuration and regular expression processing

If the automated installation of any failed, [post an issue](https://github.com/bevry/dorothy/issues) including details of your environment, and use their links for alternative installation methods. If you are downloading their binaries straight from GitHub, you can unzip with `tar -xvf <archive>`, make a discoverable binary directory with `mkdir -p -- ~/.local/bin`, move the binary there with `mv -- <bin> ~/.local/bin`, and make the binaries executable with `chmod +x -- ~/.local/bin/*`.
If the automated installation of any failed, [post an issue](https://github.com/bevry/dorothy/issues) including details of your environment, and use their links for alternative installation methods. If you are downloading their binaries straight from GitHub, you can unzip with `tar -xvf <archive>`, make a discoverable binary directory with `mkdir -p -- ~/.local/bin`, move the binary there with `mv -- <bin> ~/.local/bin`, and make the binaries executable with `chmod +x ~/.local/bin/*`.

### Try

Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-if-executable
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function echo_if_executable_test() (

eval-tester --name='symlink file' \
-- echo-if-executable -- "$file_symlink"
fs-own --quiet --permissions='+x' -- "$file_target"
fs-own --quiet --x -- "$file_target"
eval-tester --name='symlink file' --stdout="$file_symlink" \
-- echo-if-executable -- "$file_symlink"

Expand Down
9 changes: 4 additions & 5 deletions commands.beta/setup-server
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ function setup_server() (
# apply
if [[ ${#paths[@]} -ne 0 ]]; then
eval-helper --no-quiet --wrap -- \
fs-own --sudo --optional --permissions="$perms" --user="$SHARE_USER" --group="$SHARE_GROUP" \
-- "${paths[@]}"
fs-own --optional --permissions="$perms" --user="$SHARE_USER" --group="$SHARE_GROUP" --recursive -- "${paths[@]}"
else
echo-style --notice='No service configurations found yet.'
fi
Expand Down Expand Up @@ -378,7 +377,7 @@ function setup_server() (
fi

# attach the group to the executable
fs-own --sudo --optional --permissions='g+rx' --group="$SHARE_GROUP" -- "$temp"
fs-own --optional --permissions='g+rx' --group="$SHARE_GROUP" --recursive -- "$temp"
fi
}

Expand Down Expand Up @@ -659,7 +658,7 @@ function setup_server() (
# volumes
if is-not-directory --user="$SHARE_USER" --group="$SHARE_GROUP" -- '/Volumes'; then
sudo-helper -- mkdir -p -- '/Volumes'
fs-own --sudo --user="$SHARE_USER" --group="$SHARE_GROUP" -- '/Volumes'
fs-own --user="$SHARE_USER" --group="$SHARE_GROUP" --no-recursive -- '/Volumes'
fi

# drive
Expand All @@ -674,7 +673,7 @@ function setup_server() (
vault_share="$(get-flag-value share -- "${VAULT_MOUNT[@]}")"
if [[ -n $vault_share ]] && is-missing --user="$SHARE_USER" --group="$SHARE_GROUP" -- "$vault_share"; then
gocryptfs-helper new -- "$vault_share"
fs-own --sudo --user="$SHARE_USER" --group="$SHARE_GROUP" -- "$vault_share"
fs-own --user="$SHARE_USER" --group="$SHARE_GROUP" --recursive -- "$vault_share"
fi
eval-helper --no-quiet --wrap --shapeshifter \
-- mount-helper "${VAULT_MOUNT[@]}" "${OWNER_MOUNT[@]}" --mount
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/video-merge
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function video_merge() (

# check if the output file already exists, if it does, prompt for removal otherwise fail
if is-present -- "$output"; then
if confirm --linger --positive --ppid=$$ -- "The output file already exists, remove it?" "$(echo-style --code_notice="$output")"; then
if confirm --linger --positive --ppid=$$ -- 'The output file already exists, remove it?' "$(echo-style --code="$output")"; then
rm -f -- "$output"
else
help "The output file already exists: $output"
Expand Down
3 changes: 1 addition & 2 deletions commands/alias-helper
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ function alias_helper() (
EOF

# make the alias's permissions the same as the target's
chmod "$(stat -f '%p' -- "$target_absolute")" -- "$path_absolute"
#chmod --reference="$targetPath" -- "$path_absolute"
fs-own --reference="$target_absolute" -- "$path_absolute"
}

function do_symlink {
Expand Down
10 changes: 5 additions & 5 deletions commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,10 @@ function dorothy_() (

function make_executable {
# makes sure chmod isn't running on nothing, which can happen upon initial user installs
# dorothy may not have been loaded yet
if [[ $# -ne 0 ]]; then
chmod -f +x -- "$@"
# macos chmod doesn't support [--] as such don't both with it for linux either
chmod -f +x "$@"
fi
}

Expand Down Expand Up @@ -809,8 +811,7 @@ function dorothy_() (

function correct_permissions {
# make everything readable and writable, make directories accessible
fs-own --changes --optional --permissions='+rwX' \
-- "$DOROTHY"
fs-own --permissions='+Xrw' --optional --recursive -- "$DOROTHY"
# make commands executable
local commands
commands=(
Expand All @@ -821,8 +822,7 @@ function dorothy_() (
"$DOROTHY/user/commands.local/"*
"$DOROTHY/themes/oz"
)
fs-own --changes --no-recursive --permissions='+x' \
-- "${commands[@]}"
fs-own --x -- "${commands[@]}"
}

function ensure_permissions_configured {
Expand Down
Loading

0 comments on commit f27c015

Please sign in to comment.