Skip to content

Commit 4f55295

Browse files
Prefer [[ ]] to [ ].
See http://mywiki.wooledge.org/BashFAQ/031 - generally, [[ ]] is less error-prone.
1 parent 0613116 commit 4f55295

14 files changed

+59
-59
lines changed

kerndev-build

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ set -e; set -o pipefail; source kerndev-shared.sh
77
target_arch=${1:-"x86_64"}
88

99
# Sanity checks.
10-
[ ! -d $LINUX_DEV_PATH ] && fatal "can't find linux dev path at $LINUX_DEV_PATH"
11-
[ ! -f $LINUX_DEV_PATH/REPORTING-BUGS ] && \
10+
[[ ! -d $LINUX_DEV_PATH ]] && fatal "can't find linux dev path at $LINUX_DEV_PATH"
11+
[[ ! -f $LINUX_DEV_PATH/REPORTING-BUGS ]] && \
1212
fatal "Doesn't look like a linux dev path: $LINUX_DEV_PATH"
13-
[ $EUID = 0 ] && fatal "Don't run as root, causes file ownership pain"
13+
[[ $EUID = 0 ]] && fatal "Don't run as root, causes file ownership pain"
1414

1515
case $target_arch in
1616
arm)
@@ -27,7 +27,7 @@ aarch64)
2727
;;
2828
esac
2929

30-
if [ "$target_arch" != "x86_64" ]; then
30+
if [[ "$target_arch" != "x86_64" ]]; then
3131
# Make sure we have cross-compilers. `gcc` check should suffice.
3232
check_exists ${cross_compile_prefix}gcc
3333

@@ -51,7 +51,7 @@ echo Compiling kernel...
5151
# 1 extra thread to account for I/O waiting.
5252
mak -j$((cores + 1))
5353

54-
if [ -z "$DONT_INSTALL" ]; then
54+
if [[ -z "$DONT_INSTALL" ]]; then
5555
NO_DONE=y sudo -E kerndev-install $target_arch
5656
fi
5757

kerndev-check-all

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ check_opts="-f -q --show-types --no-summary"
99

1010
# Ensure the files exist, if not, die.
1111
for file in $args; do
12-
(! is_opt $file) && [ ! -f $file ] && \
12+
(! is_opt $file) && [[ ! -f $file ]] && \
1313
fatal "Can't find $file."
1414
done
1515

kerndev-config

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e; set -o pipefail; source kerndev-shared.sh
33

44
push_linux
55

6-
if [ -n "$REBUILD" ] || [ ! -f .config ]; then
6+
if [[ -n "$REBUILD" ]] || [[ ! -f .config ]]; then
77
mak mrproper
88
mak defconfig
99
fi
@@ -39,7 +39,7 @@ kenable ikconfig ikconfig_proc
3939
scripts/config --set-str uevent_helper_path ""
4040

4141
# Optionally enable flags for docker support.
42-
[ -n "$ENABLE_DOCKER_SUPPORT" ] && \
42+
[[ -n "$ENABLE_DOCKER_SUPPORT" ]] && \
4343
kenable netfilter_advanced dm_thin_provisioning bridge bridge_netfilter \
4444
devpts_multiple_instances cgroup_device memcg macvlan veth \
4545
nf_nat_ipv4 nf_nat netfilter_xt_match_{conntrack,addrtype} \
@@ -48,7 +48,7 @@ scripts/config --set-str uevent_helper_path ""
4848
cgroup_net_prio btrfs_fs
4949

5050
# Optionally, we are interested in code coverage.
51-
[ -n "$ENABLE_GCOV" ] && \
51+
[[ -n "$ENABLE_GCOV" ]] && \
5252
kenable debug_fs gcov_kernel gcov_format_autodetect gcov_profile_all
5353

5454
pop

kerndev-create

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ case $target_arch in
2121
esac
2222

2323
# Sanity checks.
24-
[ ! -f "/etc/arch-release" ] && \
24+
[[ ! -f "/etc/arch-release" ]] && \
2525
fatal This script is designed for arch linux only, sorry!
2626

2727
check_exists kerndev-create.chroot.sh kerndev-build kerndev-install pacstrap \
2828
truncate mkfs.ext4 arch-chroot
2929

30-
[ -n $USE_EXISTING_IMAGE ] && [ ! -f $KERNDEV_PATH/rootfs.img ] && \
30+
[[ -n $USE_EXISTING_IMAGE ]] && [[ ! -f $KERNDEV_PATH/rootfs.img ]] && \
3131
fatal "can't find existing rootfs image"
3232

3333
chroot_script_path=$(which kerndev-create.chroot.sh)
@@ -36,7 +36,7 @@ chroot_script_path=$(which kerndev-create.chroot.sh)
3636
elevate $@
3737

3838
# We want access to the underlying user.
39-
[ -z "$SUDO_USER" ] && fatal please run this using sudo!
39+
[[ -z "$SUDO_USER" ]] && fatal please run this using sudo!
4040

4141
# If this fails due to being unable to unmount /mnt, mount below will fail so we
4242
# can get away with ||true here.
@@ -46,7 +46,7 @@ mkdir -p $KERNDEV_PATH
4646

4747
push_kerndev
4848

49-
if [ -z "$USE_EXISTING_IMAGE" ]; then
49+
if [[ -z "$USE_EXISTING_IMAGE" ]]; then
5050
echo Creating and formatting rootfs image file...
5151
rm -f rootfs.img
5252
truncate -s $IMAGE_SIZE rootfs.img
@@ -58,7 +58,7 @@ fi
5858
mount_image rootfs.img
5959
trap "umount /mnt" EXIT
6060

61-
if [ -z "$USE_EXISTING_IMAGE" ]; then
61+
if [[ -z "$USE_EXISTING_IMAGE" ]]; then
6262
echo Downloading and installing rootfs into image...
6363
pacstrap /mnt base base-devel &>/dev/null
6464
fi
@@ -78,7 +78,7 @@ EOF
7878

7979
echo ...chroot-ed script complete!
8080

81-
if [ -z "$USE_EXISTING_IMAGE" ] && [ -n "$ENABLE_GCOV" ]; then
81+
if [[ -z "$USE_EXISTING_IMAGE" ]] && [[ -n "$ENABLE_GCOV" ]]; then
8282
echo Generating gcov script...
8383

8484
# Create 'cov' tool to check coverage for a specific file in the kernel tree.
@@ -87,7 +87,7 @@ if [ -z "$USE_EXISTING_IMAGE" ] && [ -n "$ENABLE_GCOV" ]; then
8787
cat >$cov_path <<-EOF
8888
#!/bin/bash
8989
90-
[ -z "\$1" ] && echo "usage: \$(basename \$0) [relative path to source file]" >&2 && exit 1
90+
[[ -z "\$1" ]] && echo "usage: \$(basename \$0) [relative path to source file]" >&2 && exit 1
9191
9292
# ref: https://goo.gl/rnd6yo
9393
args=\${@:1:-1}
@@ -106,7 +106,7 @@ if [ -z "$USE_EXISTING_IMAGE" ] && [ -n "$ENABLE_GCOV" ]; then
106106
pop
107107
fi
108108

109-
if [ -n "$ACCESS_CHROOT" ]; then
109+
if [[ -n "$ACCESS_CHROOT" ]]; then
110110
echo Entering chroot shell...
111111
arch-chroot /mnt
112112
echo ...chroot shell done!

kerndev-create-foreign

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e; set -o pipefail; source kerndev-shared.sh
33

44
# TODO: Duplicates kerndev-create, lots of copy-pasta, de-duplicate!!
55

6-
[ -z "$1" ] && fatal missing arch.
6+
[[ -z "$1" ]] && fatal missing arch.
77

88
target_arch=$1
99
shift
@@ -34,16 +34,16 @@ chroot_path="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
3434

3535
function cleanup()
3636
{
37-
[ -f $binfmt_path/$target_arch ] && echo -1 > $binfmt_path/$target_arch
37+
[[ -f $binfmt_path/$target_arch ]] && echo -1 > $binfmt_path/$target_arch
3838
rm -f /mnt/usr/bin/qemu-$target_arch-static
3939
unmount
4040
}
4141

4242
# Sanity checks.
4343
check_exists debootstrap qemu-system-$target_arch qemu-$target_arch-static
44-
[ ! -d $binfmt_path ] && fatal "binfmt not available."
44+
[[ ! -d $binfmt_path ]] && fatal "binfmt not available."
4545

46-
[ -n $USE_EXISTING_IMAGE ] && [ ! -f $KERNDEV_PATH/$rootfs ] && \
46+
[[ -n $USE_EXISTING_IMAGE ]] && [[ ! -f $KERNDEV_PATH/$rootfs ]] && \
4747
fatal "can't find existing rootfs image"
4848

4949
# So many commands need sudo, so just force the issue.
@@ -57,7 +57,7 @@ mkdir -p $KERNDEV_PATH
5757

5858
push_kerndev
5959

60-
if [ -z "$USE_EXISTING_IMAGE" ]; then
60+
if [[ -z "$USE_EXISTING_IMAGE" ]]; then
6161
echo Creating and formatting rootfs image file...
6262
rm -f $rootfs
6363
truncate -s $IMAGE_SIZE $rootfs
@@ -67,7 +67,7 @@ fi
6767
mount_image $rootfs
6868
trap cleanup EXIT
6969

70-
if [ -z "$USE_EXISTING_IMAGE" ]; then
70+
if [[ -z "$USE_EXISTING_IMAGE" ]]; then
7171
echo "Downloading and installing first stage rootfs into image..."
7272

7373
debootstrap --arch=$debootstrap_arch --variant=minbase --foreign \
@@ -79,7 +79,7 @@ echo Enabling binfmt for chroot...
7979
cp $(which qemu-${target_arch}-static) /mnt/usr/bin/
8080
echo "$binfmt_sig" > $binfmt_path/register
8181

82-
if [ -z "$USE_EXISTING_IMAGE" ]; then
82+
if [[ -z "$USE_EXISTING_IMAGE" ]]; then
8383
echo Entering chroot, downloading and installing second stage rootfs into image...
8484
chroot /mnt /debootstrap/debootstrap --second-stage >/dev/null
8585
fi
@@ -103,7 +103,7 @@ nameserver 8.8.8.8
103103
nameserver 8.8.4.4
104104
EOF
105105

106-
if [ -n "$ACCESS_CHROOT" ]; then
106+
if [[ -n "$ACCESS_CHROOT" ]]; then
107107
echo Entering chroot shell...
108108
arch-chroot /mnt env -i TERM=ansi PATH=$chroot_path /bin/bash
109109
echo ...chroot shell done!

kerndev-create-foreign.chroot.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ chroot_path="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
2323
# Taken from http://unix.stackexchange.com/a/14346. Non-root version didn't work.
2424
function inside_chroot()
2525
{
26-
[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]
26+
[[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]]
2727
}
2828

2929
function usage()
@@ -42,7 +42,7 @@ if ! inside_chroot; then
4242
echo not inside chroot! >&2
4343
exit 1
4444
fi
45-
if [ -z "$username" ]; then
45+
if [[ -z "$username" ]]; then
4646
usage
4747
exit 1
4848
fi
@@ -73,7 +73,7 @@ cat /etc/_hosts >> /etc/hosts
7373
rm /etc/_hosts
7474

7575
echo Setting up root password...
76-
if [ -z "$password" ]; then
76+
if [[ -z "$password" ]]; then
7777
# Don't let a typo ruin our day!
7878
while ! passwd; do
7979
echo Try again!

kerndev-create.chroot.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ password=$2 # Optional, if not provided script will prompt.
1515
# Taken from http://unix.stackexchange.com/a/14346. Non-root version didn't work.
1616
function inside_chroot()
1717
{
18-
[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]
18+
[[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]]
1919
}
2020

2121
function usage()
@@ -28,7 +28,7 @@ if ! inside_chroot; then
2828
echo not inside chroot! >&2
2929
exit 1
3030
fi
31-
if [ -z "$username" ]; then
31+
if [[ -z "$username" ]]; then
3232
usage
3333
exit 1
3434
fi
@@ -60,7 +60,7 @@ pacman -Sy --noconfirm btrfs-progs yaourt screen strace zsh lsof emacs-nox opens
6060
pacman -R --noconfirm linux &>/dev/null || true
6161

6262
echo Setting up root password...
63-
if [ -z "$password" ]; then
63+
if [[ -z "$password" ]]; then
6464
# Don't let a typo ruin our day!
6565
while ! passwd; do
6666
echo Try again!

kerndev-functions.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function push_kerndev()
4848
# If parameters are to be preserved, needs to be passed $@.
4949
function elevate()
5050
{
51-
if [ $EUID != 0 ]; then
51+
if [[ $EUID != 0 ]]; then
5252
exec sudo -E $0 $@
5353
exit $?
5454
fi
@@ -85,7 +85,7 @@ function unmount()
8585
# $1: Directory to 'give back' to user $SUDO_USER.
8686
function give_back()
8787
{
88-
[ -z "$SUDO_USER" ] && error "give_back: SUDO_USER not defined." || \
88+
[[ -z "$SUDO_USER" ]] && error "give_back: SUDO_USER not defined." || \
8989
chown -R $SUDO_USER:$SUDO_USER $1
9090
}
9191

@@ -94,7 +94,7 @@ function give_back()
9494
# $@: make arguments.
9595
function mak()
9696
{
97-
[ -z $VERBOSE ] && out="null" || out="tty"
97+
[[ -z $VERBOSE ]] && out="null" || out="tty"
9898

9999
make $make_opts $@ >/dev/$out
100100
}
@@ -103,13 +103,13 @@ function mak()
103103
# $1: Argument.
104104
function is_opt()
105105
{
106-
[[ $1 == -* ]]
106+
[[[[ $1 == -* ]]]]
107107
}
108108

109109
# Say we're done, if we're not configured to not do so.
110110
function say_done()
111111
{
112-
[ -z "$NO_DONE" ] && echo Done! || true
112+
[[ -z "$NO_DONE" ]] && echo Done! || true
113113
}
114114

115115

kerndev-install

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ x86_64)
1616
rootfs=rootfs.img
1717
kernel_image_path=$LINUX_DEV_PATH/arch/x86/boot/bzImage
1818

19-
[ ! -f $LINUX_DEV_PATH/REPORTING-BUGS ] && \
19+
[[ ! -f $LINUX_DEV_PATH/REPORTING-BUGS ]] && \
2020
fatal "doesn't look like a linux dev path: $LINUX_DEV_PATH"
21-
[ ! -f $kernel_image_path ] && \
21+
[[ ! -f $kernel_image_path ]] && \
2222
fatal "can't find kernel image at $kernel_image_path"
2323
;;
2424
*)
2525
fatal "unknown architecture: $target_arch"
2626
;;
2727
esac
2828

29-
if [ "$target_arch" != "x86_64" ]; then
29+
if [[ "$target_arch" != "x86_64" ]]; then
3030
rootfs=rootfs_${target_arch}.img
3131
make_opts="ARCH=${linux_arch} CROSS_COMPILE=$cross_compile_prefix"
3232
fi
3333

3434
# Sanity checks.
3535

3636
rootfs_image_path=$KERNDEV_PATH/$rootfs
37-
[ ! -f $rootfs_image_path ] && \
37+
[[ ! -f $rootfs_image_path ]] && \
3838
fatal "can't find root fs image at $rootfs_image_path"
3939

4040
elevate $@
@@ -49,7 +49,7 @@ echo Installing headers and modules...
4949
mak headers_install INSTALL_HDR_PATH=/mnt/usr/
5050
mak modules_install INSTALL_MOD_PATH=/mnt/
5151

52-
if [ -z "$USE_EXISTING_IMAGE" ] && [ -n "$ENABLE_GCOV" ]; then
52+
if [[ -z "$USE_EXISTING_IMAGE" ]] && [[ -n "$ENABLE_GCOV" ]]; then
5353
# We need to copy the linux source code to be able to gcov it.
5454
echo "Copying linux source to image (gcov)..."
5555

kerndev-module-headers

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ function get_full_path()
1616
echo "$( cd "$1" ; pwd -P )"
1717
}
1818

19-
([ -z "$1" ] || ([ -f "$1" ] && [ ! -d "$1" ])) && usage
19+
([[ -z "$1" ]] || ([[ -f "$1" ]] && [[ ! -d "$1" ]])) && usage
2020

2121
# Generate if doesn't exist.
2222
install -dm755 $1
2323

2424
target_dir=$(get_full_path $1)
2525
karch=${2:-x86}
26-
if [ "$#" -gt 2 ]; then
26+
if [[ "$#" -gt 2 ]]; then
2727
shift 2
2828
make_opts="$@"
2929
fi
@@ -37,9 +37,9 @@ drivers/media/dvb-frontends drivers/media/usb/dvb-usb drivers/media/tuners"
3737
push_linux
3838
trap pop EXIT
3939

40-
[ ! -f .config ] && fatal "Missing kernel configuration."
41-
[ ! -f Module.symvers ] && fatal "Missing Module.symvers, build kernel to generate."
42-
[ ! -d "$karch_dir" ] && fatal "Unrecognised karch: $karch"
40+
[[ ! -f .config ]] && fatal "Missing kernel configuration."
41+
[[ ! -f Module.symvers ]] && fatal "Missing Module.symvers, build kernel to generate."
42+
[[ ! -d "$karch_dir" ]] && fatal "Unrecognised karch: $karch"
4343

4444
echo Running modules_prepare...
4545
make $make_opts modules_prepare >/dev/null
@@ -57,7 +57,7 @@ find include -mindepth 1 -maxdepth 1 -type d | \
5757
xargs -I {} cp -a "{}" "$target_dir/include"
5858

5959
for d in include $extra_header_dirs; do
60-
[ -d "$d" ] && mkdir -p "$target_dir/$d"
60+
[[ -d "$d" ]] && mkdir -p "$target_dir/$d"
6161
done
6262

6363
mkdir -p "$target_karch_dir"
@@ -76,12 +76,12 @@ cp "$karch_dir/Makefile" "$target_karch_dir"
7676
# May as well always copy these if available.
7777
for f in Makefile_32.cpu kernel/asm-offsets.s; do
7878
p="$karch_dir/$f"
79-
[ -f $p ] && cp "$p" "$target_karch_dir/$f"
79+
[[ -f $p ]] && cp "$p" "$target_karch_dir/$f"
8080
done
8181

8282
# Copy in extra headers. Directories already created above.
8383
for d in $extra_header_dirs; do
84-
[ -d "$d" ] && cp $d/*.h "$target_dir/$d"
84+
[[ -d "$d" ]] && cp $d/*.h "$target_dir/$d"
8585
done
8686

8787
# Specific required files.

0 commit comments

Comments
 (0)