From 99f61fc3403ba393da1ee35d39ec5d302f5ef5e4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 13 Aug 2020 01:07:41 +0300 Subject: [PATCH] kiss: add support for directories and absolute file paths as sources This adds support for both absolute and relative directories in sources files. Relative file sources have always been supported, this just extends it to directories. Absolute paths to directories and files in sources is totally new. Directories will have their /contents/ copied to the initial build directory. The second field in the sources file can be used to set destination location. Checksums will not be validated for directories of any type. Absolute file paths do have their checksums validated. Notes: The package manager will check to see if the source is a directory or not. There is no need to have a trailing forward slash (though it might make sense to enforce this anyway, we'll see). --- kiss | 56 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/kiss b/kiss index 5de47d6..028b895 100755 --- a/kiss +++ b/kiss @@ -221,9 +221,13 @@ pkg_sources() { die "$1" "Failed to download $src" } - # Local source. - elif [ -f "$repo_dir/$src" ]; then - log "$1" "Found local file '$src'" + # Local source (relative). + elif [ -e "$repo_dir/$src" ]; then + log "$1" "Found local relative source '$src'" + + # Local source (absolute). + elif [ -e "/$src" ]; then + log "$1" "Found local absolute source '$src'" else die "$1" "No local file '$src'" @@ -319,10 +323,22 @@ pkg_extract() { ;; *) - # Local file. - if [ -f "$repo_dir/$src" ]; then + # Local directory (relative). + if [ -d "$repo_dir/$src" ]; then + cp -Rf "$repo_dir/$src/." . + + # Local directory (absolute). + elif [ -d "/$src" ]; then + cp -Rf "/$src/." . + + # Local file (relative). + elif [ -f "$repo_dir/$src" ]; then cp -f "$repo_dir/$src" . + # Local file (absolute). + elif [ -f "/$src" ]; then + cp -f "/$src" . + # Remote file. elif [ -f "$src_dir/$1/${src##*/}" ]; then cp -f "$src_dir/$1/${src##*/}" . @@ -699,12 +715,30 @@ pkg_checksums() { [ -f "$repo_dir/sources" ] || return 0 while read -r src _ || [ "$src" ]; do - case $src in - \#*|"") ;; - git+*) printf '%s\n' "$src" ;; - *://*) sh256 "$src_dir/$1/${src##*/}" ;; - *) sh256 "$repo_dir/$src" ;; - esac + # Skip comments and blank lines. + if [ -z "${src##\#*}" ]; then + : + + # Git source. + elif [ -z "${src##git+*}" ]; then + printf '%s\n' "$src" # This should probably be ':'. + + # Remote source. + elif [ -z "${src##*://*}" ]; then + sh256 "$src_dir/$1/${src##*/}" + + # Skip directories. + elif [ -d "$repo_dir/$src" ] || [ -d "/$src" ]; then + : + + # Local file (relative). + elif [ -f "$repo_dir/$src" ]; then + sh256 "$repo_dir/$src" + + # Local file (absolute). + elif [ -f "/$src" ]; then + sh256 "/$src" + fi done < "$repo_dir/sources" || die "$1" "Failed to generate checksums" }