Skip to content

Commit 815264e

Browse files
authored
[bootstrap] pipe wget into tar instead of using temporary files (openthread#12833)
Using `/tmp` to store large download files will fail when the system is under memory pressure. `/tmp` is backed by `tmpfs` in many Linux distributions.
1 parent 8ad0566 commit 815264e

2 files changed

Lines changed: 11 additions & 24 deletions

File tree

script/bootstrap

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ install_packages_apt()
7474
sudo apt-get --no-install-recommends install -y binutils-arm-none-eabi gcc-arm-none-eabi gdb-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
7575
elif [ "$PLATFORM" = "Ubuntu" ]; then
7676
sudo apt-get --no-install-recommends install -y bzip2 ca-certificates wget
77-
(cd /tmp \
78-
&& wget --tries 4 --no-check-certificate --quiet -c https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 \
79-
&& sudo tar xjf gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 -C /opt \
80-
&& rm gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 \
81-
&& sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.)
77+
(wget --tries 4 --no-check-certificate -O - --quiet https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 \
78+
| sudo tar xj -C /opt) \
79+
&& sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.
8280
fi
8381

8482
if [ "$PLATFORM" != "Raspbian" ] && [ "${INSTALL_FORMAT_TOOLS}" = "1" ]; then

script/install-llvm.sh

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#
2929
# This script downloads and installs a specific version of clang-format and clang-tidy.
3030

31-
set -e
31+
set -e -o pipefail
3232

3333
LLVM_VERSION="19.1.7"
3434
ARCH=$(uname -m)
@@ -42,26 +42,15 @@ fi
4242
LLVM_PACKAGE="LLVM-${LLVM_VERSION}-Linux-X64"
4343
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/${LLVM_PACKAGE}.tar.xz"
4444
INSTALL_DIR="/opt/llvm-${LLVM_VERSION}"
45-
TEMP_DIR=$(mktemp -d)
45+
INSTALL_DIR_tmp="$INSTALL_DIR.tmp"
4646

47-
cleanup()
48-
{
49-
rm -rf "${TEMP_DIR}"
50-
}
47+
sudo mkdir -p "${INSTALL_DIR_tmp}"
48+
trap 'sudo rm -rf "${INSTALL_DIR_tmp}"' EXIT
5149

52-
trap cleanup EXIT
53-
54-
cd "${TEMP_DIR}"
55-
56-
echo "Downloading LLVM from ${LLVM_URL}..."
57-
wget -O llvm.tar.xz "${LLVM_URL}"
58-
59-
echo "Uncompressing to ${TEMP_DIR}..."
60-
tar xf llvm.tar.xz
61-
62-
echo "Installing to ${INSTALL_DIR}..."
63-
sudo mkdir -p /opt
64-
sudo mv "${LLVM_PACKAGE}" "${INSTALL_DIR}"
50+
echo "Downloading LLVM from '${LLVM_URL}' into '${INSTALL_DIR}' ..."
51+
wget -O - "${LLVM_URL}" | sudo tar -f - -C "${INSTALL_DIR_tmp}" --strip-components=1 -xJ
52+
sudo rm -rf "${INSTALL_DIR}"
53+
sudo mv "${INSTALL_DIR_tmp}" "${INSTALL_DIR}"
6554

6655
echo "Creating symlinks in /usr/local/bin..."
6756
sudo ln -sf "${INSTALL_DIR}/bin/clang-format" "/usr/local/bin/clang-format-19"

0 commit comments

Comments
 (0)