util/mb/google/hatch: fix style issues in shell script

* Use all caps for variables.
* Use a single exit code for failures.
* No need to popd before exiting the script.
* Do ${var,,} and ${var^^} into variables instead of using it everywhere.
* Add more punctuation in comments.
* Specify LC_ALL=C so that upper/lower case show the desired behavior.

Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org>
Change-Id: I63aa0aa633f36b9543e809fc42fac955da5960a3
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35605
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Andrew McRae <amcrae@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
Paul Fagerburg 2019-09-25 09:31:57 -06:00 committed by Patrick Georgi
parent 2422f8c21e
commit cad708d210
1 changed files with 26 additions and 26 deletions

View File

@ -13,6 +13,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
export LC_ALL=C
if [[ "$#" -ne 1 ]]; then if [[ "$#" -ne 1 ]]; then
echo "Usage: $0 variant_name" echo "Usage: $0 variant_name"
echo "e.g. $0 kohaku" echo "e.g. $0 kohaku"
@ -26,54 +28,52 @@ fi
# you to specify the baseboard as one of the cmdline arguments. # you to specify the baseboard as one of the cmdline arguments.
# #
# This is the name of the base board that we're cloning to make the variant. # This is the name of the base board that we're cloning to make the variant.
base="hatch" BASE="hatch"
# This is the name of the variant that is being cloned # This is the name of the variant that is being cloned.
# ${var,,} converts to all lowercase # ${var,,} converts to all lowercase; ${var^^} is all uppercase.
variant="${1,,}" VARIANT="${1,,}"
VARIANT_UPPER="${VARIANT^^}"
# This script and the templates live in util/mainboard/google/hatch # This script and the templates live in util/mainboard/google/hatch
# We need to create files in src/mainboard/google/hatch # We need to create files in src/mainboard/google/hatch
pushd "${BASH_SOURCE%/*}" || exit pushd "${BASH_SOURCE%/*}" || exit 1
SRC=$(pwd) SRC=$(pwd)
popd || exit popd || exit 1
pushd "${SRC}/../../../../src/mainboard/google/${base}" || { pushd "${SRC}/../../../../src/mainboard/google/${BASE}" || {
echo "The baseboard directory for ${base} does not exist."; echo "The baseboard directory for ${BASE} does not exist.";
exit; } exit 1; }
# Make sure the variant doesn't already exist # Make sure the variant doesn't already exist.
if [[ -e variants/${variant} ]]; then if [[ -e variants/${VARIANT} ]]; then
echo "variants/${variant} already exists." echo "variants/${VARIANT} already exists."
echo "Have you already created this variant?" echo "Have you already created this variant?"
popd || exit exit 1
exit 2
fi fi
# Start a branch. Use YMD timestamp to avoid collisions. # Start a branch. Use YMD timestamp to avoid collisions.
DATE=$(date +%Y%m%d) DATE=$(date +%Y%m%d)
git checkout -b "create_${variant}_${DATE}" git checkout -b "create_${VARIANT}_${DATE}" || exit 1
# Copy the template tree to the target # Copy the template tree to the target.
mkdir -p "variants/${variant}/" mkdir -p "variants/${VARIANT}/"
cp -pr "${SRC}/template/." "variants/${variant}/" cp -pr "${SRC}/template/." "variants/${VARIANT}/"
git add "variants/${variant}/" git add "variants/${VARIANT}/"
# Now add the new variant to Kconfig and Kconfig.name # Now add the new variant to Kconfig and Kconfig.name
# These files are in the current directory, e.g. src/mainboard/google/hatch # These files are in the current directory, e.g. src/mainboard/google/hatch
"${SRC}/kconfig.py" --name "${variant}" "${SRC}/kconfig.py" --name "${VARIANT}"
mv Kconfig.new Kconfig mv Kconfig.new Kconfig
mv Kconfig.name.new Kconfig.name mv Kconfig.name.new Kconfig.name
git add Kconfig Kconfig.name git add Kconfig Kconfig.name
# Now commit the files # Now commit the files.
git commit -sm "${base}: Create ${variant} variant git commit -sm "${BASE}: Create ${VARIANT} variant
BUG=none BUG=none
TEST=util/abuild/abuild -p none -t google/${base} -x -a TEST=util/abuild/abuild -p none -t google/${BASE} -x -a
make sure the build includes GOOGLE_${variant^^}" make sure the build includes GOOGLE_${VARIANT_UPPER}"
popd || exit
echo "Please check all the files (git show), make any changes you want," echo "Please check all the files (git show), make any changes you want,"
echo "and then push to coreboot HEAD:refs/for/master" echo "and then push to coreboot HEAD:refs/for/master"