From 1d220e33a51028253281d71e46742e247cce6b24 Mon Sep 17 00:00:00 2001 From: Joakim Roubert Date: Wed, 21 Aug 2019 16:38:40 +0200 Subject: [PATCH 1/5] install.sh: Use built-in shell functionality instead of awk If install.sh relies on awk, install.sh malfunctions when run on a device with a limited environment where awk is not available. This patch replaces the use of awk with built-in shell script functionality. Change-Id: I071d9f565ff7ef38445a6dd0ea9692b903721601 Signed-off-by: Joakim Roubert --- install.sh | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/install.sh b/install.sh index afd9e16e60..af3d0d5dc6 100755 --- a/install.sh +++ b/install.sh @@ -298,13 +298,15 @@ download_hash() { HASH_URL=${GITHUB_URL}/download/${VERSION_K3S}/sha256sum-${ARCH}.txt info "Downloading hash ${HASH_URL}" curl -o ${TMP_HASH} -sfL ${HASH_URL} || fatal "Hash download failed" - HASH_EXPECTED=`grep " k3s${SUFFIX}$" ${TMP_HASH} | awk '{print $1}'` + HASH_EXPECTED=`grep " k3s${SUFFIX}$" ${TMP_HASH}` + HASH_EXPECTED=${HASH_EXPECTED%%[[:blank:]]*} } # --- check hash against installed version --- installed_hash_matches() { if [ -x ${BIN_DIR}/k3s ]; then - HASH_INSTALLED=`sha256sum ${BIN_DIR}/k3s | awk '{print $1}'` + HASH_INSTALLED=`sha256sum ${BIN_DIR}/k3s` + HASH_INSTALLED=${HASH_INSTALLED%%[[:blank:]]*} if [ "${HASH_EXPECTED}" = "${HASH_INSTALLED}" ]; then return fi @@ -322,7 +324,8 @@ download_binary() { # --- verify downloaded binary hash --- verify_binary() { info "Verifying binary download" - HASH_BIN=`sha256sum ${TMP_BIN} | awk '{print $1}'` + HASH_BIN=`sha256sum ${TMP_BIN}` + HASH_BIN=${HASH_BIN%%[[:blank:]]*} if [ "${HASH_EXPECTED}" != "${HASH_BIN}" ]; then fatal "Download sha256 does not match ${HASH_EXPECTED}, got ${HASH_BIN}" fi @@ -414,7 +417,12 @@ done pstree() { for pid in $@; do echo $pid - pstree $(ps -o ppid= -o pid= | awk "\$1==$pid {print \$2}") + # Find and show pstree for child processes of $pid + while read parent child; do + [ $parent -ne $pid ] || pstree $child + done <<-EOF + $(ps -o ppid= -o pid=) +EOF; done } @@ -425,7 +433,11 @@ killtree() { killtree $(lsof | sed -e 's/^[^0-9]*//g; s/ */\t/g' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1 | sort -n -u) do_unmount() { - MOUNTS=`cat /proc/self/mounts | awk '{print $2}' | grep "^$1" | sort -r` + MOUNTS= + while read ignore mount ignore; do + MOUNTS="$mount\n$MOUNTS" + done Date: Tue, 3 Sep 2019 07:51:33 +0200 Subject: [PATCH 2/5] Update install.sh according to yamt's suggestion --- install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 9588847d01..0213a0c4ac 100755 --- a/install.sh +++ b/install.sh @@ -422,11 +422,9 @@ pstree() { for pid in $@; do echo $pid # Find and show pstree for child processes of $pid - while read parent child; do + $(ps -o ppid= -o pid=) | while read parent child; do [ $parent -ne $pid ] || pstree $child - done <<-EOF - $(ps -o ppid= -o pid=) -EOF; + done done } From ce388e378892203dfdbca9abab47edc456d4e478 Mon Sep 17 00:00:00 2001 From: Joakim Roubert Date: Sat, 28 Sep 2019 14:29:49 +0200 Subject: [PATCH 3/5] Update install.sh Signed-off-by: Joakim Roubert --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index d9f928a532..8cb97fd75f 100755 --- a/install.sh +++ b/install.sh @@ -456,7 +456,7 @@ pstree() { for pid in $@; do echo $pid # Find and show pstree for child processes of $pid - $(ps -o ppid= -o pid=) | while read parent child; do + ps -o ppid= -o pid= | while read parent child; do [ $parent -ne $pid ] || pstree $child done done From 2548f3ebaa11670dfc3d9888bec6c299e296bd9a Mon Sep 17 00:00:00 2001 From: Joakim Roubert Date: Tue, 1 Oct 2019 08:49:01 +0200 Subject: [PATCH 4/5] Update install.sh Signed-off-by: Joakim Roubert --- install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 8cb97fd75f..cb479e30dd 100755 --- a/install.sh +++ b/install.sh @@ -483,12 +483,10 @@ do_unmount '/run/k3s' do_unmount '/var/lib/rancher/k3s' # Delete network interface(s) that match 'master cni0' -while read ignore iface ignore; do +ip link show | grep 'master cni0' | while read ignore iface ignore; do iface=${iface%%@*} [ -z "$iface" ] || ip link delete $iface -done <<-EOF - $(ip link show | grep 'master cni0') -EOF +done ip link delete cni0 ip link delete flannel.1 rm -rf /var/lib/cni/ From f0bce02a629051ab63762852757a95e1b854b928 Mon Sep 17 00:00:00 2001 From: Joakim Roubert Date: Fri, 4 Oct 2019 07:41:05 +0200 Subject: [PATCH 5/5] Update install.sh Signed-off-by: Joakim Roubert --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index cb479e30dd..90b15423b9 100755 --- a/install.sh +++ b/install.sh @@ -473,7 +473,7 @@ do_unmount() { while read ignore mount ignore; do MOUNTS="$mount\n$MOUNTS" done