aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rwxr-xr-xlibs/common238
-rwxr-xr-xlibs/git32
-rwxr-xr-xlibs/project420
-rwxr-xr-xlibs/tool69
4 files changed, 413 insertions, 346 deletions
diff --git a/libs/common b/libs/common
index 8f1379ee..fd001a5d 100755
--- a/libs/common
+++ b/libs/common
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
@@ -35,12 +35,17 @@ BLOBS_IGNORE="blobs-ignore"
BLOBS_DISCOVER="blobs-discover"
DOTEPOCH=".epoch"
+DOTRNDSEED=".rndseed"
DOTVERSION=".version"
DOTREVISION=".revision"
DOTTARFILES=".tarfiles"
-TAR_XZ="tar.xz"
-SHA256SUM="sha256sum"
-ASC="asc"
+ARCHIVE="tar.xz"
+CHECKSUM="sha256sum"
+DSIG="asc"
+
+CONFIG_SHELL="${CONFIG_SHELL:-$(which bash)}"
+EDITOR="${EDITOR:-$(which vi || true)}"
+TASKS="${TASKS:-1}"
function_check() {
local function=$1
@@ -59,32 +64,73 @@ arguments_list() {
for argument in "$@"
do
- echo "$argument"
+ printf '%s\n' "$argument"
done
}
+download_wrapper() {
+ local download_dir="$1"
+ shift
+ local uris=($@)
+
+ local wget_options=(
+ '--config=/dev/null'
+ '--secure-protocol=PFS'
+ "--directory-prefix=$download_dir"
+ '--continue'
+ '--'
+ )
+
+ local curl_options=(
+ '-q'
+ '--continue-at -'
+ '--remote-name'
+ '--retry 20'
+ '--ssl'
+ '--tlsv1.2'
+ '--'
+ )
+
+ if hash wget > /dev/null 2>&1; then
+
+ wget "${wget_options[@]}" "${uris[@]}"
+
+ elif hash curl > /dev/null 2>&1; then
+ (
+ cd "$download_dir"
+
+ curl "${curl_options[@]}" "${uris[@]}"
+ )
+ else
+ printf '\n%s\n\n' 'Error: Neither wget nor curl were found' 1>&2
+
+ return 1
+ fi
+}
+
diff_patch_file() {
local repository_path="$1"
local patch_file_path="$2"
- local filename_in_diff="$(sed -rne 's/^-{3} {1}(.*)$/\1/p' <"${patch_file_path}")"
+ # TODO: Improve handling of filenames to avoid gotchas w/ \n, \t, etc.
+ local filename_in_diff="$(sed -rne 's/^-{3}\s+([^ \r\n]*).*/\1/p' "$patch_file_path")"
local source_file_path
- if ! ( grep -E '^-{3}.*/' <"${patch_file_path}" >/dev/null 2>&1 ); then
- source_file_path="${repository_path}/${filename_in_diff##\ }"
+ if ! ( grep -E '^-{3}.*/' "$patch_file_path" >/dev/null 2>&1 ); then
+ source_file_path="$repository_path/$filename_in_diff"
else
- source_file_path="${repository_path}/${filename_in_diff##*/}"
+ source_file_path="$repository_path/${filename_in_diff##*/}"
fi
- patch "${source_file_path}" "${patch_file_path}"
+ patch "$source_file_path" "$patch_file_path"
}
path_wildcard_expand() {
local path=$@
# Evaluation fails with unescaped whitespaces.
- path=$( echo "$path" | sed "s/ /\\\ /g" )
+ path=$( printf '%s\n' "$path" | sed "s/ /\\\ /g" )
eval "arguments_list "$path""
}
@@ -92,7 +138,7 @@ path_wildcard_expand() {
file_checksum_create() {
local path=$1
- local checksum_path="$path.$SHA256SUM"
+ local checksum_path="$path.$CHECKSUM"
local name=$( basename "$path" )
local directory_path=$( dirname "$path" )
@@ -105,13 +151,13 @@ file_checksum_create() {
file_checksum_check() {
local path=$1
- local checksum_path="$path.$SHA256SUM"
+ local checksum_path="$path.$CHECKSUM"
local name=$( basename "$path" )
local directory_path=$( dirname "$path" )
if ! [ -f "$checksum_path" ]
then
- printf "Could not verify file checksum!\n" >&2
+ printf '%s\n' 'Could not verify file checksum!' >&2
return 1
fi
@@ -124,7 +170,7 @@ file_checksum_check() {
file_signature_create() {
local path=$1
- local signature_path="$path.$ASC"
+ local signature_path="$path.$DSIG"
if [ -z "$RELEASE_KEY" ]
then
@@ -137,11 +183,11 @@ file_signature_create() {
file_signature_check() {
local path=$1
- local signature_path="$path.$ASC"
+ local signature_path="$path.$DSIG"
if ! [ -f "$signature_path" ]
then
- printf "Could not verify file signature!\n" >&2
+ printf '%s\n' 'Could not verify file signature!' >&2
return 1
fi
@@ -180,145 +226,151 @@ directory_filled_check() {
}
archive_files_create() {
- local source_path=$1
+ local source_path="$1"
- local directory=$( basename "$source_path" )
+ local directory="$(basename "$source_path")"
local tarfiles_path="$source_path/$DOTTARFILES"
local revision_path="$source_path/$DOTREVISION"
local version_path="$source_path/$DOTVERSION"
+ local epoch_path="$source_path/$DOTEPOCH"
+ local rnd_seed_path="$source_path/$DOTRNDSEED"
- if git_check "$source_path"
- then
- git_files "$source_path" | tr -d '\0' > "$tarfiles_path"
- echo "$DOTTARFILES" | tr -d '\0' >> "$tarfiles_path"
+ # Files in "$tarfiles_path" are NUL terminated.
+ # `tr '\0' '\n'` for human-readable output.
+ if git_check "$source_path"; then
+ git_files "$source_path" > "$tarfiles_path"
+ printf '%s\0' "$DOTTARFILES" >> "$tarfiles_path"
else
- touch "$tarfiles_path"
-
- (
- cd "$source_path"
- find
- ) | LC_ALL=C sort | sed "s,^./,," | grep -vP "^\.$" > "$tarfiles_path"
- fi
-
- if [ -f "$revision_path" ]
- then
- echo "$DOTREVISION" | tr -d '\0' >> "$tarfiles_path"
+ find "$source_path" -print0 | env LC_ALL='C.UTF-8' sort -z | sed -z "1d;s,^$source_path/\\?,,;/^$DOTTARFILES\$/d" > "$tarfiles_path"
fi
- if [ -f "$version_path" ]
- then
- echo "$DOTVERSION" | tr -d '\0' >> "$tarfiles_path"
- fi
-
- if [ -f "$epoch_path" ]
- then
- echo "$DOTEPOCH" | tr -d '\0' >> "$tarfiles_path"
- fi
+ for dotfile in "$revision_path" \
+ "$version_path" \
+ "$epoch_path" \
+ "$rnd_seed_path"
+ do
+ if [[ -f "$dotfile" ]]; then
+ printf '%s\0' ".${dotfile##*.}" >> "$tarfiles_path"
+ fi
+ done
}
archive_files_date() {
- local source_path=$1
+ local source_path="$1"
local epoch_path="$source_path/$DOTEPOCH"
- if ! [ -z "$SOURCE_DATE_EPOCH" ]
- then
- (
- cd "$source_path"
- find -exec touch --no-dereference --date="@$SOURCE_DATE_EPOCH" {} \;
- )
+ if [[ -n "$SOURCE_DATE_EPOCH" ]]; then
+ find "$source_path" -execdir touch --no-dereference --date="@$SOURCE_DATE_EPOCH" {} +
fi
}
archive_create() {
- local archive_path=$1
- local source_path=$2
- local directory=$3
+ local archive_path="$1"
+ local source_path="$2"
+ local directory="$3"
local tarfiles_path="$source_path/$DOTTARFILES"
- local directory_path=$( dirname "$archive_path" )
+ local directory_path="$(dirname "$archive_path")"
mkdir -p "$directory_path"
- if [ -z "$directory" ]
- then
- directory=$( basename "$source_path" )
+ if [[ -z "$directory" ]]; then
+ directory="$(basename "$source_path")"
fi
archive_files_create "$source_path"
archive_files_date "$source_path"
+ local tar_options=(
+ --create
+ --xz
+ --file="$archive_path"
+ --files-from="$tarfiles_path"
+ --transform="s,^,$directory/,S"
+ --no-recursion
+ --warning=no-filename-with-nuls
+ --null
+ --owner=0
+ --group=0
+ --numeric-owner
+ )
+
(
cd "$source_path"
- tar -cJf "$archive_path" --no-recursion -T "$tarfiles_path" --transform="s,^,$directory/,S" --owner=root --group=root --numeric-owner
+ tar "${tar_options[@]}"
)
}
archive_extract() {
- local archive_path=$1
- local destination_path=$2
+ local archive_path="$1"
+ local destination_path="$2"
- if [ -z "$destination_path" ]
- then
- destination_path=$( dirname "$archive_path" )
+ if [[ -z "$destination_path" ]]; then
+ destination_path="$(dirname "$archive_path")"
fi
tar -xf "$archive_path" -ps -C "$destination_path"
}
rootfs_files_create() {
- local source_path=$1
+ local source_path="$1"
- local directory=$( basename "$source_path" )
+ local directory="$(basename "$source_path")"
local tarfiles_path="$source_path/$DOTTARFILES"
- touch "$tarfiles_path"
-
- (
- cd "$source_path"
- execute_root find
- ) | LC_ALL=C sort | sed "s,^./,," | grep -vP "^$DOTTARFILES|^\.$" > "$tarfiles_path"
+ # Files in "$tarfiles_path" are NUL terminated.
+ # `tr '\0' '\n'` for human-readable output.
+ execute_root find "$source_path" -print0 | env LC_ALL='C.UTF-8' sort -z | sed -z "1d;s,^$source_path/\\?,,;/^$DOTTARFILES\$/d" > "$tarfiles_path"
}
rootfs_files_date() {
- local source_path=$1
+ local source_path="$1"
local epoch_path="$source_path/$DOTEPOCH"
- if ! [ -z "$SOURCE_DATE_EPOCH" ]
- then
- (
- cd "$source_path"
- execute_root find -exec touch --no-dereference --date="@$SOURCE_DATE_EPOCH" {} \;
- )
+ if [[ -n "$SOURCE_DATE_EPOCH" ]]; then
+ execute_root find "$source_path" -execdir touch --no-dereference --date="@$SOURCE_DATE_EPOCH" {} +
fi
}
rootfs_create() {
- local rootfs_path=$1
- local source_path=$2
- local directory=$3
+ local rootfs_path="$1"
+ local source_path="$2"
+ local directory="$3"
local tarfiles_path="$source_path/$DOTTARFILES"
- local directory_path=$( dirname "$rootfs_path" )
+ local directory_path="$(dirname "$rootfs_path")"
mkdir -p "$directory_path"
- if [ -z "$directory" ]
- then
- directory=$( basename "$source_path" )
+ if [[ -z "$directory" ]]; then
+ directory="$(basename "$source_path")"
fi
rootfs_files_create "$source_path"
rootfs_files_date "$source_path"
+ local tar_options=(
+ --create
+ --xz
+ --file="$rootfs_path"
+ --files-from="$tarfiles_path"
+ --no-recursion
+ --warning=no-filename-with-nuls
+ --null
+ --owner=0
+ --group=0
+ --numeric-owner
+ )
+
(
cd "$source_path"
- execute_root tar -cJf "$rootfs_path" --no-recursion -T "$tarfiles_path" --numeric-owner
+ execute_root tar "${tar_options[@]}"
)
execute_root chmod 644 "$rootfs_path"
- execute_root chown $USER:$USER "$rootfs_path"
+ execute_root chown "$USER:$USER" "$rootfs_path"
}
requirements() {
@@ -331,7 +383,7 @@ requirements() {
if [ -z "$requirement_path" ]
then
- printf "Missing requirement: $requirement\n" >&2
+ printf '%s\n' "Missing requirement: $requirement" >&2
exit 1
fi
done
@@ -348,7 +400,7 @@ requirements_root() {
if [ -z "$requirement_path" ]
then
- printf "Missing requirement: $requirement\n" >&2
+ printf '%s\n' "Missing requirement: $requirement" >&2
exit 1
fi
done
@@ -370,22 +422,22 @@ arguments_concat() {
fi
done
- echo "$concat"
+ printf '%s\n' "$concat"
}
execute_root() {
local sudo=$( which sudo 2> /dev/null || true )
local arguments
- printf "Running command as root: " >&2
- echo "$@" >&2
+ printf '%s' 'Running command as root: ' >&2
+ printf '%b\n' "$*" >&2
if ! [ -z "$sudo" ]
then
sudo "$@"
else
# Quote arguments for eval through su.
- arguments=$( printf "%q " "$@" )
+ arguments=$( printf '%q ' "$@" )
su -c "$arguments"
fi
}
diff --git a/libs/git b/libs/git
index a750be32..decdfe01 100755
--- a/libs/git
+++ b/libs/git
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
@@ -202,19 +202,19 @@ git_describe() {
}
git_files() {
- local repository_path=$1
+ local repository_path="$1"
(
cd "$repository_path"
# Reproducible sorting.
- git ls-files | LC_ALL=C sort -z
+ git ls-files -z | env LC_ALL='C.UTF-8' sort -z
)
}
git_project_repository_path() {
local repository=$1
- echo "$root/$SOURCES/$repository"
+ printf '%s\n' "$root/$SOURCES/$repository"
}
git_project_check() {
@@ -231,23 +231,23 @@ git_project_patch_recursive() {
local branch="$3"
local path="${4:-.}"
- local repository_path="$(git_project_repository_path "${repository}")"
- local project_path="$(project_path "${project}")"
- local patches_path="${project_path}/${PATCHES}/${path}"
+ local repository_path="$(git_project_repository_path "$repository")"
+ local project_path="$(project_path "$project")"
+ local patches_path="$project_path/$PATCHES/$path"
- if ! [[ -d "${patches_path}" ]]; then
+ if ! [[ -d "$patches_path" ]]; then
return
fi
- if [[ "${path}" != "." ]]; then
- git_project_patch_recursive "${project}" "${repository}" "${branch}" "$(dirname "${path}")"
+ if [[ "$path" != "." ]]; then
+ git_project_patch_recursive "$project" "$repository" "$branch" "$(dirname "$path")"
fi
- for patch in "${patches_path}"/[!.]*.{patch,diff}; do
+ for patch in "$patches_path"/[!.]*.@(patch|diff); do
if [[ "${patch##*.}" == "patch" ]]; then
- git_patch "${repository_path}" "${branch}" "${patch}"
+ git_patch "$repository_path" "$branch" "$patch"
else
- diff_patch_file "${repository_path}" "${patch}"
+ diff_patch_file "$repository_path" "$patch"
fi
done
}
@@ -579,10 +579,10 @@ git_project_release() {
if ! [ -z "$release_branch" ]
then
- local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$TAR_XZ"
+ local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE"
local sources_path="$root/$SOURCES/$repository"
- printf "Releasing sources archive for $project (with ${arguments:-no argument}) from "$repository" git\n"
+ printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument}) from "$repository" git"
git_branch_checkout "$repository_path" "$release_branch"
git_submodule_update "$repository_path"
@@ -620,7 +620,7 @@ git_project_release_check() {
if ! [ -z "$release_branch" ]
then
- local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$TAR_XZ"
+ local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE"
file_exists_check "$archive_path"
diff --git a/libs/project b/libs/project
index 20a6fe77..37a5973c 100755
--- a/libs/project
+++ b/libs/project
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
@@ -15,20 +15,20 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-PROJECT_ACTIONS_GENERIC="usage download extract update build install release clean"
-PROJECT_ACTIONS_HELPERS="arguments"
-PROJECT_FUNCTIONS=$( for action in $PROJECT_ACTIONS_GENERIC ; do echo "$action" "$action""_check" ; done ; echo "$PROJECT_ACTIONS_HELPERS" )
+PROJECT_ACTIONS_GENERIC=(usage download extract update build install release clean)
+PROJECT_ACTIONS_GENERIC_IGNORE_CHECK=(usage clean)
+PROJECT_ACTIONS_HELPERS=(arguments)
-INSTALL_REGEX="\([^:]*\):\(.*\)"
+INSTALL_REGEX='\([^:]*\):\(.*\)'
project_include() {
local project=$1
local project_path=$( project_path "$project" )
- unset -f $PROJECT_FUNCTIONS
+ unset -f "${PROJECT_ACTIONS[@]}"
- . "$project_path/$project"
+ source "$project_path/$project"
project_helper_include "$project"
}
@@ -41,16 +41,16 @@ project_helper_include() {
if [ -f "$include" ]
then
- . "$include"
+ source "$include"
fi
}
project_check() {
local project="${1##*/}"
- local project_path="$(project_path "${project}")"
+ local project_path="$(project_path "$project")"
- if ! [[ -f "${project_path}/${project}" ]]; then
+ if ! [[ -f "$project_path/$project" ]]; then
return 1
fi
}
@@ -70,162 +70,108 @@ project_function_check() {
}
project_action() {
- local action=$1
+ local action="$1"
shift
- local project=$1
+ local project="$1"
shift
- local arguments=$@
+ local arguments="$*"
(
set +e
- if ! project_check "$project"
- then
- printf "Project $project check failed\n" >&2
- return 1
- fi
-
project_action_check "$action" "$project" "$@"
- # Why is this here? Commented out for now.
- # if [ $? -eq 0 ]
- # then
- # return 0
- # fi
-
- project_include "$project"
-
- if ! function_check "$action"
- then
- return 0
- fi
-
- printf "Project $project $action (with ${arguments:-no argument})\n" >&2
-
- (
- set -e
- "$action" "$@"
- )
+ printf '%s\n' "Project $project $action (with ${arguments:-no argument})" >&2
- if [ $? -ne 0 ]
- then
- printf "\nProject $project $action (with ${arguments:-no argument}) failed\n" >&2
- return 1
+ if "$action" "$@"; then
+ printf '\n%s\n' "Project $project $action (with ${arguments:-no argument}) completed" >&2
else
- printf "\nProject $project $action (with ${arguments:-no argument}) completed\n" >&2
+ printf '\n%s\n' "Project $project $action (with ${arguments:-no argument}) failed" >&2
+ return 1
fi
)
}
project_action_check() {
- local action=$1
+ local action="$1"
shift
- local project=$1
+ local project="$1"
shift
(
set +e
- if ! project_check "$project"
- then
- printf "Project $project check failed\n" >&2
+ if ! function_check "${action}_check"; then
return 1
fi
- project_include "$project"
-
- if ! function_check "$action""_check"
- then
- return 1
- fi
-
- for project_force in $PROJECTS_FORCE
- do
- if [ "$project_force" = "$project" ]
- then
+ for project_force in $PROJECTS_FORCE; do
+ if [[ "$project_force" == "$project" ]]; then
return 1
fi
done
(
set -e
- "$action""_check" "$@"
+ "${action}_check" "$@"
)
)
}
project_action_helper() {
- local helper=$1
+ local helper="$1"
shift
- local project=$1
+ local project="$1"
shift
- (
- set +e
-
- if ! project_check "$project"
- then
- printf "Project $project check failed\n" >&2
- return 1
- fi
-
- project_include "$project"
-
- if ! function_check "$helper"
- then
- return 0
- fi
+ if ! function_check "$helper"; then
+ return 0
+ fi
- (
- set -e
- "$helper" "$@"
- )
- )
+ "$helper" "$@"
}
project_action_arguments() {
- local action=$1
+ local action="$1"
shift
- local project=$1
+ local project="$1"
shift
+ project_include "$project"
+
project_action_arguments_verify_recursive "$action" "$project" "$@"
project_action_arguments_recursive "$action" "$project" "$@"
}
project_action_arguments_verify_recursive() {
- local action=$1
+ local action="$1"
shift
- local project=$1
+ local project="$1"
shift
local action_helper_arguments
# Store final argument.
- local argument=${@:$#}
+ local argument="${*:$#}"
local test
- if [ $# -gt 1 ]
- then
+ if [[ "$#" -gt 1 ]]; then
# Set previous arguments.
set "${@:1:$#-1}"
- elif [ $# -eq 1 ]
- then
+ elif [[ "$#" -eq 1 ]]; then
shift
else
return 0
fi
- action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" )
+ action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")"
- if ! [ -z "$action_helper_arguments" ]
- then
- test=$( echo "$action_helper_arguments" | grep -P "^$argument$" || true )
+ if [[ -n "$action_helper_arguments" ]]; then
+ test="$(printf '%s\n' "$action_helper_arguments" | grep -e "^$argument\$" || true)"
- if [ -z "$test" ]
- then
- printf "Invalid argument $argument for project $project action $action\n" >&2
+ if [[ -z "$test" ]]; then
+ printf '%s\n' "Invalid argument $argument for project $project action $action" >&2
return 1
fi
fi
@@ -234,62 +180,54 @@ project_action_arguments_verify_recursive() {
}
project_action_arguments_recursive() {
- local action=$1
+ local action="$1"
shift
- local project=$1
+ local project="$1"
shift
local action_helper_arguments
local argument
- local ifs_save
- action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" )
+ action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@" || true)"
- if [ $? -ne 0 ] || [ -z "$action_helper_arguments" ]
- then
+ if [[ -z "$action_helper_arguments" ]]; then
project_action "$action" "$project" "$@"
else
- # This it to allow space characters in arguments.
- ifs_save=$IFS
- IFS=$'\n'
+ # This is to allow space characters in arguments.
+ local ifs_save="$IFS"
+ local IFS=$'\n'
- for argument in $( echo "$action_helper_arguments" )
+ for argument in $(printf '%s\n' "$action_helper_arguments")
do
- (
- IFS=$ifs_save
+ IFS="$ifs_save"
- # Only a single argument at a time is returned by the helper.
- project_action_arguments_recursive "$action" "$project" "$@" "$argument"
- )
+ # Only a single argument at a time is returned by the helper.
+ project_action_arguments_recursive "$action" "$project" "$@" "$argument"
done
-
- IFS=$ifs_save
fi
}
project_action_projects() {
- local action=$1
+ local action="$1"
shift
- local project=$1
+ local project="$1"
shift
- local project_path=$( project_path "$project" )
+ local project_path="$(project_path "$project")"
local project_projects_path="$project_path/$CONFIGS/$PROJECTS"
local project_projects_action_path="$project_path/$CONFIGS/$PROJECTS-$action"
local arguments
local path
- if [ -f "$project_projects_action_path" ]
- then
- path=$project_projects_action_path
+ if [[ -f "$project_projects_action_path" ]]; then
+ path="$project_projects_action_path"
else
- path=$project_projects_path
+ path="$project_projects_path"
fi
# Multiple arguments can be read from the file.
- while read arguments
- do
- eval "project_action_arguments "$action" $arguments"
+ while read -r arguments; do
+ eval "project_action_arguments $action $arguments"
done < "$path"
}
@@ -298,7 +236,7 @@ project_path() {
local project_path="$root/$PROJECTS/$project"
- echo "$project_path"
+ printf '%s\n' "$project_path"
}
project_sources_path() {
@@ -331,7 +269,7 @@ project_sources_path() {
if ! [ -z "$sources_path" ]
then
- echo "$sources_path"
+ printf '%s\n' "$sources_path"
return
fi
@@ -340,7 +278,7 @@ project_sources_path() {
if directory_filled_check "$path"
then
- echo "$path"
+ printf '%s\n' "$path"
return
fi
@@ -364,7 +302,7 @@ project_sources_path() {
if ! [ -z "$sources_path" ]
then
- echo "$sources_path"
+ printf '%s\n' "$sources_path"
return
fi
}
@@ -381,13 +319,13 @@ project_sources_directory_filled_check() {
project_sources_directory_filled_error() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local sources_path=$( project_sources_path "$project" "$@" )
if ! [ -z "$sources_path" ]
then
- printf "Sources directory for project $project (with ${arguments:-no argument}) already exists\n" >&2
+ printf '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists" >&2
return 1
else
return 0
@@ -397,13 +335,13 @@ project_sources_directory_filled_error() {
project_sources_directory_missing_empty_error() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local sources_path=$( project_sources_path "$project" "$@" )
if [ -z "$sources_path" ]
then
- printf "Sources directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2
+ printf '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty" >&2
return 1
else
return 0
@@ -425,7 +363,7 @@ project_sources_archive() {
path="$path-$argument"
fi
- local archive="$path.$TAR_XZ"
+ local archive="$path.$ARCHIVE"
if ! [ -f "$archive" ]
then
@@ -437,19 +375,19 @@ project_sources_archive() {
if ! [ -z "$sources_archive" ]
then
- echo "$sources_archive"
+ printf '%s\n' "$sources_archive"
fi
}
project_sources_archive_extract() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local archive=$( project_sources_archive "$project" "$@" )
local destination=$( dirname "$archive" )
- printf "Extracting source archive for $project (with ${arguments:-no argument})\n"
+ printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})"
file_verification_check "$archive"
archive_extract "$archive" "$destination"
@@ -458,7 +396,7 @@ project_sources_archive_extract() {
project_sources_archive_update() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local repository=$project
local sources_path=$( project_sources_path "$project" "$repository" "$@" )
@@ -470,7 +408,7 @@ project_sources_archive_update() {
rm -rf "$sources_path"
fi
- printf "Extracting source archive for $project (with ${arguments:-no argument})\n"
+ printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})"
file_verification_check "$archive"
archive_extract "$archive" "$destination"
@@ -479,12 +417,12 @@ project_sources_archive_update() {
project_sources_archive_missing_error() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local archive=$( project_sources_archive "$project" "$@" )
if [ -z "$archive" ] || ! [ -f "$archive" ]
then
- printf "Missing sources archive for $project (with ${arguments:-no argument})\n" >&2
+ printf '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})" >&2
return 1
else
return 0
@@ -504,6 +442,27 @@ project_sources_archive_missing_check() {
fi
}
+project_sources_prepare() {
+ local project="$1"
+ local sources_path="$2"
+
+ # Not implemented yet / May end up not being needed
+ #project_sources_prepare_blobs
+ project_sources_prepare_patch "$project" "$sources_path" "$@"
+}
+
+project_sources_prepare_patch() {
+ local project="$1"
+ local sources_path="$2"
+
+ local project_path="$(project_path "$project")"
+ local patches_path="$project_path/$PATCHES"
+
+ for patch in "$patches_path"/[!.]*.@(patch|diff); do
+ diff_patch_file "$sources_path" "$patch"
+ done
+}
+
project_blobs_path() {
local project=$1
shift
@@ -529,12 +488,12 @@ project_blobs_path() {
if [ -f "$blobs_path" ]
then
- echo "$blobs_path"
+ printf '%s\n' "$blobs_path"
return
fi
done
- echo "$blobs_path"
+ printf '%s\n' "$blobs_path"
}
project_blobs_ignore_path() {
@@ -562,7 +521,7 @@ project_blobs_ignore_path() {
if [ -f "$blobs_ignore_path" ]
then
- echo "$blobs_ignore_path"
+ printf '%s\n' "$blobs_ignore_path"
return
fi
done
@@ -590,55 +549,53 @@ project_arguments_targets() {
}
project_usage_actions() {
- local project=$1
+ local project="$1"
shift
- printf "\nGeneric actions:\n"
+ printf '\n%s\n' 'Generic actions:'
- for action in $PROJECT_ACTIONS_GENERIC
- do
- if function_check "$action"
- then
- printf " $action\n"
- fi
- done
+ (
+ for action in "${PROJECT_ACTIONS_GENERIC[@]}"; do
+ if function_check "$action"; then
+ printf '%s\n' " $action"
+ fi
+ done
+ )
- if [ $# -gt 0 ]
- then
- printf "\nSpecific actions:\n"
+ if [[ "$#" -gt 0 ]]; then
+ printf '\n%s\n' 'Specific actions:'
- for action in "$@"
- do
- printf " $action\n"
- done
+ (
+ for action in "$@"; do
+ printf '%s\n' " $action"
+ done
+ )
fi
}
project_usage_arguments() {
- local project=$1
+ local project="$1"
shift
- printf "\nArguments:\n"
+ printf '\n%s\n' 'Arguments:'
- project_usage_arguments_recursive "$project" " " "$@"
+ project_usage_arguments_recursive "$project" ' ' "$@"
}
project_usage_arguments_recursive() {
- local project=$1
+ local project="$1"
shift
- local spacing=$1
+ local spacing="$1"
shift
local action_helper_arguments
local argument
- action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" )
+ action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")"
- if ! [ -z "$action_helper_arguments" ]
- then
- echo "$action_helper_arguments" | while read argument
- do
- printf "$spacing$argument\n"
+ if [[ -n "$action_helper_arguments" ]]; then
+ for argument in $action_helper_arguments; do
+ printf '%s\n' "$spacing$argument"
project_usage_arguments_recursive "$project" " $spacing" "$@" "$argument"
done
fi
@@ -676,6 +633,45 @@ project_download_check_git() {
git_project_prepare_check "$project" "$repository" "$@"
}
+project_download_archive() {
+ local project="$1"
+ shift
+ local archive_uri="$1"
+ shift
+ local archive_dsig_uri="$1"
+
+ local archive="${archive_uri##*/}"
+ local compress_fmt="${archive##*.tar}"
+
+ local directory_prefix="$root/$SOURCES"
+ local archive_path="$root/$SOURCES/$archive"
+ local sources_path="$root/$SOURCES/$project"
+
+ if [[ "${compress_fmt#*.}" != "${ARCHIVE#*.}" ]]; then
+ ARCHIVE="tar$compress_fmt"
+ fi
+
+ # TODO: Split this code block into separate functions
+ # Archive verification will be included at that point in time
+ if ! project_sources_directory_filled_check "$project"; then
+ download_wrapper "$directory_prefix" "$archive_uri" "$archive_dsig_uri"
+ archive_extract "$archive_path" "$directory_prefix"
+
+ mv "${archive_path%.tar*}" "$sources_path"
+ fi
+
+ # Patch the source, if necessary
+ project_sources_prepare "$project" "$sources_path"
+}
+
+project_download_check_archive() {
+ local project="$1"
+ local sources_path="$2"
+
+ # TODO: Write the following function
+ #project_sources_archive_extract_check "$project" "$sources_path"
+}
+
project_extract() {
local project=$1
shift
@@ -684,7 +680,7 @@ project_extract() {
if ! project_sources_directory_filled_check "$project" "$repository" "$@"
then
- project_sources_archive_missing_error "$project" "$@"
+ project_sources_archive_missing_error "$project" "$@" || return 1
project_sources_archive_extract "$project" "$@"
fi
}
@@ -727,7 +723,7 @@ project_update_check_git() {
requirements "git"
- if git_project_check "$repository"
+ if ! git_project_check "$repository"
then
# Git repository should always be updated (even if upstream didn't progress).
# For instance, this is useful for testing new versions of patches without changing revision.
@@ -767,13 +763,13 @@ project_build_check() {
continue
fi
- while read rule
+ while read -r rule
do
- source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" )
+ source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" )
source_path="$build_path/$source"
# Source may contain a wildcard.
- path_wildcard_expand "$source_path" | while read source_file_path
+ path_wildcard_expand "$source_path" | while read -r source_file_path
do
if ! [ -f "$source_file_path" ] && ! [ -d "$source_file_path" ]
then
@@ -796,19 +792,19 @@ project_build_path() {
build_path="$build_path-$argument"
done
- echo "$build_path"
+ printf '%s\n' "$build_path"
}
project_build_directory_missing_empty_error() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local build_path=$( project_build_path "$project" "$@" )
if ! directory_filled_check "$build_path"
then
- printf "Build directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2
+ printf '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty" >&2
return 1
else
return 0
@@ -849,19 +845,19 @@ project_install() {
project_build_directory_missing_empty_error "$project" "$@"
- while read rule
+ while read -r rule
do
- source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" )
+ source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" )
source_path="$build_path/$source"
- destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
+ destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" )
destination_path="$install_path/$destination"
destination_directory_path=$( dirname "$destination_path" )
mkdir -p "$destination_directory_path"
# Source may contain a wildcard.
- path_wildcard_expand "$source_path" | while read source_file_path
+ path_wildcard_expand "$source_path" | while read -r source_file_path
do
cp -rT "$source_file_path" "$destination_path"
done
@@ -890,19 +886,19 @@ project_install() {
continue
fi
- while read rule
+ while read -r rule
do
- source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" )
+ source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" )
source_path="$project_path/$INSTALL/$path/$source"
- destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
+ destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" )
destination_path="$install_path/$destination"
destination_directory_path=$( dirname "$destination_path" )
mkdir -p "$destination_directory_path"
# Source may contain a wildcard.
- path_wildcard_expand "$source_path" | while read source_file_path
+ path_wildcard_expand "$source_path" | while read -r source_file_path
do
cp -rT "$source_file_path" "$destination_path"
done
@@ -943,9 +939,9 @@ project_install_check() {
project_build_directory_missing_empty_error "$project" "$@"
- while read rule
+ while read -r rule
do
- destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
+ destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" )
destination_path="$install_path/$destination"
if ! [ -f "$destination_path" ] && ! [ -d "$destination_path" ]
@@ -977,9 +973,9 @@ project_install_check() {
continue
fi
- while read rule
+ while read -r rule
do
- destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
+ destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" )
destination_path="$install_path/$destination"
if ! [ -f "$destination_path" ] && ! [ -d "$destination_path" ]
@@ -1002,19 +998,19 @@ project_install_path() {
install_path="$install_path-$argument"
done
- echo "$install_path"
+ printf '%s\n' "$install_path"
}
project_install_directory_missing_empty_error() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local install_path=$( project_install_path "$project" "$@" )
if ! directory_filled_check "$install_path"
then
- printf "Install directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2
+ printf '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty" >&2
return 1
else
return 0
@@ -1038,7 +1034,7 @@ project_release_path() {
release_path="$release_path/$project"
fi
- echo "$release_path"
+ printf '%s\n' "$release_path"
}
project_release_archive_path() {
@@ -1056,9 +1052,9 @@ project_release_archive_path() {
path="$path-$argument"
done
- local archive_path="$release_path/$path.$TAR_XZ"
+ local archive_path="$release_path/$path.$ARCHIVE"
- echo "$archive_path"
+ printf '%s\n' "$archive_path"
}
project_release_rootfs_path() {
@@ -1076,9 +1072,9 @@ project_release_rootfs_path() {
path="$path-$argument"
done
- local rootfs_path="$release_path/$path.$TAR_XZ"
+ local rootfs_path="$release_path/$path.$ARCHIVE"
- echo "$rootfs_path"
+ printf '%s\n' "$rootfs_path"
}
project_release_sources_archive_path() {
@@ -1109,22 +1105,22 @@ project_release_sources_archive_path() {
if ! [ -z "$release_path" ]
then
- local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$TAR_XZ"
+ local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$ARCHIVE"
- echo "$archive_path"
+ printf '%s\n' "$archive_path"
fi
}
project_release_sources_archive_create() {
local project=$1
shift
- local arguments=$@
+ local arguments="$*"
local repository=$project
local archive_path=$( project_release_sources_archive_path "$project" "$@" )
local sources_path=$( project_sources_path "$project" "$repository" "$@" )
- printf "Releasing sources archive for $project (with ${arguments:-no argument})\n"
+ printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument})"
archive_create "$archive_path" "$sources_path"
file_verification_create "$archive_path"
@@ -1196,10 +1192,10 @@ project_release_install() {
project_install_directory_missing_empty_error "$project" "$@"
- local files=$( cd "$install_path" && find -type f || true )
+ local files=$( find "$install_path" -type f || true )
local file
- echo "$files" | while read file
+ printf '%s\n' "$files" | while read -r file
do
path="$release_path/$file"
directory_path=$( dirname "$path" )
@@ -1223,10 +1219,10 @@ project_release_install_check() {
project_install_directory_missing_empty_error "$project" "$@"
- local files=$( cd "$install_path" && find -type f || true )
+ local files=$( find "$install_path" -type f || true )
local file
- echo "$files" | while read file
+ printf '%s\n' "$files" | while read -r file
do
path="$release_path/$file"
@@ -1257,12 +1253,12 @@ project_release_install_archive_create() {
shift
local prefix=$1
shift
- local arguments=$@
+ local arguments="$*"
local install_path=$( project_install_path "$project" "$@" )
local archive_path=$( project_release_archive_path "$project" "$prefix" "$@" )
- printf "Releasing $prefix archive for $project (with ${arguments:-no argument})\n"
+ printf '%s\n' "Releasing $prefix archive for $project (with ${arguments:-no argument})"
archive_create "$archive_path" "$install_path"
file_verification_create "$archive_path"
@@ -1305,12 +1301,12 @@ project_release_install_rootfs_create() {
shift
local prefix=$1
shift
- local arguments=$@
+ local arguments="$*"
local install_path=$( project_install_path "$project" "$@" )
local rootfs_path=$( project_release_rootfs_path "$project" "$prefix" "$@" )
- printf "Releasing $prefix rootfs for $project (with ${arguments:-no argument})\n"
+ printf '%s\n' "Releasing $prefix rootfs for $project (with ${arguments:-no argument})"
rootfs_create "$rootfs_path" "$install_path"
file_verification_create "$rootfs_path"
@@ -1421,7 +1417,7 @@ project_file_path() {
return 1
fi
- echo "$file_path"
+ printf '%s\n' "$file_path"
}
project_file_test() {
diff --git a/libs/tool b/libs/tool
index 3a9c4a1b..8ed70e18 100755
--- a/libs/tool
+++ b/libs/tool
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
@@ -15,16 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-TOOL_ACTIONS_GENERIC="usage update execute"
-TOOL_ACTIONS_HELPERS="arguments"
-TOOL_FUNCTIONS=$( for action in $TOOL_ACTIONS_GENERIC ; do echo "$action" "$action""_check" ; done ; echo "$TOOL_ACTIONS_HELPERS" )
+TOOL_ACTIONS_GENERIC=(usage update execute)
+TOOL_ACTIONS_GENERIC_IGNORE_CHECK=(usage update)
+TOOL_ACTIONS_HELPERS=(arguments)
tool_include() {
local tool=$1
local tool_path=$( tool_path "$tool" )
- unset -f $TOOL_FUNCTIONS
+ unset -f "${TOOL_ACTIONS[@]}"
. "$tool_path/$tool"
@@ -46,9 +46,9 @@ tool_helper_include() {
tool_check() {
local tool="${1##*/}"
- local tool_path="$(tool_path "${tool}")"
+ local tool_path="$(tool_path "$tool")"
- if ! [[ -f "${tool_path}/${tool}" ]]; then
+ if ! [[ -f "$tool_path/$tool" ]]; then
return 1
fi
}
@@ -79,7 +79,7 @@ tool_action() {
if ! tool_check "$tool"
then
- printf "Tool $tool check failed\n" >&2
+ printf '%s\n' "Tool $tool check failed" >&2
return 1
fi
@@ -97,7 +97,7 @@ tool_action() {
return 0
fi
- printf "Tool $tool $action (with ${arguments:-no argument})\n" >&2
+ printf '%s\n' "Tool $tool $action (with ${arguments:-no argument})" >&2
(
set -e
@@ -106,10 +106,10 @@ tool_action() {
if [ $? -ne 0 ]
then
- printf "\nTool $tool $action (with ${arguments:-no argument}) failed\n" >&2
+ printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed" >&2
return 1
else
- printf "\nTool $tool $action (with ${arguments:-no argument}) completed\n" >&2
+ printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) completed" >&2
fi
)
}
@@ -125,7 +125,7 @@ tool_action_check() {
if ! tool_check "$tool"
then
- printf "Tool $tool check failed\n" >&2
+ printf '%s\n' "Tool $tool check failed" >&2
return 1
fi
@@ -162,7 +162,7 @@ tool_action_helper() {
if ! tool_check "$tool"
then
- printf "Tool $tool check failed\n" >&2
+ printf '%s\n' "Tool $tool check failed" >&2
return 1
fi
@@ -193,19 +193,38 @@ tool_action_arguments_recursive() {
then
tool_action "$action" "$tool" "$@"
else
- echo "$action_helper_arguments" | while read argument
+ printf '%s\n' "$action_helper_arguments" | while read argument
do
tool_action_arguments_recursive "$action" "$tool" "$@" "$argument"
done
fi
}
+tool_arguments_targets() {
+ local tool="$1"
+ shift
+
+ local tool_path="$(tool_path "$tool")"
+ local targets_path="$tool_path/$CONFIGS"
+ local argument
+
+ for argument in "$@"; do
+ targets_path="$targets_path/$argument"
+ done
+
+ targets_path="$targets_path/$TARGETS"
+
+ if [[ -f "$targets_path" ]]; then
+ cat "$targets_path"
+ fi
+}
+
tool_path() {
local tool=$1
local tool_path="$root/$TOOLS/$tool"
- echo "$tool_path"
+ printf '%s\n' "$tool_path"
}
tool_sources_path() {
@@ -224,7 +243,7 @@ tool_sources_path() {
if directory_filled_check "$path"
then
- echo "$path"
+ printf '%s\n' "$path"
return
fi
done
@@ -234,23 +253,23 @@ tool_usage_actions() {
local tool=$1
shift
- printf "\nGeneric actions:\n"
+ printf '\n%s\n' 'Generic actions:'
- for action in $TOOL_ACTIONS_GENERIC
+ for action in "${TOOL_ACTIONS_GENERIC[@]}"
do
if function_check "$action"
then
- printf " $action\n"
+ printf '%s\n' " $action"
fi
done
if [ $# -gt 0 ]
then
- printf "\nSpecific actions:\n"
+ printf '\n%s\n' 'Specific actions:'
for action in "$@"
do
- printf " $action\n"
+ printf '%s\n' " $action"
done
fi
}
@@ -259,7 +278,7 @@ tool_usage_arguments() {
local tool=$1
shift
- printf "\nArguments:\n"
+ printf '\n%s\n' 'Arguments:'
tool_usage_arguments_recursive "$tool" " " "$@"
}
@@ -275,9 +294,9 @@ tool_usage_arguments_recursive() {
if ! [ -z "$action_helper_arguments" ]
then
- echo "$action_helper_arguments" | while read argument
+ printf '%s\n' "$action_helper_arguments" | while read argument
do
- printf "$spacing$argument\n"
+ printf '%s\n' "$spacing$argument"
tool_usage_arguments_recursive "$tool" " $spacing" "$@" "$argument"
done
fi
@@ -316,7 +335,7 @@ tool_file_path() {
return 1
fi
- echo "$file_path"
+ printf '%s\n' "$file_path"
}
tool_file_test() {