Use getopts for ynh_setup_source helper

This commit is contained in:
Maniack Crudelis 2018-12-29 18:17:08 +01:00 committed by GitHub
parent 6425117c4d
commit bc08c5c872
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -141,22 +141,27 @@ ynh_backup_before_upgrade () {
# sources/extra_files/$src_id will be applied to dest_dir # sources/extra_files/$src_id will be applied to dest_dir
# #
# #
# usage: ynh_setup_source dest_dir [source_id] # usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id]
# | arg: dest_dir - Directory where to setup sources # | arg: -d, --dest_dir - Directory where to setup sources
# | arg: source_id - Name of the app, if the package contains more than one app # | arg: -s, --source_id - Name of the app, if the package contains more than one app
ynh_setup_source () { ynh_setup_source () {
local dest_dir=$1 # Declare an array to define the options of this helper.
local src_id=${2:-app} # If the argument is not given, source_id equals "app" declare -Ar args_array=( [d]=dest_dir= [s]=source_id= )
local dest_dir
local source_id
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
source_id="${source_id:-app}" # If the argument is not given, source_id equals "app"
# Load value from configuration file (see above for a small doc about this file # Load value from configuration file (see above for a small doc about this file
# format) # format)
local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
local src_sum=$(grep 'SOURCE_SUM=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_sum=$(grep 'SOURCE_SUM=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
local src_format=$(grep 'SOURCE_FORMAT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_format=$(grep 'SOURCE_FORMAT=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
local src_extract=$(grep 'SOURCE_EXTRACT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_extract=$(grep 'SOURCE_EXTRACT=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
local src_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${source_id}.src" | cut -d= -f2-)
# Default value # Default value
src_sumprg=${src_sumprg:-sha256sum} src_sumprg=${src_sumprg:-sha256sum}
@ -165,7 +170,7 @@ ynh_setup_source () {
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}
if [ "$src_filename" = "" ] ; then if [ "$src_filename" = "" ] ; then
src_filename="${src_id}.${src_format}" src_filename="${source_id}.${src_format}"
fi fi
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}" local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}"
@ -211,18 +216,18 @@ ynh_setup_source () {
fi fi
# Apply patches # Apply patches
if (( $(find $YNH_CWD/../sources/patches/ -type f -name "${src_id}-*.patch" 2> /dev/null | wc -l) > "0" )); then if (( $(find $YNH_CWD/../sources/patches/ -type f -name "${source_id}-*.patch" 2> /dev/null | wc -l) > "0" )); then
local old_dir=$(pwd) local old_dir=$(pwd)
(cd "$dest_dir" \ (cd "$dest_dir" \
&& for p in $YNH_CWD/../sources/patches/${src_id}-*.patch; do \ && for p in $YNH_CWD/../sources/patches/${source_id}-*.patch; do \
patch -p1 < $p; done) \ patch -p1 < $p; done) \
|| ynh_die "Unable to apply patches" || ynh_die "Unable to apply patches"
cd $old_dir cd $old_dir
fi fi
# Add supplementary files # Add supplementary files
if test -e "$YNH_CWD/../sources/extra_files/${src_id}"; then if test -e "$YNH_CWD/../sources/extra_files/${source_id}"; then
cp -a $YNH_CWD/../sources/extra_files/$src_id/. "$dest_dir" cp -a $YNH_CWD/../sources/extra_files/$source_id/. "$dest_dir"
fi fi
} }