Skip to content

Commit

Permalink
Fixing shell scripts to pass shellcheck test
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivas Muthu committed Dec 9, 2024
1 parent c738f1a commit 3ea21cb
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions modules/common/containerd-rootless-child.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -e
export PATH="@path@"


if ! [ -w $HOME ]; then
if ! [ -w "$HOME" ]; then
echo "HOME needs to be set and writable"
exit 1
fi
Expand Down Expand Up @@ -43,7 +43,7 @@ for i in "${!mountSources[@]}"; do
# The actual files in the parent namespace are *not removed* by this rm command.
rm -rf "$mountPoint"

echo >&2 Bind mounting ${mountSource} to ${mountPoint} inside mount namespace
echo >&2 Bind mounting "${mountSource}" to "${mountPoint}" inside mount namespace
mkdir -p "$mountSource" "$mountPoint"
mount --bind "$mountSource" "$mountPoint"
done
Expand Down
2 changes: 1 addition & 1 deletion modules/common/containerd-rootless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -e
export PATH="@path@"


if ! [ -w $XDG_RUNTIME_DIR ]; then
if ! [ -w "$XDG_RUNTIME_DIR" ]; then
echo "XDG_RUNTIME_DIR needs to be set and writable"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion script/kind/usr/local/bin/kind-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
> /sys/fs/cgroup/cgroup.subtree_control
fi

exec $@
exec "$@"
6 changes: 5 additions & 1 deletion script/rootless/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export REPO_DIR=$(git rev-parse --show-toplevel)
#!/bin/bash
set -euo pipefail

REPO_DIR="$(git rev-parse --show-toplevel)"
export REPO_DIR

export BIN_DIR="${REPO_DIR}/build/bin"
export CONTAINERD_ADDRESS="${REPO_DIR}/build/containerd/containerd.sock"
Expand Down
3 changes: 2 additions & 1 deletion script/rootless/containerd.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

rootlesskit \
Expand All @@ -9,5 +10,5 @@ rootlesskit \
--copy-up=/run \
--copy-up=/var/lib \
--port-driver=slirp4netns \
--state-dir=$REPO_DIR/build/rootlesskit-containerd \
--state-dir="$REPO_DIR/build/rootlesskit-containerd" \
sh -c "containerd --config ${CONTAINERD_CONFIG_FILE}"
5 changes: 3 additions & 2 deletions script/rootless/create-containerd-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

mkdir -p $(dirname $CONTAINERD_CONFIG_FILE)
cat <<EOM > $CONTAINERD_CONFIG_FILE
mkdir -p "$(dirname "$CONTAINERD_CONFIG_FILE")"
cat <<EOM > "$CONTAINERD_CONFIG_FILE"
version = 2
root = "$REPO_DIR/build/containerd/root"
state = "$REPO_DIR/build/containerd/state"
Expand Down
5 changes: 3 additions & 2 deletions script/rootless/create-nerdctl-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

mkdir -p $(dirname $NERDCTL_TOML)
cat <<EOM > $NERDCTL_TOML
mkdir -p "$(dirname "$NERDCTL_TOML")"
cat <<EOM > "$NERDCTL_TOML"
address = "${REPO_DIR}/build/containerd/containerd.sock"
snapshotter = "nix"
data_root = "${REPO_DIR}/build/nerdctl/root/"
Expand Down
5 changes: 3 additions & 2 deletions script/rootless/create-nix-snapshotter-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

mkdir -p $(dirname $NIX_SNAPSHOTTER_CONFIG_FILE)
cat <<EOM > $NIX_SNAPSHOTTER_CONFIG_FILE
mkdir -p "$(dirname "$NIX_SNAPSHOTTER_CONFIG_FILE")"
cat <<EOM > "$NIX_SNAPSHOTTER_CONFIG_FILE"
address = "${REPO_DIR}/build/nix-snapshotter/nix-snapshotter.sock"
root = "${REPO_DIR}/build/containerd/root/io.containerd.snapshotter.v1.nix"
Expand Down
5 changes: 3 additions & 2 deletions script/rootless/load-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

image=$1

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

outPath=$(nix build --print-out-paths .#image-${image})
${BIN_DIR}/nix2container --address $CONTAINERD_ADDRESS load ${outPath}
outPath=$(nix build --print-out-paths .#image-"${image}")
"${BIN_DIR}"/nix2container --address "$CONTAINERD_ADDRESS" load "${outPath}"
1 change: 1 addition & 0 deletions script/rootless/nerdctl.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

nerdctl "$@"
1 change: 1 addition & 0 deletions script/rootless/nix-snapshotter.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

./build/bin/nix-snapshotter \
Expand Down
3 changes: 2 additions & 1 deletion script/rootless/nsenter.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

pid=$(cat "$REPO_DIR/build/rootlesskit-containerd/child_pid")
nsenter -U --preserve-credentials -m -n -t "$pid" $@
nsenter -U --preserve-credentials -m -n -t "$pid" "$@"

0 comments on commit 3ea21cb

Please sign in to comment.