Skip to content

Commit

Permalink
New EXTRACT command (#50)
Browse files Browse the repository at this point in the history
The EXTRACT command can be used to copy files back from the guest to the host; the counterpart of INSTALL.

Co-authored-by: Alvar Penning <[email protected]>
  • Loading branch information
sensslen and oxzi authored Jan 17, 2022
1 parent 60fe8e8 commit fb9cd12
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- New `ENV` command for environment variables.
- New `EXTRACT` command to copy files back to the host; @sensslen.

## [0.4.4] - 2021-11-09
### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ The included file _has_ to have a `.Pifile` extension which need not be specifie
`INSTALL` installs a given file or directory into the destination in the image.
The optionally permission mode (*chmod*) can be set as the first parameter.

#### `EXTRACT SOURCE DEST`
`EXTRACT` copies a given file or directory from the image to the destination.

#### `PATH /my/guest/path`
`PATH` adds the given path to an overlaying PATH variable, used within the `RUN` command.

Expand Down
4 changes: 4 additions & 0 deletions examples/RPi-OpenWRT.Pifile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ INSTALL "README.md" "/tmp/"
WORKDIR /tmp
RUN head -n1 "README.md"

# test if EXTRACT works
RUN sh -c 'echo "hello from within the guest" > /tmp/hello'
EXTRACT "/tmp/hello" "./hello"

# test an INCLUDE - both with and without the .Pifile extension
INCLUDE examples/Module-Hello.Pifile
INCLUDE examples/Module-Hello
Expand Down
4 changes: 4 additions & 0 deletions stages/00-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ INSTALL() {
:
}

EXTRACT() {
:
}

PATH() {
:
}
Expand Down
16 changes: 16 additions & 0 deletions stages/30-chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ INSTALL() {
fi
}

# EXTRACT copies a given file or directory from the image to the destination.
#
# Usage: EXTRACT SOURCE DEST
EXTRACT() {
echo -e "\033[0;32m### EXTRACT $*\033[0m"

local src="${CHROOT_MOUNT}/$1"
local dst=$2

if [[ -d "${src}" ]]; then
cp -r -T -P --preserve=mode "${src}" "${dst}"
else
cp -r -P --preserve=mode "${src}" "${dst}"
fi
}

# PATH adds the given path to an overlaying PATH variable, used within the RUN
# command.
#
Expand Down

0 comments on commit fb9cd12

Please sign in to comment.