Skip to content

Make clean.sh scripts executable from any directory#730

Merged
MakisH merged 4 commits into
precice:developfrom
Eshaan-byte:fix/clean-scripts-any-directory
Jul 2, 2026
Merged

Make clean.sh scripts executable from any directory#730
MakisH merged 4 commits into
precice:developfrom
Eshaan-byte:fix/clean-scripts-any-directory

Conversation

@Eshaan-byte

@Eshaan-byte Eshaan-byte commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends the fix from #716 to the remaining case-level clean.sh scripts and one non-symlinked clean-tutorial.sh.

  • Added SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" and cd "$SCRIPT_DIR" to all 111 case-level clean.sh files
  • Applied the same fix to partitioned-heat-conduction-direct/clean-tutorial.sh (real file, not a symlink, so Make clean-tutorial.sh executable from any directory #716 didn't cover it)
  • Added missing set -e -u to flow-around-controlled-moving-cylinder/solid-python/clean.sh for consistency

Closes #667

Test plan

  • Run ../clean-tutorial.sh from inside a case directory (e.g. quickstart/fluid-openfoam/)
  • Run ./fluid-openfoam/clean.sh from a tutorial directory (e.g. quickstart/)
  • Run clean-all.sh from the repository root
  • Verify all three work without errors

Checklist

  • I added a summary of any user-facing changes (compared to the last release) in the changelog-entries/<PRnumber>.md.
  • I will remember to squash-and-merge, providing a useful summary of the changes of this PR.

Extends the fix from precice#716 to the remaining case-level clean.sh
scripts and one non-symlinked clean-tutorial.sh.

- Added SCRIPT_DIR resolution and cd to all 111 case-level clean.sh
- Applied the same fix to partitioned-heat-conduction-direct/clean-tutorial.sh
- Added missing set -e -u to flow-around-controlled-moving-cylinder/solid-python/clean.sh

Closes precice#667
@MakisH MakisH added the GSoC Contributed in the context of the Google Summer of Code label Feb 27, 2026
@MakisH

MakisH commented Feb 27, 2026

Copy link
Copy Markdown
Member

Hi @Eshaan-byte,

Similar comment as in #716: We want to keep these files as slim as possible. Would it be possible to move this (or probably a similar hack) to ../tools/cleaning-tools.sh?

Also: No need for an issue before a PR, if the PR is anyway on the way.

@Eshaan-byte

Copy link
Copy Markdown
Contributor Author

Hi @MakisH, thanks for the review!

The challenge is that clean.sh sources cleaning-tools.sh via a relative path (../../tools/cleaning-tools.sh), which fails before cleaning-tools.sh even loads when called from a different directory.

A possible approach to keep clean.sh slim: change the source line to resolve from $0 instead of $PWD, and let cleaning-tools.sh handle the cd.

clean.sh (only the source line changes):
#!/usr/bin/env sh
set -e -u

. "$(dirname "$0")/../../tools/cleaning-tools.sh"

clean_openfoam .
cleaning-tools.sh (add at the top):

cd "$(cd "$(dirname "$0")" && pwd)"
This way no extra lines are added to clean.sh — it stays the same size. Would this approach work for you?

@PranjalManhgaye

PranjalManhgaye commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

Hi @Eshaan-byte , thanks for the suggestion ,i agree that resolving the source path using dirname "$0" fixes the issue locally.

In the final merged PR #716, i applied a similar idea but made it explicit in each script so they reliably determine their own directory before sourcing anything. This ensures all cleaning scripts are truly callable from any directory, not just when sourcing a helper file. That’s the pattern that got approved — scripts use:
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

idea was to make the files slim,
This avoids depending solely on the sourced file to set up the correct working directory and makes each script self-contained and robust across environments.
thanks you pointed ,

@MakisH MakisH left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the main usability issue was always with the clean-tutorial.sh (since one is typically inside a case directory, e.g., quickstart/fluid-openfoam and needs to call ../clean-tutorial.sh), this is still a welcome usability improvement.

I always wanted to have these scripts as slim as possible, but this is not a large addition either.

I tested calling the scripts from various locations, and I did not observe any issue.

I also ported the remaining/newer cases, and I will do further polishing in another PR.

Thanks again for contributing!

@MakisH MakisH merged commit 5a03067 into precice:develop Jul 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GSoC Contributed in the context of the Google Summer of Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleaning scripts are not callable from the root directory

3 participants