Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle realpath in makerootfs.sh sanely #3274

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ Make sure that Docker is up and running on your system. On MacOS just start a do
docker version
```

#### Get system dependencies (git, make, qemu, jq, gnu-sed, coreutils)
#### Get system dependencies (git, make, qemu, jq, gnu-sed)

##### On OSX (using [Brew](https://brew.sh/))

```sh
$ brew install git make jq qemu gnu-sed coreutils
$ brew install git make jq qemu gnu-sed
```

> **_NOTE:_** (M1 Macs) `qemu` may also require `python3 nettle ninja` to install properly, that is:
>
> ```sh
> $ brew install git make jq python3 nettle ninja qemu gnu-sed coreutils
> $ brew install git make jq python3 nettle ninja qemu gnu-sed
> ```

##### On Ubuntu Linux
Expand Down
35 changes: 31 additions & 4 deletions tools/makerootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ do_imagefromtar() {
cat "${tarfile}" | docker run -i --rm -v /dev:/dev --privileged -v "$IMAGE:/rootfs.img" "${MKROOTFS_TAG}"
}

abspath() {
local target
local dir
local filename
local absolute_dir

target="$1"
if [ -z "$target" ]; then
echo "Error: Unable to find file '$target'" >&2
return 1
fi
# we have two problems here:
# First, we want to realpath a file that may not exist yet.
# on some OSes, it is fine; on others, it returns an error.
# a prerequisite is that the directory exists, so we can realpath that,
# and just append the filename after.
# Second, we want to use realpath, but it is not available on all OSes.
dir=$(dirname "$target")
filename=$(basename "$target")
if [ ! -d "$dir" ]; then
echo "Error: Unable to find directory '$dir'" >&2
return 1
fi
absolute_dir=$(cd "$dir"; pwd -P)
echo "${absolute_dir}/${filename}"
}

bail() {
echo "$@" >&2
help
Expand Down Expand Up @@ -89,10 +116,10 @@ while getopts "t:i:a:f:y:d:h" o
do
case $o in
t)
tarfile=$(realpath "$OPTARG")
tarfile=$(abspath "$OPTARG")
;;
i)
imgfile=$(realpath "$OPTARG")
imgfile=$(abspath "$OPTARG")
;;
a)
arch="$OPTARG"
Expand All @@ -101,10 +128,10 @@ do
format="$OPTARG"
;;
y)
ymlfile=$(realpath "$OPTARG")
ymlfile=$(abspath "$OPTARG")
;;
d)
execdir=$(realpath "$OPTARG")
execdir=$(abspath "$OPTARG")
;;
h)
help
Expand Down