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

[enh] add xz decompression for sources #1785

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Depends: ${python3:Depends}, ${misc:Depends}
, rspamd, opendkim-tools, postsrsd, procmail, mailutils
, redis-server
, acl
, git, curl, wget, cron, unzip, jq, bc, at, procps
, git, curl, wget, cron, unzip, jq, bc, at, procps, tar, gzip, bzip2, xz-utils
, lsb-release, haveged, fake-hwclock, equivs, lsof, whois
Recommends: yunohost-admin
, ntp, inetutils-ping | iputils-ping
Expand Down
46 changes: 33 additions & 13 deletions helpers/utils
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,22 @@ fi
# ```text
# format = "tar.gz"/xz/bz2 # automatically guessed from the extension of the URL, but can be set explicitly. Will use `tar` to extract
# "zip" # automatically guessed from the extension of the URL, but can be set explicitly. Will use `unzip` to extract
# "gz" # automatically guessed from the extension of the URL, but can be set explicitly. Will use `gunzip` to extract
# "bz2" # automatically guessed from the extension of the URL, but can be set explicitly. Will use `bunzip2` to extract
# "xz" # automatically guessed from the extension of the URL, but can be set explicitly. Will use `xz -d` to extract
# "docker" # useful to extract files from an already-built docker image (instead of rebuilding them locally). Will use `docker-image-extract` to extract
# "whatever" # an arbitrary value, not really meaningful except to imply that the file won't be extracted
#
# in_subdir = true # default, there's an intermediate subdir in the archive before accessing the actual files
# false # sources are directly in the archive root
# n # (special cases) an integer representing a number of subdirs levels to get rid of
#
# extract = true # default if file is indeed an archive such as .zip, .tar.gz, .tar.bz2, ...
# extract = true # default if file is indeed an archive such as .zip, .tar.gz, .tar.bz2, gz, ...
# = false # default if file 'format' is not set and the file is not to be extracted because it is not an archive but a script or binary or whatever asset.
# # in which case the file will only be `mv`ed to the location possibly renamed using the `rename` value
#
# rename = "whatever_your_want" # to be used for convenience when `extract` is false and the default name of the file is not practical
# # also used for single file archives (gz, bz2, xz) to rename the extracted file (default : the source id, or the app name for main source)
# platform = "linux/amd64" # (defaults to "linux/$YNH_ARCH") to be used in conjonction with `format = "docker"` to specify which architecture to extract for
# ```
#
Expand Down Expand Up @@ -187,22 +191,22 @@ ynh_setup_source() {
[[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?"

if [[ -z "$src_format" ]]
then
if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]]
then
if [[ -z "$src_format" ]]; then
if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]]; then
src_format="zip"
elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]]
then
elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]]; then
src_format="tar.gz"
elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]]
then
elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]]; then
src_format="tar.xz"
elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]
then
elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]; then
src_format="tar.bz2"
elif [[ -z "$src_extract" ]]
then
elif [[ "$src_url" =~ ^.*\.gz$ ]]; then
src_format="gz"
elif [[ "$src_url" =~ ^.*\.xz$ ]]; then
src_format="xz"
elif [[ "$src_url" =~ ^.*\.bz2$ ]]; then
src_format="bz2"
elif [[ -z "$src_extract" ]]; then
src_extract="false"
fi
fi
Expand Down Expand Up @@ -329,6 +333,22 @@ ynh_setup_source() {
unzip -quo $src_filename -d "$dest_dir"
fi
ynh_secure_remove --file="$src_filename"
elif [[ "$src_format" =~ ^gz|xz|bz2$ ]]; then
if [[ -z "$src_rename" ]]; then
if [[ "$source_id" == "main" ]]; then
local src_rename=$app
Comment on lines +338 to +339
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused by this because this will lead to inconsistent behavior between this case and other case (where the main source is just kept as "main" and not "$app") x_X ... What's the rationale for this ?

Copy link
Author

Choose a reason for hiding this comment

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

The goal is to allow the omission of rename in resource definition. (I just remember, writing this line, I've mentioned to set rename in the «how to test» section of this PR 🥴)

In the the forgejo app case, I thought it was logical to extract the archive to the same name as the application one.

else
local src_rename=$source_id
fi
fi
if [[ "$src_format" == "gz" ]]; then
gunzip --stdout $src_filename > "$dest_dir/$src_rename"
elif [[ "$src_format" == "xz" ]]; then
xz -d --stdout $src_filename > "$dest_dir/$src_rename"
elif [[ "$src_format" == "bz2" ]]; then
bunzip2 --stdout $src_filename > "$dest_dir/$src_rename"
fi
_ynh_apply_default_permissions "$dest_dir/$src_rename"
else
local strip=""
if [ "$src_in_subdir" != "false" ]; then
Expand Down
3 changes: 3 additions & 0 deletions src/utils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ class SourcesResource(AppResource):
- `format` : The "format" of the asset. It is typically automatically guessed from the extension of the URL (or the mention of "tarball", "zipball" in the URL), but can be set explicitly:
- `tar.gz`, `tar.xz`, `tar.bz2` : will use `tar` to extract the archive
- `zip` : will use `unzip` to extract the archive
- `gz` : will use `gunzip` to extract
- `bz2` : will use `bunzip2` to extract
- `xz` : will use `xz -d` to extract
- `docker` : useful to extract files from an already-built docker image (instead of rebuilding them locally). Will use `docker-image-extract`
- `whatever`: whatever arbitrary value, not really meaningful except to imply that the file won't be extracted (eg because it's a .deb to be manually installed with dpkg/apt, or a script, or ...)
- `in_subdir`: `true` (default) or `false`, depending on if there's an intermediate subdir in the archive before accessing the actual files. Can also be `N` (an integer) to handle special cases where there's `N` level of subdir to get rid of to actually access the files
Expand Down