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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add bz2 and gzip source decompression
  • Loading branch information
emmanuel-averty committed Mar 13, 2024
commit aa64f07a3fbb62d9b566b6768015f552170ca29b
42 changes: 24 additions & 18 deletions helpers/utils
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,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 [[ "$src_url" =~ ^.*\.xz$ ]]
then
elif [[ "$src_url" =~ ^.*\.gz$ ]]; then
src_format="gz"
elif [[ "$src_url" =~ ^.*\.xz$ ]]; then
src_format="xz"
elif [[ -z "$src_extract" ]]
then
elif [[ "$src_url" =~ ^.*\.bz2$ ]]; then
src_format="bz2"
elif [[ -z "$src_extract" ]]; then
src_extract="false"
fi
fi
Expand Down Expand Up @@ -332,13 +329,22 @@ ynh_setup_source() {
unzip -quo $src_filename -d "$dest_dir"
fi
ynh_secure_remove --file="$src_filename"
elif [[ "$src_format" == "xz" ]]; then
elif [[ "$src_format" =~ ^gz|xz|bz2$ ]]; then
if [[ -z "$src_rename" ]]; then
xz -d --stdout $src_filename > "$dest_dir/$(basename $src_filename)"
else
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