diff options
Diffstat (limited to 'libs')
-rwxr-xr-x | libs/common | 202 | ||||
-rwxr-xr-x | libs/git | 112 | ||||
-rwxr-xr-x | libs/project | 359 | ||||
-rwxr-xr-x | libs/tool | 83 |
4 files changed, 396 insertions, 360 deletions
diff --git a/libs/common b/libs/common index b1d2f571..43fe3b08 100755 --- a/libs/common +++ b/libs/common @@ -73,17 +73,39 @@ download_wrapper() { shift local uris=($@) - # TODO: Add support for curl, in addition - # to wget, for compatibility reasons - wget_options=( - --config=/dev/null - --secure-protocol=PFS - --directory-prefix="${download_dir}" - --continue - -- + local wget_options=( + '--config=/dev/null' + '--secure-protocol=PFS' + "--directory-prefix=$download_dir" + '--continue' + '--' ) - wget "${wget_options[@]}" "${uris[@]}" + 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() { @@ -91,24 +113,24 @@ diff_patch_file() { local patch_file_path="$2" # 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 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=$( printf '%s\n' "$path" | sed "s/ /\\\ /g" ) + path=$(printf '%s\n' "$path" | sed "s/ /\\\ /g") eval "arguments_list "$path"" } @@ -117,8 +139,8 @@ file_checksum_create() { local path=$1 local checksum_path="$path.$CHECKSUM" - local name=$( basename "$path" ) - local directory_path=$( dirname "$path" ) + local name=$(basename "$path") + local directory_path=$(dirname "$path") ( cd "$directory_path" @@ -130,12 +152,12 @@ file_checksum_check() { local path=$1 local checksum_path="$path.$CHECKSUM" - local name=$( basename "$path" ) - local directory_path=$( dirname "$path" ) + local name=$(basename "$path") + local directory_path=$(dirname "$path") - if ! [ -f "$checksum_path" ] + if ! [[ -f "$checksum_path" ]] then - printf '%s\n' 'Could not verify file checksum!' >&2 + printf 1>&2 '%s\n' 'Could not verify file checksum!' return 1 fi @@ -150,7 +172,7 @@ file_signature_create() { local signature_path="$path.$DSIG" - if [ -z "$RELEASE_KEY" ] + if [[ -z "$RELEASE_KEY" ]] then return 0 fi @@ -163,9 +185,9 @@ file_signature_check() { local signature_path="$path.$DSIG" - if ! [ -f "$signature_path" ] + if ! [[ -f "$signature_path" ]] then - printf '%s\n' 'Could not verify file signature!' >&2 + printf 1>&2 '%s\n' 'Could not verify file signature!' return 1 fi @@ -195,7 +217,7 @@ file_exists_check() { directory_filled_check() { local path=$1 - if [ -z "$( ls -A "$path" 2> /dev/null )" ] + if [[ -z "$(ls -A "$path" 2> /dev/null)" ]] then return 1 else @@ -206,29 +228,29 @@ directory_filled_check() { archive_files_create() { local source_path="$1" - 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}" + 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" - # Files in "${tarfiles_path}" are NUL terminated. + # 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}" + if git_check "$source_path"; then + git_files "$source_path" > "$tarfiles_path" + printf '%s\0' "$DOTTARFILES" >> "$tarfiles_path" else - find "${source_path}" -print0 | env LC_ALL='C.UTF-8' sort -z | sed -z "1d;s,^${source_path}/\\?,,;/^${DOTTARFILES}\$/d" > "${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 - for dotfile in "${revision_path}" \ - "${version_path}" \ - "${epoch_path}" \ - "${rnd_seed_path}" + for dotfile in "$revision_path" \ + "$version_path" \ + "$epoch_path" \ + "$rnd_seed_path" do - if [[ -f "${dotfile}" ]]; then - printf '%s\0' ".${dotfile##*.}" >> "${tarfiles_path}" + if [[ -f "$dotfile" ]]; then + printf '%s\0' ".${dotfile##*.}" >> "$tarfiles_path" fi done } @@ -236,10 +258,10 @@ archive_files_create() { archive_files_date() { local source_path="$1" - local epoch_path="${source_path}/${DOTEPOCH}" + local epoch_path="$source_path/$DOTEPOCH" - if [[ -n "${SOURCE_DATE_EPOCH}" ]]; then - find "${source_path}" -execdir 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 } @@ -248,24 +270,24 @@ archive_create() { local source_path="$2" local directory="$3" - local tarfiles_path="${source_path}/${DOTTARFILES}" - local directory_path="$(dirname "${archive_path}")" + local tarfiles_path="$source_path/$DOTTARFILES" + local directory_path="$(dirname "$archive_path")" - mkdir -p "${directory_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}" + 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" + --file="$archive_path" + --files-from="$tarfiles_path" + --transform="s,^,$directory/,S" --no-recursion --warning=no-filename-with-nuls --null @@ -275,7 +297,7 @@ archive_create() { ) ( - cd "${source_path}" + cd "$source_path" tar "${tar_options[@]}" ) } @@ -284,31 +306,31 @@ archive_extract() { 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}" + tar -xf "$archive_path" -ps -C "$destination_path" } rootfs_files_create() { local source_path="$1" - local directory="$(basename "${source_path}")" - local tarfiles_path="${source_path}/${DOTTARFILES}" + local directory="$(basename "$source_path")" + local tarfiles_path="$source_path/$DOTTARFILES" - # Files in "${tarfiles_path}" are NUL terminated. + # 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}" + 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 epoch_path="${source_path}/${DOTEPOCH}" + local epoch_path="$source_path/$DOTEPOCH" - if [[ -n "${SOURCE_DATE_EPOCH}" ]]; then - execute_root find "${source_path}" -execdir 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 } @@ -317,23 +339,23 @@ rootfs_create() { local source_path="$2" local directory="$3" - local tarfiles_path="${source_path}/${DOTTARFILES}" - local directory_path="$(dirname "${rootfs_path}")" + local tarfiles_path="$source_path/$DOTTARFILES" + local directory_path="$(dirname "$rootfs_path")" - mkdir -p "${directory_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}" + rootfs_files_create "$source_path" + rootfs_files_date "$source_path" local tar_options=( --create --xz - --file="${rootfs_path}" - --files-from="${tarfiles_path}" + --file="$rootfs_path" + --files-from="$tarfiles_path" --no-recursion --warning=no-filename-with-nuls --null @@ -343,12 +365,12 @@ rootfs_create() { ) ( - cd "${source_path}" + cd "$source_path" execute_root tar "${tar_options[@]}" ) - execute_root chmod 644 "${rootfs_path}" - execute_root chown "${USER}:${USER}" "${rootfs_path}" + execute_root chmod 644 "$rootfs_path" + execute_root chown "$USER:$USER" "$rootfs_path" } requirements() { @@ -357,11 +379,11 @@ requirements() { for requirement in "$@" do - requirement_path=$( which "$requirement" || true ) + requirement_path=$(which "$requirement" || true) - if [ -z "$requirement_path" ] + if [[ -z "$requirement_path" ]] then - printf '%s\n' "Missing requirement: $requirement" >&2 + printf 1>&2 '%s\n' "Missing requirement: $requirement" exit 1 fi done @@ -374,11 +396,11 @@ requirements_root() { for requirement in "$@" do # We need to keep stdout output to show the command. - requirement_path=$( execute_root which "$requirement" || true ) + requirement_path=$(execute_root which "$requirement" || true) - if [ -z "$requirement_path" ] + if [[ -z "$requirement_path" ]] then - printf '%s\n' "Missing requirement: $requirement" >&2 + printf 1>&2 '%s\n' "Missing requirement: $requirement" exit 1 fi done @@ -392,7 +414,7 @@ arguments_concat() { for argument in "$@" do - if ! [ -z "$concat" ] + if [[ -n "$concat" ]] then concat="$concat""$delimiter""$argument" else @@ -404,18 +426,18 @@ arguments_concat() { } execute_root() { - local sudo=$( which sudo 2> /dev/null || true ) + local sudo=$(which sudo 2> /dev/null || true) local arguments - printf '%s' 'Running command as root: ' >&2 - printf '%b\n' "$*" >&2 + printf 1>&2 '%s' 'Running command as root: ' + printf 1>&2 '%b\n' "$*" - if ! [ -z "$sudo" ] + if [[ -n "$sudo" ]] then sudo "$@" else # Quote arguments for eval through su. - arguments=$( printf '%q ' "$@" ) + arguments=$(printf '%q ' "$@") su -c "$arguments" fi } @@ -63,7 +63,7 @@ git_branch_create() { cd "$repository_path" git checkout -B "$branch" - if ! [ -z "$revision" ] + if [[ -n "$revision" ]] then git reset --hard "$revision" fi @@ -96,13 +96,13 @@ git_branch_check() { ( cd "$repository_path" 2> /dev/null > /dev/null - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then return 1 fi git rev-parse --verify "$branch" 2> /dev/null > /dev/null - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then return 1 fi @@ -123,13 +123,13 @@ git_fetch_check() { ( cd "$repository_path" 2> /dev/null > /dev/null - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then return 1 fi - local output=$( git fetch --dry-run origin 2>&1 ) - if ! [ -z "$output" ] + local output=$(git fetch --dry-run origin 2>&1) + if [[ -n "$output" ]] then return 1 fi @@ -205,7 +205,7 @@ git_files() { local repository_path="$1" ( - cd "${repository_path}" + cd "$repository_path" # Reproducible sorting. git ls-files -z | env LC_ALL='C.UTF-8' sort -z ) @@ -220,7 +220,7 @@ git_project_repository_path() { git_project_check() { local repository=$1 - local repository_path=$( git_project_repository_path "$repository" ) + local repository_path=$(git_project_repository_path "$repository") git_check "$repository_path" } @@ -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 } @@ -257,8 +257,8 @@ git_project_clone() { shift local urls=$@ - local repository_path=$( git_project_repository_path "$repository" ) - local directory_path=$( dirname "$repository_path" ) + local repository_path=$(git_project_repository_path "$repository") + local directory_path=$(dirname "$repository_path") local url mkdir -p "$directory_path" @@ -270,7 +270,7 @@ git_project_clone() { do git_clone "$repository_path" "$url" - if [ $? -eq 0 ] + if [[ $? -eq 0 ]] then return 0 fi @@ -297,11 +297,11 @@ git_project_prepare_blobs() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) - local blobs_path=$( project_blobs_path "$project" "$@" ) + local repository_path=$(git_project_repository_path "$repository") + local blobs_path=$(project_blobs_path "$project" "$@") local blob - if ! [ -f "$blobs_path" ] + if ! [[ -f "$blobs_path" ]] then return fi @@ -320,7 +320,7 @@ git_project_prepare_patch() { local repository=$1 shift - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" local prepare_branch local prepare_path @@ -330,9 +330,9 @@ git_project_prepare_patch() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -344,7 +344,7 @@ git_project_prepare_patch() { local revision_path="$configs_path/$path/$REVISION" - if ! [ -f "$revision_path" ] + if ! [[ -f "$revision_path" ]] then continue fi @@ -353,7 +353,7 @@ git_project_prepare_patch() { prepare_path=$path done - if ! [ -z "$prepare_branch" ] + if [[ -n "$prepare_branch" ]] then git_project_patch_recursive "$project" "$repository" "$prepare_branch" "$prepare_path" fi @@ -365,8 +365,8 @@ git_project_prepare_revision() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) - local project_path=$( project_path "$project" ) + local repository_path=$(git_project_repository_path "$repository") + local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" local prepare_branch local prepare_revision @@ -376,9 +376,9 @@ git_project_prepare_revision() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -390,16 +390,16 @@ git_project_prepare_revision() { local revision_path="$configs_path/$path/$REVISION" - if ! [ -f "$revision_path" ] + if ! [[ -f "$revision_path" ]] then continue fi prepare_branch=$branch - prepare_revision=$( cat "$revision_path" ) + prepare_revision=$(cat "$revision_path") done - if ! [ -z "$prepare_branch" ] + if [[ -n "$prepare_branch" ]] then git_branch_create "$repository_path" "$prepare_branch" "$prepare_revision" fi @@ -411,8 +411,8 @@ git_project_prepare_check() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) - local project_path=$( project_path "$project" ) + local repository_path=$(git_project_repository_path "$repository") + local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" local prepare_branch local branch=$project @@ -421,9 +421,9 @@ git_project_prepare_check() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -435,7 +435,7 @@ git_project_prepare_check() { local revision_path="$configs_path/$path/$REVISION" - if ! [ -f "$revision_path" ] + if ! [[ -f "$revision_path" ]] then continue fi @@ -443,7 +443,7 @@ git_project_prepare_check() { prepare_branch=$branch done - if ! [ -z "$prepare_branch" ] + if [[ -n "$prepare_branch" ]] then git_branch_check "$repository_path" "$prepare_branch" fi @@ -455,14 +455,14 @@ git_project_prepare_clean() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) + local repository_path=$(git_project_repository_path "$repository") local prepare_branch local branch=$project local argument for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -475,7 +475,7 @@ git_project_prepare_clean() { prepare_branch=$branch done - if ! [ -z "$prepare_branch" ] + if [[ -n "$prepare_branch" ]] then # Let's not worry about missing branches. ( @@ -483,7 +483,7 @@ git_project_prepare_clean() { git_branch_delete "$repository_path" "$prepare_branch" - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then return 0 fi @@ -497,14 +497,14 @@ git_project_checkout() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) + local repository_path=$(git_project_repository_path "$repository") local checkout_branch local branch=$project local argument for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -517,7 +517,7 @@ git_project_checkout() { checkout_branch=$branch done - if ! [ -z "$checkout_branch" ] + if [[ -n "$checkout_branch" ]] then git_branch_checkout "$repository_path" "$checkout_branch" git_submodule_update "$repository_path" @@ -530,7 +530,7 @@ git_project_update() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) + local repository_path=$(git_project_repository_path "$repository") git_fetch "$repository_path" git_branch_checkout "$repository_path" "$ORIGIN_HEAD" @@ -557,14 +557,14 @@ git_project_release() { shift local arguments=$@ - local repository_path=$( git_project_repository_path "$repository" ) + local repository_path=$(git_project_repository_path "$repository") local release_branch local branch=$project local argument for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -577,7 +577,7 @@ git_project_release() { release_branch=$branch done - if ! [ -z "$release_branch" ] + if [[ -n "$release_branch" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" local sources_path="$root/$SOURCES/$repository" @@ -598,14 +598,14 @@ git_project_release_check() { local repository=$1 shift - local repository_path=$( git_project_repository_path "$repository" ) + local repository_path=$(git_project_repository_path "$repository") local release_branch local branch=$project local argument for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -618,13 +618,13 @@ git_project_release_check() { release_branch=$branch done - if ! [ -z "$release_branch" ] + if [[ -n "$release_branch" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" file_exists_check "$archive_path" - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then return 1 else diff --git a/libs/project b/libs/project index 8eaf0d2d..4c8b2fff 100755 --- a/libs/project +++ b/libs/project @@ -24,7 +24,7 @@ INSTALL_REGEX='\([^:]*\):\(.*\)' project_include() { local project=$1 - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") unset -f "${PROJECT_ACTIONS[@]}" @@ -36,10 +36,10 @@ project_include() { project_helper_include() { local project=$1 - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local include="$project_path/$project-helper" - if [ -f "$include" ] + if [[ -f "$include" ]] then source "$include" fi @@ -48,9 +48,9 @@ project_helper_include() { 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 } @@ -79,14 +79,14 @@ project_action() { ( set +e - project_action_check "${action}" "${project}" "$@" + project_action_check "$action" "$project" "$@" - printf '%s\n' "Project ${project} ${action} (with ${arguments:-no argument})" >&2 + printf 1>&2 '%s\n' "Project $project $action (with ${arguments:-no argument})" - if "${action}" "$@"; then - printf '\n%s\n' "Project ${project} ${action} (with ${arguments:-no argument}) completed" >&2 + if "$action" "$@"; then + printf 1>&2 '\n%s\n' "Project $project $action (with ${arguments:-no argument}) completed" else - printf '\n%s\n' "Project ${project} ${action} (with ${arguments:-no argument}) failed" >&2 + printf 1>&2 '\n%s\n' "Project $project $action (with ${arguments:-no argument}) failed" return 1 fi ) @@ -105,8 +105,8 @@ project_action_check() { 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 @@ -124,11 +124,11 @@ project_action_helper() { local project="$1" shift - if ! function_check "${helper}"; then + if ! function_check "$helper"; then return 0 fi - "${helper}" "$@" + "$helper" "$@" } project_action_arguments() { @@ -137,10 +137,10 @@ project_action_arguments() { local project="$1" shift - project_include "${project}" + project_include "$project" - project_action_arguments_verify_recursive "${action}" "${project}" "$@" - project_action_arguments_recursive "${action}" "${project}" "$@" + project_action_arguments_verify_recursive "$action" "$project" "$@" + project_action_arguments_recursive "$action" "$project" "$@" } project_action_arguments_verify_recursive() { @@ -165,18 +165,18 @@ project_action_arguments_verify_recursive() { return 0 fi - action_helper_arguments="$(project_action_helper 'arguments' "${project}" "$@")" + action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")" - if [[ -n "${action_helper_arguments}" ]]; then - test="$(printf '%s\n' "${action_helper_arguments}" | grep -e "^${argument}\$" || true)" + if [[ -n "$action_helper_arguments" ]]; then + test="$(printf '%s\n' "$action_helper_arguments" | grep -e "^$argument\$" || true)" - if [[ -z "${test}" ]]; then - printf '%s\n' "Invalid argument ${argument} for project ${project} action ${action}" >&2 + if [[ -z "$test" ]]; then + printf 1>&2 '%s\n' "Invalid argument $argument for project $project action $action" return 1 fi fi - project_action_arguments_verify_recursive "${action}" "${project}" "$@" + project_action_arguments_verify_recursive "$action" "$project" "$@" } project_action_arguments_recursive() { @@ -187,28 +187,23 @@ project_action_arguments_recursive() { local action_helper_arguments local argument - local ifs_save - action_helper_arguments="$(project_action_helper 'arguments' "${project}" "$@" || true)" + action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@" || true)" - if [[ -z "${action_helper_arguments}" ]]; then - project_action "${action}" "${project}" "$@" + 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 $(printf '%s\n' "${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 } @@ -218,22 +213,22 @@ project_action_projects() { local project="$1" shift - 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 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 -r arguments; do - eval "project_action_arguments ${action} ${arguments}" - done < "${path}" + eval "project_action_arguments $action $arguments" + done < "$path" } project_path() { @@ -259,7 +254,7 @@ project_sources_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path-$argument" fi @@ -272,7 +267,7 @@ project_sources_path() { sources_path=$path done - if ! [ -z "$sources_path" ] + if [[ -n "$sources_path" ]] then printf '%s\n' "$sources_path" return @@ -292,7 +287,7 @@ project_sources_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -305,7 +300,7 @@ project_sources_path() { sources_path=$path done - if ! [ -z "$sources_path" ] + if [[ -n "$sources_path" ]] then printf '%s\n' "$sources_path" return @@ -316,7 +311,7 @@ project_sources_directory_filled_check() { local project=$1 shift - local sources_path=$( project_sources_path "$project" "$@" ) + local sources_path=$(project_sources_path "$project" "$@") test ! -z "$sources_path" } @@ -326,11 +321,11 @@ project_sources_directory_filled_error() { shift local arguments="$*" - local sources_path=$( project_sources_path "$project" "$@" ) + local sources_path=$(project_sources_path "$project" "$@") - if ! [ -z "$sources_path" ] + if [[ -n "$sources_path" ]] then - printf '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists" >&2 + printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists" return 1 else return 0 @@ -342,11 +337,11 @@ project_sources_directory_missing_empty_error() { shift local arguments="$*" - local sources_path=$( project_sources_path "$project" "$@" ) + local sources_path=$(project_sources_path "$project" "$@") - if [ -z "$sources_path" ] + if [[ -z "$sources_path" ]] then - printf '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty" >&2 + printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty" return 1 else return 0 @@ -363,14 +358,14 @@ project_sources_archive() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path-$argument" fi local archive="$path.$ARCHIVE" - if ! [ -f "$archive" ] + if ! [[ -f "$archive" ]] then continue fi @@ -378,7 +373,7 @@ project_sources_archive() { sources_archive=$archive done - if ! [ -z "$sources_archive" ] + if [[ -n "$sources_archive" ]] then printf '%s\n' "$sources_archive" fi @@ -389,8 +384,8 @@ project_sources_archive_extract() { shift local arguments="$*" - local archive=$( project_sources_archive "$project" "$@" ) - local destination=$( dirname "$archive" ) + local archive=$(project_sources_archive "$project" "$@") + local destination=$(dirname "$archive") printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})" @@ -404,11 +399,11 @@ project_sources_archive_update() { local arguments="$*" local repository=$project - local sources_path=$( project_sources_path "$project" "$repository" "$@" ) - local archive=$( project_sources_archive "$project" "$@" ) - local destination=$( dirname "$archive" ) + local sources_path=$(project_sources_path "$project" "$repository" "$@") + local archive=$(project_sources_archive "$project" "$@") + local destination=$(dirname "$archive") - if [ -d "$sources_path" ] + if [[ -d "$sources_path" ]] then rm -rf "$sources_path" fi @@ -424,10 +419,10 @@ project_sources_archive_missing_error() { shift local arguments="$*" - local archive=$( project_sources_archive "$project" "$@" ) - if [ -z "$archive" ] || ! [ -f "$archive" ] + local archive=$(project_sources_archive "$project" "$@") + if [[ -z "$archive" ]] || ! [[ -f "$archive" ]] then - printf '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})" >&2 + printf 1>&2 '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})" return 1 else return 0 @@ -438,8 +433,8 @@ project_sources_archive_missing_check() { local project=$1 shift - local archive=$( project_sources_archive "$project" "$@" ) - if [ -z "$archive" ] || ! [ -f "$archive" ] + local archive=$(project_sources_archive "$project" "$@") + if [[ -z "$archive" ]] || ! [[ -f "$archive" ]] then return 0 else @@ -453,18 +448,18 @@ project_sources_prepare() { # Not implemented yet / May end up not being needed #project_sources_prepare_blobs - project_sources_prepare_patch "${project}" "${sources_path}" "$@" + 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}" + 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}" + for patch in "$patches_path"/[!.]*.@(patch|diff); do + diff_patch_file "$sources_path" "$patch" done } @@ -472,16 +467,16 @@ project_blobs_path() { local project=$1 shift - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" local argument local path for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -491,7 +486,7 @@ project_blobs_path() { local blobs_path="$configs_path/$path/$BLOBS" - if [ -f "$blobs_path" ] + if [[ -f "$blobs_path" ]] then printf '%s\n' "$blobs_path" return @@ -505,16 +500,16 @@ project_blobs_ignore_path() { local project=$1 shift - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" local argument local path for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -524,7 +519,7 @@ project_blobs_ignore_path() { blobs_ignore_path="$configs_path/$path/$BLOBS_IGNORE" - if [ -f "$blobs_ignore_path" ] + if [[ -f "$blobs_ignore_path" ]] then printf '%s\n' "$blobs_ignore_path" return @@ -536,7 +531,7 @@ project_arguments_targets() { local project=$1 shift - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local targets_path="$project_path/$CONFIGS" local argument @@ -547,7 +542,7 @@ project_arguments_targets() { targets_path="$targets_path/$TARGETS" - if [ -f "$targets_path" ] + if [[ -f "$targets_path" ]] then cat "$targets_path" fi @@ -561,8 +556,8 @@ project_usage_actions() { ( for action in "${PROJECT_ACTIONS_GENERIC[@]}"; do - if function_check "${action}"; then - printf '%s\n' " ${action}" + if function_check "$action"; then + printf '%s\n' " $action" fi done ) @@ -572,7 +567,7 @@ project_usage_actions() { ( for action in "$@"; do - printf '%s\n' " ${action}" + printf '%s\n' " $action" done ) fi @@ -584,7 +579,7 @@ project_usage_arguments() { printf '\n%s\n' 'Arguments:' - project_usage_arguments_recursive "${project}" ' ' "$@" + project_usage_arguments_recursive "$project" ' ' "$@" } project_usage_arguments_recursive() { @@ -596,12 +591,12 @@ project_usage_arguments_recursive() { local action_helper_arguments local argument - action_helper_arguments="$(project_action_helper 'arguments' "${project}" "$@")" + action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")" - 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}" + 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 } @@ -648,25 +643,25 @@ project_download_archive() { 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}" + 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}" + 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}" + 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}" + mv "${archive_path%.tar*}" "$sources_path" fi # Patch the source, if necessary - project_sources_prepare "${project}" "${sources_path}" + project_sources_prepare "$project" "$sources_path" } project_download_check_archive() { @@ -674,7 +669,7 @@ project_download_check_archive() { local sources_path="$2" # TODO: Write the following function - #project_sources_archive_extract_check "${project}" "${sources_path}" + #project_sources_archive_extract_check "$project" "$sources_path" } project_extract() { @@ -685,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 } @@ -742,8 +737,8 @@ project_build_check() { local project=$1 shift - local project_path=$( project_path "$project" ) - local build_path=$( project_build_path "$project" "$@" ) + local project_path=$(project_path "$project") + local build_path=$(project_build_path "$project" "$@") local source_file_path local argument local rule @@ -751,9 +746,9 @@ project_build_check() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -763,20 +758,20 @@ project_build_check() { configs_install_path="$project_path/$CONFIGS/$path/$INSTALL" - if ! [ -f "$configs_install_path" ] + if ! [[ -f "$configs_install_path" ]] then continue fi while read -r rule do - source=$( printf '%s\n' "$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 -r source_file_path do - if ! [ -f "$source_file_path" ] && ! [ -d "$source_file_path" ] + if ! [[ -f "$source_file_path" ]] && ! [[ -d "$source_file_path" ]] then false fi @@ -805,11 +800,11 @@ project_build_directory_missing_empty_error() { shift local arguments="$*" - local build_path=$( project_build_path "$project" "$@" ) + local build_path=$(project_build_path "$project" "$@") if ! directory_filled_check "$build_path" then - printf '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty" >&2 + printf 1>&2 '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty" return 1 else return 0 @@ -820,9 +815,9 @@ project_install() { local project=$1 shift - local project_path=$( project_path "$project" ) - local build_path=$( project_build_path "$project" "$@" ) - local install_path=$( project_install_path "$project" "$@" ) + local project_path=$(project_path "$project") + local build_path=$(project_build_path "$project" "$@") + local install_path=$(project_install_path "$project" "$@") local source_file_path local argument local rule @@ -831,9 +826,9 @@ project_install() { # Install built files first. for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -843,7 +838,7 @@ project_install() { configs_install_path="$project_path/$CONFIGS/$path/$INSTALL" - if ! [ -f "$configs_install_path" ] + if ! [[ -f "$configs_install_path" ]] then continue fi @@ -852,12 +847,12 @@ project_install() { while read -r rule do - source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" ) + source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g") source_path="$build_path/$source" - destination=$( printf '%s\n' "$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" ) + destination_directory_path=$(dirname "$destination_path") mkdir -p "$destination_directory_path" @@ -874,9 +869,9 @@ project_install() { # Install install files then. for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -886,19 +881,19 @@ project_install() { install_install_path="$project_path/$INSTALL/$path/$INSTALL" - if ! [ -f "$install_install_path" ] + if ! [[ -f "$install_install_path" ]] then continue fi while read -r rule do - source=$( printf '%s\n' "$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=$( printf '%s\n' "$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" ) + destination_directory_path=$(dirname "$destination_path") mkdir -p "$destination_directory_path" @@ -915,9 +910,9 @@ project_install_check() { local project=$1 shift - local project_path=$( project_path "$project" ) - local build_path=$( project_build_path "$project" "$@" ) - local install_path=$( project_install_path "$project" "$@" ) + local project_path=$(project_path "$project") + local build_path=$(project_build_path "$project" "$@") + local install_path=$(project_install_path "$project" "$@") local argument local rule local path @@ -925,9 +920,9 @@ project_install_check() { # Install built files first. for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -937,7 +932,7 @@ project_install_check() { configs_install_path="$project_path/$CONFIGS/$path/$INSTALL" - if ! [ -f "$configs_install_path" ] + if ! [[ -f "$configs_install_path" ]] then continue fi @@ -946,10 +941,10 @@ project_install_check() { while read -r rule do - destination=$( printf '%s\n' "$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" ] + if ! [[ -f "$destination_path" ]] && ! [[ -d "$destination_path" ]] then false fi @@ -961,9 +956,9 @@ project_install_check() { # Install install files then. for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -973,17 +968,17 @@ project_install_check() { install_install_path="$project_path/$INSTALL/$path/$INSTALL" - if ! [ -f "$install_install_path" ] + if ! [[ -f "$install_install_path" ]] then continue fi while read -r rule do - destination=$( printf '%s\n' "$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" ] + if ! [[ -f "$destination_path" ]] && ! [[ -d "$destination_path" ]] then false fi @@ -1011,11 +1006,11 @@ project_install_directory_missing_empty_error() { shift local arguments="$*" - local install_path=$( project_install_path "$project" "$@" ) + local install_path=$(project_install_path "$project" "$@") if ! directory_filled_check "$install_path" then - printf '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty" >&2 + printf 1>&2 '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty" return 1 else return 0 @@ -1030,9 +1025,9 @@ project_release_path() { local release_path="$root/$RELEASE/$prefix" # Special care for tools and systems, that depend on the host arch. - if [ "$prefix" = "$SYSTEMS" ] || [ "$prefix" = "$TOOLS" ] + if [[ "$prefix" = "$SYSTEMS" ]] || [[ "$prefix" = "$TOOLS" ]] then - local machine=$( uname -m ) + local machine=$(uname -m) release_path="$release_path/$machine/$project" else @@ -1048,7 +1043,7 @@ project_release_archive_path() { local prefix=$1 shift - local release_path=$( project_release_path "$project" "$prefix" ) + local release_path=$(project_release_path "$project" "$prefix") local argument local path="$project" @@ -1068,7 +1063,7 @@ project_release_rootfs_path() { local prefix=$1 shift - local release_path=$( project_release_path "$project" "$prefix" ) + local release_path=$(project_release_path "$project" "$prefix") local argument local path="$project" @@ -1093,7 +1088,7 @@ project_release_sources_archive_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path-$argument" fi @@ -1108,7 +1103,7 @@ project_release_sources_archive_path() { release_path=$path done - if ! [ -z "$release_path" ] + if [[ -n "$release_path" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$ARCHIVE" @@ -1122,8 +1117,8 @@ project_release_sources_archive_create() { local arguments="$*" local repository=$project - local archive_path=$( project_release_sources_archive_path "$project" "$@" ) - local sources_path=$( project_sources_path "$project" "$repository" "$@" ) + local archive_path=$(project_release_sources_archive_path "$project" "$@") + local sources_path=$(project_sources_path "$project" "$repository" "$@") printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument})" @@ -1135,8 +1130,8 @@ project_release_sources_archive_exists_check() { local project=$1 shift - local archive_path=$( project_release_sources_archive_path "$project" "$@" ) - if [ -z "$archive_path" ] || ! [ -f "$archive_path" ] + local archive_path=$(project_release_sources_archive_path "$project" "$@") + if [[ -z "$archive_path" ]] || ! [[ -f "$archive_path" ]] then return 1 else @@ -1190,20 +1185,20 @@ project_release_install() { local prefix=$1 shift - local install_path=$( project_install_path "$project" "$@" ) - local release_path=$( project_release_path "$project" "$prefix" ) + local install_path=$(project_install_path "$project" "$@") + local release_path=$(project_release_path "$project" "$prefix") local directory_path local path project_install_directory_missing_empty_error "$project" "$@" - local files=$( find "$install_path" -type f || true ) + local files=$(find "$install_path" -type f || true) local file printf '%s\n' "$files" | while read -r file do path="$release_path/$file" - directory_path=$( dirname "$path" ) + directory_path=$(dirname "$path") mkdir -p "$directory_path" @@ -1218,13 +1213,13 @@ project_release_install_check() { local prefix=$1 shift - local install_path=$( project_install_path "$project" "$@" ) - local release_path=$( project_release_path "$project" "$prefix" ) + local install_path=$(project_install_path "$project" "$@") + local release_path=$(project_release_path "$project" "$prefix") local path project_install_directory_missing_empty_error "$project" "$@" - local files=$( find "$install_path" -type f || true ) + local files=$(find "$install_path" -type f || true) local file printf '%s\n' "$files" | while read -r file @@ -1260,8 +1255,8 @@ project_release_install_archive_create() { shift local arguments="$*" - local install_path=$( project_install_path "$project" "$@" ) - local archive_path=$( project_release_archive_path "$project" "$prefix" "$@" ) + local install_path=$(project_install_path "$project" "$@") + local archive_path=$(project_release_archive_path "$project" "$prefix" "$@") printf '%s\n' "Releasing $prefix archive for $project (with ${arguments:-no argument})" @@ -1275,7 +1270,7 @@ project_release_install_archive_exists_check() { local prefix=$1 shift - local archive_path=$( project_release_archive_path "$project" "$prefix" "$@" ) + local archive_path=$(project_release_archive_path "$project" "$prefix" "$@") file_exists_check "$archive_path" } @@ -1308,8 +1303,8 @@ project_release_install_rootfs_create() { shift local arguments="$*" - local install_path=$( project_install_path "$project" "$@" ) - local rootfs_path=$( project_release_rootfs_path "$project" "$prefix" "$@" ) + local install_path=$(project_install_path "$project" "$@") + local rootfs_path=$(project_release_rootfs_path "$project" "$prefix" "$@") printf '%s\n' "Releasing $prefix rootfs for $project (with ${arguments:-no argument})" @@ -1323,7 +1318,7 @@ project_release_install_rootfs_exists_check() { local prefix=$1 shift - local rootfs_path=$( project_release_rootfs_path "$project" "$prefix" "$@" ) + local rootfs_path=$(project_release_rootfs_path "$project" "$prefix" "$@") file_exists_check "$rootfs_path" } @@ -1341,7 +1336,7 @@ project_clean_build() { local project=$1 shift - local build_path=$( project_build_path "$project" "$@" ) + local build_path=$(project_build_path "$project" "$@") rm -rf "$build_path" } @@ -1350,7 +1345,7 @@ project_clean_install() { local project=$1 shift - local install_path=$( project_install_path "$project" "$@" ) + local install_path=$(project_install_path "$project" "$@") rm -rf "$install_path" } @@ -1363,7 +1358,7 @@ project_clean_release() { for prefix in "$SOURCES" "$SYSTEMS" "$IMAGES" "$TOOLS" "$DOCS" do - local release_path=$( project_release_path "$project" "$prefix" ) + local release_path=$(project_release_path "$project" "$prefix") rm -rf "$release_path" done @@ -1383,7 +1378,7 @@ project_clean_rootfs_install() { local project=$1 shift - local install_path=$( project_install_path "$project" "$@" ) + local install_path=$(project_install_path "$project" "$@") execute_root rm -rf "$install_path" @@ -1397,19 +1392,19 @@ project_file_path() { local file=$1 shift - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local path="$project_path/$directory" local argument local file_path for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path/$argument" fi - if ! [ -f "$path/$file" ] + if ! [[ -f "$path/$file" ]] then continue fi @@ -1417,7 +1412,7 @@ project_file_path() { file_path="$path/$file" done - if [ -z "$file_path" ] + if [[ -z "$file_path" ]] then return 1 fi @@ -1426,15 +1421,15 @@ project_file_path() { } project_file_test() { - local file_path=$( project_file_path "$@" ) + local file_path=$(project_file_path "$@") test -f "$file_path" } project_file_contents() { - local file_path=$( project_file_path "$@" ) + local file_path=$(project_file_path "$@") - if [ -f "$file_path" ] + if [[ -f "$file_path" ]] then cat "$file_path" fi @@ -1448,21 +1443,21 @@ project_file_contents_herit() { local file=$1 shift - local project_path=$( project_path "$project" ) + local project_path=$(project_path "$project") local path="$project_path/$directory" local argument local file_path for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path/$argument" fi file_path="$path/$file" - if ! [ -f "$file_path" ] + if ! [[ -f "$file_path" ]] then continue fi @@ -22,11 +22,11 @@ TOOL_ACTIONS_HELPERS=(arguments) tool_include() { local tool=$1 - local tool_path=$( tool_path "$tool" ) + local tool_path=$(tool_path "$tool") unset -f "${TOOL_ACTIONS[@]}" - . "$tool_path/$tool" + source "$tool_path/$tool" tool_helper_include "$tool" } @@ -34,21 +34,21 @@ tool_include() { tool_helper_include() { local tool=$1 - local tool_path=$( tool_path "$tool" ) + local tool_path=$(tool_path "$tool") local include="$tool_path/$tool-helper" - if [ -f "$include" ] + if [[ -f "$include" ]] then - . "$include" + source "$include" fi } 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,13 +79,13 @@ tool_action() { if ! tool_check "$tool" then - printf '%s\n' "Tool $tool check failed" >&2 + printf 1>&2 '%s\n' "Tool $tool check failed" return 1 fi tool_action_check "$action" "$tool" "$@" - if [ $? -eq 0 ] + if [[ $? -eq 0 ]] then return 0 fi @@ -97,19 +97,19 @@ tool_action() { return 0 fi - printf '%s\n' "Tool $tool $action (with ${arguments:-no argument})" >&2 + printf 1>&2 '%s\n' "Tool $tool $action (with ${arguments:-no argument})" ( set -e "$action" "$@" ) - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then - printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed" >&2 + printf 1>&2 '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed" return 1 else - printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) completed" >&2 + printf 1>&2 '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) completed" fi ) } @@ -125,7 +125,7 @@ tool_action_check() { if ! tool_check "$tool" then - printf '%s\n' "Tool $tool check failed" >&2 + printf 1>&2 '%s\n' "Tool $tool check failed" return 1 fi @@ -138,7 +138,7 @@ tool_action_check() { for tool_force in $TOOLS_FORCE do - if [ "$tool_force" = "$tool" ] + if [[ "$tool_force" = "$tool" ]] then return 1 fi @@ -162,7 +162,7 @@ tool_action_helper() { if ! tool_check "$tool" then - printf '%s\n' "Tool $tool check failed" >&2 + printf 1>&2 '%s\n' "Tool $tool check failed" return 1 fi @@ -186,10 +186,10 @@ tool_action_arguments_recursive() { local tool=$1 shift - local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" ) + local action_helper_arguments=$(tool_action_helper "arguments" "$tool" "$@") local argument - if [ $? -ne 0 ] || [ -z "$action_helper_arguments" ] + if [[ $? -ne 0 ]] || [[ -z "$action_helper_arguments" ]] then tool_action "$action" "$tool" "$@" else @@ -200,6 +200,25 @@ tool_action_arguments_recursive() { 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 @@ -217,7 +236,7 @@ tool_sources_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -244,7 +263,7 @@ tool_usage_actions() { fi done - if [ $# -gt 0 ] + if [[ $# -gt 0 ]] then printf '\n%s\n' 'Specific actions:' @@ -270,10 +289,10 @@ tool_usage_arguments_recursive() { local spacing=$1 shift - local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" ) + local action_helper_arguments=$(tool_action_helper "arguments" "$tool" "$@") local argument - if ! [ -z "$action_helper_arguments" ] + if [[ -n "$action_helper_arguments" ]] then printf '%s\n' "$action_helper_arguments" | while read argument do @@ -291,19 +310,19 @@ tool_file_path() { local file=$1 shift - local tool_path=$( tool_path "$tool" ) + local tool_path=$(tool_path "$tool") local path="$tool_path/$directory" local argument local file_path for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path/$argument" fi - if ! [ -f "$path/$file" ] + if ! [[ -f "$path/$file" ]] then continue fi @@ -311,7 +330,7 @@ tool_file_path() { file_path="$path/$file" done - if [ -z "$file_path" ] + if [[ -z "$file_path" ]] then return 1 fi @@ -320,15 +339,15 @@ tool_file_path() { } tool_file_test() { - local file_path=$( tool_file_path "$@" ) + local file_path=$(tool_file_path "$@") test -f "$file_path" } tool_file_contents() { - local file_path=$( tool_file_path "$@" ) + local file_path=$(tool_file_path "$@") - if [ -f "$file_path" ] + if [[ -f "$file_path" ]] then cat "$file_path" fi @@ -342,21 +361,21 @@ tool_file_contents_herit() { local file=$1 shift - local tool_path=$( tool_path "$tool" ) + local tool_path=$(tool_path "$tool") local path="$tool_path/$directory" local argument local file_path for argument in "" "$@" do - if ! [ -z "$argument" ] + if [[ -n "$argument" ]] then path="$path/$argument" fi file_path="$path/$file" - if ! [ -f "$file_path" ] + if ! [[ -f "$file_path" ]] then continue fi |