Skip to content

Commit

Permalink
Merge pull request #3214 from apostasie/dev-shell
Browse files Browse the repository at this point in the history
Shellscript sanity / cleanup PR
  • Loading branch information
AkihiroSuda authored Jul 17, 2024
2 parents 370cab6 + bbf2293 commit 0dfa3bb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ done

TMPIDFILE=$(mktemp)
BOOTSTRAP_KEY=$(ipfs-key 2>"${TMPIDFILE}" | base64 -w 0)
ID=$(cat "${TMPIDFILE}" | grep "ID " | sed -E 's/[^:]*: (.*)/\1/')
ID=$(grep "ID " "${TMPIDFILE}" | sed -E 's/[^:]*: (.*)/\1/')
rm "${TMPIDFILE}"

BOOTSTRAP_PEER_PRIV_KEY=$(echo "${BOOTSTRAP_KEY}" | base64 -w 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

set -eu -o pipefail

for d in ipfs-swarm-key-gen ; do
if ! command -v $d >/dev/null 2>&1 ; then
echo "$d not found"
exit 1
fi
done
if ! command -v ipfs-swarm-key-gen >/dev/null 2>&1 ; then
echo "ipfs-swarm-key-gen not found"
exit 1
fi

SWARM_KEY=$(ipfs-swarm-key-gen | base64 | tr -d '\n')

Expand Down
10 changes: 4 additions & 6 deletions examples/nerdctl-ipfs-registry-kubernetes/ipfs/bootstrap.yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

set -eu -o pipefail

for d in ipfs-swarm-key-gen ; do
if ! command -v $d >/dev/null 2>&1 ; then
echo "$d not found"
exit 1
fi
done
if ! command -v ipfs-swarm-key-gen >/dev/null 2>&1 ; then
echo "ipfs-swarm-key-gen not found"
exit 1
fi

SWARM_KEY=$(ipfs-swarm-key-gen | base64 | tr -d '\n')

Expand Down
14 changes: 5 additions & 9 deletions extras/rootless/containerd-rootless-setuptool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ set -eu

# utility functions
INFO() {
# https://github.com/koalaman/shellcheck/issues/1593
# shellcheck disable=SC2039
/bin/echo -e "\e[104m\e[97m[INFO]\e[49m\e[39m ${*}"
printf "\e[104m\e[97m[INFO]\e[49m\e[39m %s\n" "$*"
}

WARNING() {
# shellcheck disable=SC2039
/bin/echo >&2 -e "\e[101m\e[97m[WARNING]\e[49m\e[39m ${*}"
>&2 printf "\e[101m\e[97m[WARNING]\e[49m\e[39m %s\n" "$*"
}

ERROR() {
# shellcheck disable=SC2039
/bin/echo >&2 -e "\e[101m\e[97m[ERROR]\e[49m\e[39m ${*}"
>&2 printf "\e[101m\e[97m[ERROR]\e[49m\e[39m %s\n" "$*"
}

# constants
Expand Down Expand Up @@ -143,8 +139,8 @@ propagate_env_from() {
pid="$1"
env="$(sed -e "s/\x0/'\n/g" <"/proc/${pid}/environ" | sed -Ee "s/^[^=]*=/export \0'/g")"
shift
for key in $@; do
eval $(echo "$env" | grep "^export ${key=}")
for key in "$@"; do
eval "$(echo "$env" | grep "^export ${key=}")"
done
}

Expand Down
35 changes: 18 additions & 17 deletions extras/rootless/containerd-rootless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ fi
: "${XDG_DATA_HOME:=$HOME/.local/share}"
: "${XDG_CONFIG_HOME:=$HOME/.config}"

if [ -z $_CONTAINERD_ROOTLESS_CHILD ]; then
if [ -z "$_CONTAINERD_ROOTLESS_CHILD" ]; then
if [ "$(id -u)" = "0" ]; then
echo "Must not run as root"
exit 1
fi
case "$1" in
"check" | "install" | "uninstall")
echo "Did you mean 'containerd-rootless-setuptool.sh $@' ?"
echo "Did you mean 'containerd-rootless-setuptool.sh $*' ?"
exit 1
;;
esac
Expand All @@ -81,19 +81,19 @@ if [ -z $_CONTAINERD_ROOTLESS_CHILD ]; then
: "${CONTAINERD_ROOTLESS_ROOTLESSKIT_DETACH_NETNS:=auto}"
net=$CONTAINERD_ROOTLESS_ROOTLESSKIT_NET
mtu=$CONTAINERD_ROOTLESS_ROOTLESSKIT_MTU
if [ -z $net ]; then
if [ -z "$net" ]; then
if command -v slirp4netns >/dev/null 2>&1; then
# If --netns-type is present in --help, slirp4netns is >= v0.4.0.
if slirp4netns --help | grep -qw -- --netns-type; then
net=slirp4netns
if [ -z $mtu ]; then
if [ -z "$mtu" ]; then
mtu=65520
fi
else
echo "slirp4netns found but seems older than v0.4.0. Falling back to VPNKit."
fi
fi
if [ -z $net ]; then
if [ -z "$net" ]; then
if command -v vpnkit >/dev/null 2>&1; then
net=vpnkit
else
Expand All @@ -102,7 +102,7 @@ if [ -z $_CONTAINERD_ROOTLESS_CHILD ]; then
fi
fi
fi
if [ -z $mtu ]; then
if [ -z "$mtu" ]; then
mtu=1500
fi

Expand All @@ -120,12 +120,12 @@ if [ -z $_CONTAINERD_ROOTLESS_CHILD ]; then

case "$CONTAINERD_ROOTLESS_ROOTLESSKIT_DETACH_NETNS" in
auto)
if rootlesskit --help | grep -qw -- "--detach-netns"; then
CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS=--detach-netns $CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS
if rootlesskit --help | grep -qw -- "--detach-netns"; then
CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS="--detach-netns $CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS"
fi
;;
1 | true)
CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS=--detach-netns $CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS
CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS="--detach-netns $CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS"
;;
0 | false)
# NOP
Expand All @@ -144,18 +144,19 @@ if [ -z $_CONTAINERD_ROOTLESS_CHILD ]; then
# (by either systemd-networkd or NetworkManager)
# * /run: copy-up is required so that we can create /run/containerd (hardcoded) in our namespace
# * /var/lib: copy-up is required so that we can create /var/lib/containerd in our namespace
# shellcheck disable=SC2086
exec rootlesskit \
--state-dir=$CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR \
--net=$net --mtu=$mtu \
--slirp4netns-sandbox=$CONTAINERD_ROOTLESS_ROOTLESSKIT_SLIRP4NETNS_SANDBOX \
--slirp4netns-seccomp=$CONTAINERD_ROOTLESS_ROOTLESSKIT_SLIRP4NETNS_SECCOMP \
--disable-host-loopback --port-driver=$CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER \
--state-dir="$CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR" \
--net="$net" --mtu="$mtu" \
--slirp4netns-sandbox="$CONTAINERD_ROOTLESS_ROOTLESSKIT_SLIRP4NETNS_SANDBOX" \
--slirp4netns-seccomp="$CONTAINERD_ROOTLESS_ROOTLESSKIT_SLIRP4NETNS_SECCOMP" \
--disable-host-loopback --port-driver="$CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER" \
--copy-up=/etc --copy-up=/run --copy-up=/var/lib \
--propagation=rslave \
$CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS \
$0 $@
"$0" "$@"
else
[ $_CONTAINERD_ROOTLESS_CHILD = 1 ]
[ "$_CONTAINERD_ROOTLESS_CHILD" = 1 ]
# Remove the *symlinks* for the existing files in the parent namespace if any,
# so that we can create our own files in our mount namespace.
# The actual files in the parent namespace are *not removed* by this rm command.
Expand Down Expand Up @@ -193,5 +194,5 @@ else
chcon system_u:object_r:iptables_var_run_t:s0 /run
fi

exec containerd $@
exec containerd "$@"
fi
10 changes: 5 additions & 5 deletions hack/generate-release-note.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
minimal_amd64tgz="$(find _output -name '*linux-amd64.tar.gz*' -and ! -name '*full*')"
full_amd64tgz="$(find _output -name '*linux-amd64.tar.gz*' -and -name '*full*')"

minimal_amd64tgz_basename="$(basename ${minimal_amd64tgz})"
full_amd64tgz_basename="$(basename ${full_amd64tgz})"
minimal_amd64tgz_basename="$(basename "${minimal_amd64tgz}")"
full_amd64tgz_basename="$(basename "${full_amd64tgz}")"

cat <<-EOX
## Changes
Expand All @@ -37,7 +37,7 @@ Extract the archive to a path like \`/usr/local/bin\` or \`~/bin\` .
<p>
\`\`\`
$(tar tzvf ${minimal_amd64tgz})
$(tar tzvf "${minimal_amd64tgz}")
\`\`\`
</p>
</details>
Expand All @@ -49,7 +49,7 @@ Extract the archive to a path like \`/usr/local\` or \`~/.local\` .
<p>
\`\`\`
$(tar tzvf ${full_amd64tgz})
$(tar tzvf "${full_amd64tgz}")
\`\`\`
</p>
</details>
Expand All @@ -59,7 +59,7 @@ $(tar tzvf ${full_amd64tgz})
See \`share/doc/nerdctl-full/README.md\`:
\`\`\`markdown
$(tar xOzf ${full_amd64tgz} share/doc/nerdctl-full/README.md)
$(tar xOzf "${full_amd64tgz}" share/doc/nerdctl-full/README.md)
\`\`\`
</p>
</details>
Expand Down

0 comments on commit 0dfa3bb

Please sign in to comment.