Skip to contentSkip to conversation

linguas: Ensure that scripts runs from the directory that it resides

PATCH Superseded Glenn Washburn 2 participants 4 messages Nov 9, 2025 – Nov 14, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linguas: Ensure that scripts runs from the directory that it resides

The script assumes that it is run from the root of the source tree, which is where it is located. So this should be enforced to prevent accidental misuses.

---
 linguas.sh | 5 +++++
 1 file changed, 5 insertions(+)
linguas.sh +5 -0
index b95ad4f7d9c2..45cdf2ac14ac 100755
@@ -1,5 +1,10 @@
 #!/bin/sh
 
+SDIR=$(realpath -e "$0")
+SDIR=${SDIR%/*}
+
+cd "$SDIR"
+
 rsync -Lrtvz translationproject.org::tp/latest/grub/ po
 
 autogenerated="en@quot en@hebrew de@hebrew en@cyrillic en@greek en@arabic en@piglatin de_CH"
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 14 lines · Glenn Washburn

The script assumes that it is run from the root of the source tree, which is where it is located. So this should be enforced to prevent accidental misuses.

---
 linguas.sh | 5 +++++
 1 file changed, 5 insertions(+)
linguas.sh +0 -0
index b95ad4f7d9c2..45cdf2ac14ac 100755

linguas.sh line 3

Quoted 3 lines
linguas.sh +1 -0
@@ -1,5 +1,10 @@
 #!/bin/sh
 
+SDIR=$(realpath -e "$0")

SDIR=$(readlink -f "$0")

linguas.sh line 4

Quoted 1 line
linguas.sh +1 -0
+SDIR=${SDIR%/*}

SDIR=$(dirname "$SDIR")

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 17 lines · On Wed, 12 Nov 2025 21:39:09 +0100 Daniel Kiper <[email protected]> wrote:
Quoted 16 lines · Glenn Washburn

The script assumes that it is run from the root of the source tree, which is where it is located. So this should be enforced to prevent accidental misuses.

---
 linguas.sh | 5 +++++
 1 file changed, 5 insertions(+)
linguas.sh +0 -0
index b95ad4f7d9c2..45cdf2ac14ac 100755
@@ -1,5 +1,10 @@
 #!/bin/sh
 
Quoted 3 lines

linguas.sh line 3

Quoted 1 line
linguas.sh +1 -0
+SDIR=$(realpath -e "$0")

SDIR=$(readlink -f "$0")

I'm curious, why do you prefer this? On Debian they both come from the coreutils package. They both resolve symlinks, so functionally I believe they are the same. According to the Debian readlink man page, "Note realpath(1) is the preferred command to use for canonicalization functionality." I find the name a little more intuitive, as we want the real path and the argument might not be a link to be read, which is what readlink suggests to me. Is readlink an older util, and thus more widely supported?

Quoted 4 lines

linguas.sh line 4

Quoted 2 lines
linguas.sh +1 -0
+SDIR=${SDIR%/*}

SDIR=$(dirname "$SDIR")

Also, why this is preferable? My guess is that it is more readable. I chose the pure shell approach because its one less exec and external binary dependency. That syntax is supported on both sh and dash, so I expect wide compatibility.

Glenn

Quoted 2 lines

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw
Quoted 22 lines · Glenn Washburn
Quoted 17 lines · On Wed, 12 Nov 2025 21:39:09 +0100 > Daniel Kiper <[email protected]> wrote:
Quoted 16 lines · Glenn Washburn

The script assumes that it is run from the root of the source tree, which is where it is located. So this should be enforced to prevent accidental misuses.

---
 linguas.sh | 5 +++++
 1 file changed, 5 insertions(+)
linguas.sh +0 -0
index b95ad4f7d9c2..45cdf2ac14ac 100755
@@ -1,5 +1,10 @@
 #!/bin/sh
 
Quoted 3 lines

linguas.sh line 3

Quoted 1 line
linguas.sh +1 -0
+SDIR=$(realpath -e "$0")

SDIR=$(readlink -f "$0")

Quoted 8 lines

I'm curious, why do you prefer this? On Debian they both come from the coreutils package. They both resolve symlinks, so functionally I believe they are the same. According to the Debian readlink man page, "Note realpath(1) is the preferred command to use for canonicalization functionality." I find the name a little more intuitive, as we want the real path and the argument might not be a link to be read, which is what readlink suggests to me. Is readlink an older util, and thus more widely supported?

When I was resolving the same problem years ago there wasn't such note in the readlink(1) man. However, if it is there right now then I think it makes more sense to use realpath instead. Though I think you should mention in the commit message why you chose it instead of readlink.

Quoted 6 lines
Quoted 3 lines

linguas.sh line 4

Quoted 1 line
linguas.sh +1 -0
+SDIR=${SDIR%/*}

SDIR=$(dirname "$SDIR")

Also, why this is preferable? My guess is that it is more readable. I chose the pure shell approach because its one less exec and

Yep...

Quoted 2 lines

external binary dependency. That syntax is supported on both sh and dash, so I expect wide compatibility.

I think it does not matter much here. However, if you prefer shell approach please explain your choice in the commit message.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel