diff options
author | Alistair Delva <adelva@google.com> | 2021-06-29 11:02:05 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-29 11:02:05 +0000 |
commit | 5d1b677d36c699e811167befb6a3198c3b8b7137 (patch) | |
tree | 92e30090a764fb12ffb7844eba6fe269c4778b4a | |
parent | b0a686f7fe95e76796da0029f639f85da629ce95 (diff) | |
parent | 6a7d81e7447cf68d92aeaa11adccb2925c62e245 (diff) | |
download | tests-5d1b677d36c699e811167befb6a3198c3b8b7137.tar.gz |
Convert build_rootfs.sh to google shell style am: 6a7d81e744
Original change: https://android-review.googlesource.com/c/kernel/tests/+/1672106
Change-Id: I347ea236a14c6e9a069935b0464a81772c15bf70
-rwxr-xr-x | net/test/build_rootfs.sh | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/net/test/build_rootfs.sh b/net/test/build_rootfs.sh index 5563d8a..874f678 100755 --- a/net/test/build_rootfs.sh +++ b/net/test/build_rootfs.sh @@ -16,6 +16,7 @@ # set -e +set -u SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) @@ -28,7 +29,7 @@ export LC_ALL=C usage() { echo -n "usage: $0 [-h] [-s bullseye] [-a i386|amd64|armhf|arm64] " - echo "[-m http://mirror/debian] [-n net_test.rootfs.`date +%Y%m%d`]" + echo "[-m http://mirror/debian] [-n net_test.rootfs.$(date +%Y%m%d)]" exit 1 } @@ -38,13 +39,13 @@ suite=bullseye arch=amd64 while getopts ":hs:a:m:n:" opt; do - case $opt in + case "${opt}" in h) usage ;; s) - if [[ "$OPTARG" != "bullseye" ]]; then - echo "Invalid suite: $OPTARG" >&2 + if [[ "${OPTARG}" != "bullseye" ]]; then + echo "Invalid suite: ${OPTARG}" >&2 usage fi suite="${OPTARG}" @@ -61,28 +62,28 @@ while getopts ":hs:a:m:n:" opt; do esac ;; m) - mirror=$OPTARG + mirror="${OPTARG}" ;; n) - name=$OPTARG + name="${OPTARG}" ;; \?) - echo "Invalid option: $OPTARG" >&2 + echo "Invalid option: ${OPTARG}" >&2 usage ;; :) - echo "Invalid option: $OPTARG requires an argument" >&2 + echo "Invalid option: ${OPTARG} requires an argument" >&2 usage ;; esac done if [[ -z "${name}" ]]; then - name=net_test.rootfs.${arch}.${suite}.`date +%Y%m%d` + name="net_test.rootfs.${arch}.${suite}.$(date +%Y%m%d)" fi # Switch to qemu-debootstrap for incompatible architectures -if [ "$arch" = "arm64" ]; then +if [ "${arch}" = "arm64" ]; then debootstrap=qemu-debootstrap fi @@ -93,10 +94,10 @@ failure() { trap failure ERR # Import the package list for this release -packages=`cat $SCRIPT_DIR/rootfs/$suite.list | xargs | tr -s ' ' ','` +packages=$(cat "${SCRIPT_DIR}/rootfs/${suite}.list" | xargs | tr -s ' ' ',') # For the debootstrap intermediates -tmpdir=`mktemp -d` +tmpdir=$(mktemp -d) tmpdir_remove() { echo "Removing temporary files.." >&2 sudo rm -rf "${tmpdir}" @@ -104,55 +105,54 @@ tmpdir_remove() { trap tmpdir_remove EXIT workdir="${tmpdir}/_" - mkdir "${workdir}" chmod 0755 "${workdir}" sudo chown root:root "${workdir}" # Run the debootstrap first -cd $workdir -sudo $debootstrap --arch=$arch --variant=minbase --include=$packages \ - $suite . $mirror +cd "${workdir}" +sudo "${debootstrap}" --arch="${arch}" --variant=minbase --include="${packages}" \ + "${suite}" . "${mirror}" # Workarounds for bugs in the debootstrap suite scripts -for mount in `cat /proc/mounts | cut -d' ' -f2 | grep -e ^$workdir`; do - echo "Unmounting mountpoint $mount.." >&2 - sudo umount $mount +for mount in $(cat /proc/mounts | cut -d' ' -f2 | grep -e "^${workdir}"); do + echo "Unmounting mountpoint ${mount}.." >&2 + sudo umount "${mount}" done # Copy the chroot preparation scripts, and enter the chroot -for file in $suite.sh common.sh net_test.sh; do - sudo cp -a $SCRIPT_DIR/rootfs/$file root/$file - sudo chown root:root root/$file +for file in "${suite}.sh" common.sh net_test.sh; do + sudo cp -a "${SCRIPT_DIR}/rootfs/${file}" "root/${file}" + sudo chown root:root "root/${file}" done -sudo chroot . /root/$suite.sh +sudo chroot . "/root/${suite}.sh" # Leave the workdir, to build the filesystem cd - # For the final image mount -mount=`mktemp -d` +mount=$(mktemp -d) mount_remove() { - rmdir $mount - tmpdir_remove + rmdir "${mount}" + tmpdir_remove } trap mount_remove EXIT # Create a 1G empty ext3 filesystem -truncate -s 1G $name -mke2fs -F -t ext3 -L ROOT $name +truncate -s 1G "${name}" +mke2fs -F -t ext3 -L ROOT "${name}" # Mount the new filesystem locally -sudo mount -o loop -t ext3 $name $mount +sudo mount -o loop -t ext3 "${name}" "${mount}" image_unmount() { - sudo umount $mount + sudo umount "${mount}" mount_remove } trap image_unmount EXIT # Copy the patched debootstrap results into the new filesystem -sudo cp -a $workdir/* $mount +sudo cp -a "${workdir}"/* "${mount}" # Fill the rest of the space with zeroes, to optimize compression -sudo dd if=/dev/zero of=$mount/sparse bs=1M 2>/dev/null || true -sudo rm -f $mount/sparse +sudo dd if=/dev/zero of="${mount}/sparse" bs=1M 2>/dev/null || true +sudo rm -f "${mount}/sparse" -echo "Debian $suite for $arch filesystem generated at '$name'." +echo "Debian ${suite} for ${arch} filesystem generated at '${name}'." |