diff options
author | Andrew Robbins <contact@andrewrobbins.info> | 2017-10-26 02:32:54 -0400 |
---|---|---|
committer | Andrew Robbins <contact@andrewrobbins.info> | 2017-10-28 23:30:01 -0400 |
commit | 85934d62d767a484fa560066b6edb69a18145690 (patch) | |
tree | 8136b2cdfe3bee1b8ed854d519811e953ca0e4a7 /libs | |
parent | c3f80f40f9e9b7bc3a57c3ed774dfdc1f46a8196 (diff) | |
download | librebootfr-85934d62d767a484fa560066b6edb69a18145690.tar.gz librebootfr-85934d62d767a484fa560066b6edb69a18145690.zip |
Replace usage of the '[' Bash builtin with '[['
There's no benefit to using the POSIX-style '[' test builtin
considering its '-a' and '-o' operators are unused in the Libreboot
build system. Plus, '[[' is safer with respect to any containing file
redirections (for example).
Prior, both '[' and '[[' were used throughout the codebase--a
disparity in usage which this change aims to eliminate.
Diffstat (limited to 'libs')
-rwxr-xr-x | libs/common | 16 | ||||
-rwxr-xr-x | libs/git | 58 | ||||
-rwxr-xr-x | libs/project | 96 | ||||
-rwxr-xr-x | libs/tool | 28 |
4 files changed, 99 insertions, 99 deletions
diff --git a/libs/common b/libs/common index 750886db..b7a7022e 100755 --- a/libs/common +++ b/libs/common @@ -155,7 +155,7 @@ file_checksum_check() { local name=$( basename "$path" ) local directory_path=$( dirname "$path" ) - if ! [ -f "$checksum_path" ] + if ! [[ -f "$checksum_path" ]] then printf 1>&2 '%s\n' 'Could not verify file checksum!' return 1 @@ -172,7 +172,7 @@ file_signature_create() { local signature_path="$path.$DSIG" - if [ -z "$RELEASE_KEY" ] + if [[ -z "$RELEASE_KEY" ]] then return 0 fi @@ -185,7 +185,7 @@ file_signature_check() { local signature_path="$path.$DSIG" - if ! [ -f "$signature_path" ] + if ! [[ -f "$signature_path" ]] then printf 1>&2 '%s\n' 'Could not verify file signature!' return 1 @@ -217,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 @@ -381,7 +381,7 @@ requirements() { do requirement_path=$( which "$requirement" || true ) - if [ -z "$requirement_path" ] + if [[ -z "$requirement_path" ]] then printf 1>&2 '%s\n' "Missing requirement: $requirement" exit 1 @@ -398,7 +398,7 @@ requirements_root() { # We need to keep stdout output to show the command. requirement_path=$( execute_root which "$requirement" || true ) - if [ -z "$requirement_path" ] + if [[ -z "$requirement_path" ]] then printf 1>&2 '%s\n' "Missing requirement: $requirement" exit 1 @@ -414,7 +414,7 @@ arguments_concat() { for argument in "$@" do - if ! [ -z "$concat" ] + if ! [[ -z "$concat" ]] then concat="$concat""$delimiter""$argument" else @@ -432,7 +432,7 @@ execute_root() { printf 1>&2 '%s' 'Running command as root: ' printf 1>&2 '%b\n' "$*" - if ! [ -z "$sudo" ] + if ! [[ -z "$sudo" ]] then sudo "$@" else @@ -63,7 +63,7 @@ git_branch_create() { cd "$repository_path" git checkout -B "$branch" - if ! [ -z "$revision" ] + if ! [[ -z "$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" ] + if ! [[ -z "$output" ]] then return 1 fi @@ -270,7 +270,7 @@ git_project_clone() { do git_clone "$repository_path" "$url" - if [ $? -eq 0 ] + if [[ $? -eq 0 ]] then return 0 fi @@ -301,7 +301,7 @@ git_project_prepare_blobs() { local blobs_path=$( project_blobs_path "$project" "$@" ) local blob - if ! [ -f "$blobs_path" ] + if ! [[ -f "$blobs_path" ]] then return fi @@ -330,9 +330,9 @@ git_project_prepare_patch() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$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 ! [[ -z "$prepare_branch" ]] then git_project_patch_recursive "$project" "$repository" "$prepare_branch" "$prepare_path" fi @@ -376,9 +376,9 @@ git_project_prepare_revision() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -390,7 +390,7 @@ git_project_prepare_revision() { local revision_path="$configs_path/$path/$REVISION" - if ! [ -f "$revision_path" ] + if ! [[ -f "$revision_path" ]] then continue fi @@ -399,7 +399,7 @@ git_project_prepare_revision() { prepare_revision=$( cat "$revision_path" ) done - if ! [ -z "$prepare_branch" ] + if ! [[ -z "$prepare_branch" ]] then git_branch_create "$repository_path" "$prepare_branch" "$prepare_revision" fi @@ -421,9 +421,9 @@ git_project_prepare_check() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$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 ! [[ -z "$prepare_branch" ]] then git_branch_check "$repository_path" "$prepare_branch" fi @@ -462,7 +462,7 @@ git_project_prepare_clean() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then branch="$branch-$argument" fi @@ -475,7 +475,7 @@ git_project_prepare_clean() { prepare_branch=$branch done - if ! [ -z "$prepare_branch" ] + if ! [[ -z "$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 @@ -504,7 +504,7 @@ git_project_checkout() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then branch="$branch-$argument" fi @@ -517,7 +517,7 @@ git_project_checkout() { checkout_branch=$branch done - if ! [ -z "$checkout_branch" ] + if ! [[ -z "$checkout_branch" ]] then git_branch_checkout "$repository_path" "$checkout_branch" git_submodule_update "$repository_path" @@ -564,7 +564,7 @@ git_project_release() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then branch="$branch-$argument" fi @@ -577,7 +577,7 @@ git_project_release() { release_branch=$branch done - if ! [ -z "$release_branch" ] + if ! [[ -z "$release_branch" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" local sources_path="$root/$SOURCES/$repository" @@ -605,7 +605,7 @@ git_project_release_check() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then branch="$branch-$argument" fi @@ -618,13 +618,13 @@ git_project_release_check() { release_branch=$branch done - if ! [ -z "$release_branch" ] + if ! [[ -z "$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 524e6222..72bd647a 100755 --- a/libs/project +++ b/libs/project @@ -39,7 +39,7 @@ project_helper_include() { local project_path=$( project_path "$project" ) local include="$project_path/$project-helper" - if [ -f "$include" ] + if [[ -f "$include" ]] then source "$include" fi @@ -254,7 +254,7 @@ project_sources_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path-$argument" fi @@ -267,7 +267,7 @@ project_sources_path() { sources_path=$path done - if ! [ -z "$sources_path" ] + if ! [[ -z "$sources_path" ]] then printf '%s\n' "$sources_path" return @@ -287,7 +287,7 @@ project_sources_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path/$argument" fi @@ -300,7 +300,7 @@ project_sources_path() { sources_path=$path done - if ! [ -z "$sources_path" ] + if ! [[ -z "$sources_path" ]] then printf '%s\n' "$sources_path" return @@ -323,7 +323,7 @@ project_sources_directory_filled_error() { local sources_path=$( project_sources_path "$project" "$@" ) - if ! [ -z "$sources_path" ] + if ! [[ -z "$sources_path" ]] then printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists" return 1 @@ -339,7 +339,7 @@ project_sources_directory_missing_empty_error() { local sources_path=$( project_sources_path "$project" "$@" ) - if [ -z "$sources_path" ] + if [[ -z "$sources_path" ]] then printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty" return 1 @@ -358,14 +358,14 @@ project_sources_archive() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path-$argument" fi local archive="$path.$ARCHIVE" - if ! [ -f "$archive" ] + if ! [[ -f "$archive" ]] then continue fi @@ -373,7 +373,7 @@ project_sources_archive() { sources_archive=$archive done - if ! [ -z "$sources_archive" ] + if ! [[ -z "$sources_archive" ]] then printf '%s\n' "$sources_archive" fi @@ -403,7 +403,7 @@ project_sources_archive_update() { local archive=$( project_sources_archive "$project" "$@" ) local destination=$( dirname "$archive" ) - if [ -d "$sources_path" ] + if [[ -d "$sources_path" ]] then rm -rf "$sources_path" fi @@ -420,7 +420,7 @@ project_sources_archive_missing_error() { local arguments="$*" local archive=$( project_sources_archive "$project" "$@" ) - if [ -z "$archive" ] || ! [ -f "$archive" ] + if [[ -z "$archive" ]] || ! [[ -f "$archive" ]] then printf 1>&2 '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})" return 1 @@ -434,7 +434,7 @@ project_sources_archive_missing_check() { shift local archive=$( project_sources_archive "$project" "$@" ) - if [ -z "$archive" ] || ! [ -f "$archive" ] + if [[ -z "$archive" ]] || ! [[ -f "$archive" ]] then return 0 else @@ -474,9 +474,9 @@ project_blobs_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -486,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 @@ -507,9 +507,9 @@ project_blobs_ignore_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -519,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 @@ -542,7 +542,7 @@ project_arguments_targets() { targets_path="$targets_path/$TARGETS" - if [ -f "$targets_path" ] + if [[ -f "$targets_path" ]] then cat "$targets_path" fi @@ -746,9 +746,9 @@ project_build_check() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -758,7 +758,7 @@ project_build_check() { configs_install_path="$project_path/$CONFIGS/$path/$INSTALL" - if ! [ -f "$configs_install_path" ] + if ! [[ -f "$configs_install_path" ]] then continue fi @@ -771,7 +771,7 @@ project_build_check() { # 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 @@ -826,9 +826,9 @@ project_install() { # Install built files first. for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -838,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 @@ -869,9 +869,9 @@ project_install() { # Install install files then. for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -881,7 +881,7 @@ project_install() { install_install_path="$project_path/$INSTALL/$path/$INSTALL" - if ! [ -f "$install_install_path" ] + if ! [[ -f "$install_install_path" ]] then continue fi @@ -920,9 +920,9 @@ project_install_check() { # Install built files first. for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -932,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 @@ -944,7 +944,7 @@ project_install_check() { 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 @@ -956,9 +956,9 @@ project_install_check() { # Install install files then. for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then - if [ -z "$path" ] + if [[ -z "$path" ]] then path="$argument" else @@ -968,7 +968,7 @@ project_install_check() { install_install_path="$project_path/$INSTALL/$path/$INSTALL" - if ! [ -f "$install_install_path" ] + if ! [[ -f "$install_install_path" ]] then continue fi @@ -978,7 +978,7 @@ project_install_check() { 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 @@ -1025,7 +1025,7 @@ 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 ) @@ -1088,7 +1088,7 @@ project_release_sources_archive_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path-$argument" fi @@ -1103,7 +1103,7 @@ project_release_sources_archive_path() { release_path=$path done - if ! [ -z "$release_path" ] + if ! [[ -z "$release_path" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$ARCHIVE" @@ -1131,7 +1131,7 @@ project_release_sources_archive_exists_check() { shift local archive_path=$( project_release_sources_archive_path "$project" "$@" ) - if [ -z "$archive_path" ] || ! [ -f "$archive_path" ] + if [[ -z "$archive_path" ]] || ! [[ -f "$archive_path" ]] then return 1 else @@ -1399,12 +1399,12 @@ project_file_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path/$argument" fi - if ! [ -f "$path/$file" ] + if ! [[ -f "$path/$file" ]] then continue fi @@ -1412,7 +1412,7 @@ project_file_path() { file_path="$path/$file" done - if [ -z "$file_path" ] + if [[ -z "$file_path" ]] then return 1 fi @@ -1429,7 +1429,7 @@ project_file_test() { project_file_contents() { local file_path=$( project_file_path "$@" ) - if [ -f "$file_path" ] + if [[ -f "$file_path" ]] then cat "$file_path" fi @@ -1450,14 +1450,14 @@ project_file_contents_herit() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path/$argument" fi file_path="$path/$file" - if ! [ -f "$file_path" ] + if ! [[ -f "$file_path" ]] then continue fi @@ -37,7 +37,7 @@ tool_helper_include() { local tool_path=$( tool_path "$tool" ) local include="$tool_path/$tool-helper" - if [ -f "$include" ] + if [[ -f "$include" ]] then source "$include" fi @@ -85,7 +85,7 @@ tool_action() { tool_action_check "$action" "$tool" "$@" - if [ $? -eq 0 ] + if [[ $? -eq 0 ]] then return 0 fi @@ -104,7 +104,7 @@ tool_action() { "$action" "$@" ) - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then printf 1>&2 '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed" return 1 @@ -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 @@ -189,7 +189,7 @@ tool_action_arguments_recursive() { 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 @@ -236,7 +236,7 @@ tool_sources_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path/$argument" fi @@ -263,7 +263,7 @@ tool_usage_actions() { fi done - if [ $# -gt 0 ] + if [[ $# -gt 0 ]] then printf '\n%s\n' 'Specific actions:' @@ -292,7 +292,7 @@ tool_usage_arguments_recursive() { local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" ) local argument - if ! [ -z "$action_helper_arguments" ] + if ! [[ -z "$action_helper_arguments" ]] then printf '%s\n' "$action_helper_arguments" | while read argument do @@ -317,12 +317,12 @@ tool_file_path() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path/$argument" fi - if ! [ -f "$path/$file" ] + if ! [[ -f "$path/$file" ]] then continue fi @@ -330,7 +330,7 @@ tool_file_path() { file_path="$path/$file" done - if [ -z "$file_path" ] + if [[ -z "$file_path" ]] then return 1 fi @@ -347,7 +347,7 @@ tool_file_test() { tool_file_contents() { local file_path=$( tool_file_path "$@" ) - if [ -f "$file_path" ] + if [[ -f "$file_path" ]] then cat "$file_path" fi @@ -368,14 +368,14 @@ tool_file_contents_herit() { for argument in "" "$@" do - if ! [ -z "$argument" ] + if ! [[ -z "$argument" ]] then path="$path/$argument" fi file_path="$path/$file" - if ! [ -f "$file_path" ] + if ! [[ -f "$file_path" ]] then continue fi |