mirror of
https://github.com/YunoHost-Apps/seafile_ynh.git
synced 2024-09-03 20:26:01 +02:00
Update helper setup source
This commit is contained in:
parent
db0c65931e
commit
eb0b904011
1 changed files with 73 additions and 103 deletions
|
@ -1,23 +1,20 @@
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch upstream sources
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 2.6.4 or higher.
|
# NOTE this is a full copy of upstream ynh_setup_source but with some specific patch releated to seafile docker archive
|
||||||
ynh_setup_source_custom() {
|
ynh_setup_source_custom() {
|
||||||
# Declare an array to define the options of this helper.
|
# ============ Argument parsing =============
|
||||||
local legacy_args=dsk
|
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace)
|
||||||
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=)
|
|
||||||
local dest_dir
|
local dest_dir
|
||||||
local source_id
|
local source_id
|
||||||
local keep
|
local keep
|
||||||
local full_replace
|
local full_replace
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
keep="${keep:-}"
|
keep="${keep:-}"
|
||||||
full_replace="${full_replace:-0}"
|
full_replace="${full_replace:-0}"
|
||||||
|
|
||||||
if test -e $YNH_APP_BASEDIR/manifest.toml && cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq -e '.resources.sources' >/dev/null
|
|
||||||
then
|
|
||||||
source_id="${source_id:-main}"
|
source_id="${source_id:-main}"
|
||||||
local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]")
|
# ===========================================
|
||||||
|
|
||||||
|
local sources_json=$(ynh_read_manifest "resources.sources[\"$source_id\"]")
|
||||||
if jq -re ".url" <<< "$sources_json"
|
if jq -re ".url" <<< "$sources_json"
|
||||||
then
|
then
|
||||||
local arch_prefix=""
|
local arch_prefix=""
|
||||||
|
@ -27,9 +24,9 @@ ynh_setup_source_custom() {
|
||||||
|
|
||||||
local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')"
|
local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')"
|
local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
local src_sumprg="sha256sum"
|
|
||||||
local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')"
|
local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')"
|
local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
|
src_in_subdir=${src_in_subdir:-true}
|
||||||
local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')"
|
local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')"
|
local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')"
|
local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')"
|
||||||
|
@ -51,30 +48,15 @@ ynh_setup_source_custom() {
|
||||||
elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]
|
elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]
|
||||||
then
|
then
|
||||||
src_format="tar.bz2"
|
src_format="tar.bz2"
|
||||||
|
elif [[ "$src_url" =~ ^.*\.tar$ ]]
|
||||||
|
then
|
||||||
|
src_format="tar"
|
||||||
elif [[ -z "$src_extract" ]]
|
elif [[ -z "$src_extract" ]]
|
||||||
then
|
then
|
||||||
src_extract="false"
|
src_extract="false"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
source_id="${source_id:-app}"
|
|
||||||
local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src"
|
|
||||||
|
|
||||||
# Load value from configuration file (see above for a small doc about this file
|
|
||||||
# format)
|
|
||||||
local src_url=$(grep 'SOURCE_URL=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_sum=$(grep 'SOURCE_SUM=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_format=$(grep 'SOURCE_FORMAT=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_rename=$(grep 'SOURCE_FILENAME=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_extract=$(grep 'SOURCE_EXTRACT=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
local src_platform=$(grep 'SOURCE_PLATFORM=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Default value
|
|
||||||
src_sumprg=${src_sumprg:-sha256sum}
|
|
||||||
src_in_subdir=${src_in_subdir:-true}
|
|
||||||
src_format=${src_format:-tar.gz}
|
src_format=${src_format:-tar.gz}
|
||||||
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
|
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
|
||||||
src_extract=${src_extract:-true}
|
src_extract=${src_extract:-true}
|
||||||
|
@ -84,10 +66,6 @@ ynh_setup_source_custom() {
|
||||||
ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter"
|
ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# (Unused?) mecanism where one can have the file in a special local cache to not have to download it...
|
|
||||||
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${source_id}"
|
|
||||||
|
|
||||||
# Gotta use this trick with 'dirname' because source_id may contain slashes x_x
|
# Gotta use this trick with 'dirname' because source_id may contain slashes x_x
|
||||||
mkdir -p $(dirname /var/cache/yunohost/download/${YNH_APP_ID}/${source_id})
|
mkdir -p $(dirname /var/cache/yunohost/download/${YNH_APP_ID}/${source_id})
|
||||||
src_filename="/var/cache/yunohost/download/${YNH_APP_ID}/${source_id}"
|
src_filename="/var/cache/yunohost/download/${YNH_APP_ID}/${source_id}"
|
||||||
|
@ -100,14 +78,10 @@ ynh_setup_source_custom() {
|
||||||
fi
|
fi
|
||||||
# END APP CUSTOMIZATION
|
# END APP CUSTOMIZATION
|
||||||
else
|
else
|
||||||
if test -e "$local_src"; then
|
|
||||||
cp $local_src $src_filename
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?"
|
[ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?"
|
||||||
|
|
||||||
# If the file was prefetched but somehow doesn't match the sum, rm and redownload it
|
# If the file was prefetched but somehow doesn't match the sum, rm and redownload it
|
||||||
if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status
|
if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | sha256sum --check --status
|
||||||
then
|
then
|
||||||
rm -f "$src_filename"
|
rm -f "$src_filename"
|
||||||
fi
|
fi
|
||||||
|
@ -121,16 +95,16 @@ ynh_setup_source_custom() {
|
||||||
local out
|
local out
|
||||||
# Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget)
|
# Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget)
|
||||||
out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$src_filename $src_url 2>&1) \
|
out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$src_filename $src_url 2>&1) \
|
||||||
|| ynh_die --message="$out"
|
|| ynh_die "$out"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check the control sum
|
# Check the control sum
|
||||||
if ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status
|
if ! echo "${src_sum} ${src_filename}" | sha256sum --check --status
|
||||||
then
|
then
|
||||||
local actual_sum="$(${src_sumprg} ${src_filename} | cut --delimiter=' ' --fields=1)"
|
local actual_sum="$(sha256sum ${src_filename} | cut --delimiter=' ' --fields=1)"
|
||||||
local actual_size="$(du -hs ${src_filename} | cut --fields=1)"
|
local actual_size="$(du -hs ${src_filename} | cut --fields=1)"
|
||||||
rm -f ${src_filename}
|
rm -f ${src_filename}
|
||||||
ynh_die --message="Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})."
|
ynh_die "Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -150,19 +124,12 @@ ynh_setup_source_custom() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$full_replace" -eq 1 ]; then
|
if [ "$full_replace" -eq 1 ]; then
|
||||||
ynh_secure_remove --file="$dest_dir"
|
ynh_safe_rm "$dest_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract source into the app dir
|
# Extract source into the app dir
|
||||||
mkdir --parents "$dest_dir"
|
mkdir --parents "$dest_dir"
|
||||||
|
|
||||||
if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then
|
|
||||||
_ynh_apply_default_permissions $dest_dir
|
|
||||||
fi
|
|
||||||
if [ -n "${final_path:-}" ] && [ "$dest_dir" == "$final_path" ]; then
|
|
||||||
_ynh_apply_default_permissions $dest_dir
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$src_extract" == "false" ]]; then
|
if [[ "$src_extract" == "false" ]]; then
|
||||||
if [[ -z "$src_rename" ]]
|
if [[ -z "$src_rename" ]]
|
||||||
then
|
then
|
||||||
|
@ -179,11 +146,11 @@ ynh_setup_source_custom() {
|
||||||
local tmp_dir=$(mktemp --directory)
|
local tmp_dir=$(mktemp --directory)
|
||||||
unzip -quo $src_filename -d "$tmp_dir"
|
unzip -quo $src_filename -d "$tmp_dir"
|
||||||
cp --archive $tmp_dir/*/. "$dest_dir"
|
cp --archive $tmp_dir/*/. "$dest_dir"
|
||||||
ynh_secure_remove --file="$tmp_dir"
|
ynh_safe_rm "$tmp_dir"
|
||||||
else
|
else
|
||||||
unzip -quo $src_filename -d "$dest_dir"
|
unzip -quo $src_filename -d "$dest_dir"
|
||||||
fi
|
fi
|
||||||
ynh_secure_remove --file="$src_filename"
|
ynh_safe_rm "$src_filename"
|
||||||
else
|
else
|
||||||
local strip=""
|
local strip=""
|
||||||
if [ "$src_in_subdir" != "false" ]; then
|
if [ "$src_in_subdir" != "false" ]; then
|
||||||
|
@ -194,31 +161,30 @@ ynh_setup_source_custom() {
|
||||||
fi
|
fi
|
||||||
strip="--strip-components $sub_dirs"
|
strip="--strip-components $sub_dirs"
|
||||||
fi
|
fi
|
||||||
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]; then
|
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz|tar$ ]]; then
|
||||||
tar --extract --file=$src_filename --directory="$dest_dir" $strip
|
tar --extract --file=$src_filename --directory="$dest_dir" $strip
|
||||||
else
|
else
|
||||||
ynh_die --message="Archive format unrecognized."
|
ynh_die "Archive format unrecognized."
|
||||||
fi
|
fi
|
||||||
ynh_secure_remove --file="$src_filename"
|
ynh_safe_rm "$src_filename"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Apply patches
|
# Apply patches
|
||||||
if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then
|
if [ -d "$YNH_APP_BASEDIR/patches/" ]; then
|
||||||
local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/)
|
local patches_folder=$(realpath "$YNH_APP_BASEDIR/patches/$source_id")
|
||||||
if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2>/dev/null | wc --lines) > "0")); then
|
|
||||||
pushd "$dest_dir"
|
pushd "$dest_dir"
|
||||||
for p in $patches_folder/${source_id}-*.patch; do
|
for patchfile in "$patches_folder/"*.patch; do
|
||||||
echo $p
|
echo "Applying $patchfile"
|
||||||
patch --strip=1 <$p || ynh_print_warn --message="Packagers /!\\ patch $p failed to apply"
|
if ! patch --strip=1 < "$patchfile"; then
|
||||||
|
if ynh_in_ci_tests; then
|
||||||
|
ynh_die "Patch $patchfile failed to apply!"
|
||||||
|
else
|
||||||
|
ynh_print_warn "Warn your packagers /!\\ Patch $patchfile failed to apply"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
popd
|
popd
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Add supplementary files
|
|
||||||
if test -e "$YNH_APP_BASEDIR/sources/extra_files/${source_id}"; then
|
|
||||||
cp --archive $YNH_APP_BASEDIR/sources/extra_files/$source_id/. "$dest_dir"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Keep files to be backup/restored at the end of the helper
|
# Keep files to be backup/restored at the end of the helper
|
||||||
# Assuming $dest_dir already exists
|
# Assuming $dest_dir already exists
|
||||||
|
@ -239,4 +205,8 @@ ynh_setup_source_custom() {
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
rm -rf /var/cache/yunohost/files_to_keep_during_setup_source/
|
rm -rf /var/cache/yunohost/files_to_keep_during_setup_source/
|
||||||
|
|
||||||
|
if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then
|
||||||
|
_ynh_apply_default_permissions $dest_dir
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue