Skip to content

Commit

Permalink
add maybe_sudo logic to scripts, update READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-yankee committed Jan 23, 2025
1 parent 775a247 commit 9123909
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 65 deletions.
9 changes: 5 additions & 4 deletions drake_bazel_download/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ For an introduction to Bazel, refer to

## Instructions

First, run the `install_prereqs` script to download the Drake source to `/opt/drake/`.
This also runs Drake's setup script to install the required Ubuntu packages:
First, run the `install_prereqs` script to download the
Drake source to `/opt/drake/`. This also runs Drake's
setup script to install the required Ubuntu packages:

```bash
sudo setup/install_prereqs
setup/install_prereqs
```

Additionally, if you don't already have bazel or bazelisk installed, then install bazelisk:

```bash
sudo setup/install_bazelisk
setup/install_bazelisk
```

Then, to build and test all apps:
Expand Down
8 changes: 4 additions & 4 deletions drake_bazel_download/setup/install_bazelisk
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

set -euxo pipefail

if [[ "${EUID:-}" -ne 0 ]]; then
echo 'This script must be run as root' >&2
exit 2
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

wget -O bazelisk.deb \
https://github.com/bazelbuild/bazelisk/releases/download/v1.24.0/bazelisk-amd64.deb
dpkg -i bazelisk.deb
${maybe_sudo} dpkg -i bazelisk.deb
rm -f bazelisk.deb
14 changes: 7 additions & 7 deletions drake_bazel_download/setup/install_prereqs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@

set -euxo pipefail

if [[ "${EUID:-}" -ne 0 ]]; then
echo 'This script must be run as root' >&2
exit 2
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

apt-get update
apt-get install --no-install-recommends lsb-release
${maybe_sudo} apt-get update
${maybe_sudo} apt-get install --no-install-recommends lsb-release

if [[ "$(lsb_release -sc)" != 'jammy' ]]; then
echo 'This script requires Ubuntu 22.04 (Jammy)' >&2
exit 3
fi

apt-get install --no-install-recommends $(cat <<EOF
${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
ca-certificates
wget
EOF
Expand All @@ -58,4 +58,4 @@ tar -xf drake.tar.gz -C /opt
# Show version for debugging; use echo for newline / readability.
echo -e "\ndrake VERSION.TXT: $(cat /opt/drake/share/doc/drake/VERSION.TXT)\n"

/opt/drake/share/drake/setup/install_prereqs
${maybe_sudo} /opt/drake/share/drake/setup/install_prereqs
7 changes: 6 additions & 1 deletion drake_bazel_external/.github/setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

set -euxo pipefail

maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

# CI setup
sudo .github/ubuntu_setup
${maybe_sudo} .github/ubuntu_setup

# drake source setup
setup/install_prereqs
10 changes: 5 additions & 5 deletions drake_bazel_external/.github/ubuntu_setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

set -euxo pipefail

if [[ "${EUID:-}" -ne 0 ]]; then
echo 'This script must be run as root' >&2
exit 2
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes

export DEBIAN_FRONTEND='noninteractive'

apt-get update
apt-get install --no-install-recommends lsb-release
${maybe_sudo} apt-get update
${maybe_sudo} apt-get install --no-install-recommends lsb-release

if [[ "$(lsb_release -sc)" != 'jammy' ]]; then
echo 'This script requires Ubuntu 22.04 (Jammy)' >&2
Expand Down
6 changes: 3 additions & 3 deletions drake_bazel_external/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ For an introduction to Bazel, refer to

## Instructions

First, run the `install_prereqs` script to download the Drake source to `drake-master/`
(from the current directory). This also runs Drake's setup script to
install the required Ubuntu packages:
First, run the `install_prereqs` script to download
the Drake source to `drake-master/` (from the current directory).
This also runs Drake's setup script to install the required Ubuntu packages:

```bash
setup/install_prereqs
Expand Down
9 changes: 7 additions & 2 deletions drake_bazel_external/setup/install_prereqs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

set -euxo pipefail

sudo apt-get install --no-install-recommends $(cat <<EOF
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
wget
EOF
)
Expand All @@ -18,4 +23,4 @@ trap 'rm -f drake.tar.gz' EXIT
tar -xf drake.tar.gz

# Install the source prereqs
sudo drake-master/setup/ubuntu/install_prereqs.sh
${maybe_sudo} drake-master/setup/ubuntu/install_prereqs.sh
7 changes: 6 additions & 1 deletion drake_bazel_external_legacy/.github/setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

set -euxo pipefail

maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

# CI setup
sudo .github/ubuntu_setup
${maybe_sudo} .github/ubuntu_setup

# drake source setup
setup/install_prereqs
10 changes: 5 additions & 5 deletions drake_bazel_external_legacy/.github/ubuntu_setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

set -euxo pipefail

if [[ "${EUID:-}" -ne 0 ]]; then
echo 'This script must be run as root' >&2
exit 2
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes

export DEBIAN_FRONTEND='noninteractive'

apt-get update
apt-get install --no-install-recommends lsb-release
${maybe_sudo} apt-get update
${maybe_sudo} apt-get install --no-install-recommends lsb-release

if [[ "$(lsb_release -sc)" != 'jammy' ]]; then
echo 'This script requires Ubuntu 22.04 (Jammy)' >&2
Expand Down
6 changes: 3 additions & 3 deletions drake_bazel_external_legacy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ For an introduction to Bazel, refer to

## Instructions

First, run the `install_prereqs` script to download the Drake source to `drake-master/`
(from the current directory). This also runs Drake's setup script to
install the required Ubuntu packages:
First, run the `install_prereqs` script to download the
Drake source to `drake-master/` (from the current directory).
This also runs Drake's setup script to install the required Ubuntu packages:

```bash
setup/install_prereqs
Expand Down
9 changes: 7 additions & 2 deletions drake_bazel_external_legacy/setup/install_prereqs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

set -euxo pipefail

sudo apt-get install --no-install-recommends $(cat <<EOF
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
wget
EOF
)
Expand All @@ -18,4 +23,4 @@ trap 'rm -f drake.tar.gz' EXIT
tar -xf drake.tar.gz

# Install the source prereqs
sudo drake-master/setup/ubuntu/install_prereqs.sh
${maybe_sudo} drake-master/setup/ubuntu/install_prereqs.sh
11 changes: 8 additions & 3 deletions drake_cmake_external/.github/setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@

set -euxo pipefail

maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

# CI setup
sudo .github/ubuntu_setup
${maybe_sudo} .github/ubuntu_setup

# drake source setup
setup/install_prereqs

# Provide regression coverage for the WITH_USER_...=ON options by un-installing
# packages that should not be necessary in this particular build flavor. This
# example configures them to be built from source.
sudo apt-get remove libeigen3-dev libfmt-dev libspdlog-dev
sudo apt-get autoremove
${maybe_sudo} apt-get remove libeigen3-dev libfmt-dev libspdlog-dev
${maybe_sudo} apt-get autoremove
10 changes: 5 additions & 5 deletions drake_cmake_external/.github/ubuntu_setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

set -euxo pipefail

if [[ "${EUID:-}" -ne 0 ]]; then
echo 'This script must be run as root' >&2
exit 2
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes

export DEBIAN_FRONTEND='noninteractive'

apt-get update
apt-get install --no-install-recommends lsb-release
${maybe_sudo} apt-get update
${maybe_sudo} apt-get install --no-install-recommends lsb-release

if [[ "$(lsb_release -sc)" != 'jammy' ]]; then
echo 'This script requires Ubuntu 22.04 (Jammy)' >&2
Expand Down
6 changes: 3 additions & 3 deletions drake_cmake_external/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This pulls in Drake using the CMake `ExternalProject_Add(drake)` mechanism.

## Instructions

First, run the `install_prereqs` script to download the Drake source to `drake-master/`
(from the current directory). This also runs Drake's setup script to
install the required Ubuntu packages:
First, run the `install_prereqs` script to download the
Drake source to `drake-master/` (from the current directory).
This also runs Drake's setup script to install the required Ubuntu packages:

```bash
setup/install_prereqs
Expand Down
9 changes: 7 additions & 2 deletions drake_cmake_external/setup/install_prereqs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

set -euxo pipefail

sudo apt-get install --no-install-recommends $(cat <<EOF
maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
wget
EOF
)
Expand All @@ -18,4 +23,4 @@ trap 'rm -f drake.tar.gz' EXIT
tar -xf drake.tar.gz

# Install the source prereqs
sudo drake-master/setup/ubuntu/install_prereqs.sh
${maybe_sudo} drake-master/setup/ubuntu/install_prereqs.sh
2 changes: 1 addition & 1 deletion drake_cmake_installed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ These instructions are only supported for Ubuntu 22.04 (Jammy).

# Download Drake source to /opt/drake/ and install
# various system dependencies
sudo setup/install_prereqs
setup/install_prereqs

###############################################################
# Install Drake to $HOME/drake
Expand Down
25 changes: 15 additions & 10 deletions drake_cmake_installed/setup/install_prereqs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

set -euxo pipefail

maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

case "$OSTYPE" in
darwin*)
# Mac specific installations
Expand All @@ -40,10 +45,10 @@ case "$OSTYPE" in
fi

if [[ ! -d /opt/drake ]]; then
sudo mkdir -p /opt/drake
sudo chmod g+rwx /opt/drake
sudo chown "${USER}" /opt/drake
sudo chgrp admin /opt/drake
${maybe_sudo} mkdir -p /opt/drake
${maybe_sudo} chmod g+rwx /opt/drake
${maybe_sudo} chown "${USER}" /opt/drake
${maybe_sudo} chgrp admin /opt/drake
fi

# Install Drake dependencies.
Expand All @@ -59,15 +64,15 @@ case "$OSTYPE" in
exit 2
fi

apt-get update
apt-get install --no-install-recommends lsb-release
${maybe_sudo} apt-get update
${maybe_sudo} apt-get install --no-install-recommends lsb-release

if [[ "$(lsb_release -sc)" != 'jammy' ]]; then
echo 'This script requires Ubuntu 22.04 (Jammy)' >&2
exit 3
fi

apt-get install --no-install-recommends $(cat <<EOF
${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
ca-certificates
wget
EOF
Expand All @@ -78,8 +83,8 @@ EOF
trap 'rm -f drake.tar.gz' EXIT
tar -xf drake.tar.gz -C /opt

apt-get update
apt-get install --no-install-recommends $(cat <<EOF
${maybe_sudo} apt-get update
${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
python3-all-dev
EOF
)
Expand All @@ -89,4 +94,4 @@ esac
# Show version for debugging; use echo for newline / readability.
echo -e "\ndrake VERSION.TXT: $(cat /opt/drake/share/doc/drake/VERSION.TXT)\n"

/opt/drake/share/drake/setup/install_prereqs
${maybe_sudo} /opt/drake/share/drake/setup/install_prereqs
13 changes: 9 additions & 4 deletions drake_cmake_installed_apt/.github/ubuntu_apt_setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

set -euxo pipefail

maybe_sudo=
if [[ "${EUID}" -ne 0 ]]; then
maybe_sudo=sudo
fi

export DEBIAN_FRONTEND=noninteractive

apt-get -qq update || (sleep 30; apt-get -qq update)
apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \
${maybe_sudo} apt-get -qq update || (sleep 30; apt-get -qq update)
${maybe_sudo} apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \
install build-essential ca-certificates cmake gnupg lsb-release wget

readonly codename="$(lsb_release -cs)"
Expand All @@ -16,6 +21,6 @@ wget -qO- --retry-connrefused https://drake-apt.csail.mit.edu/drake.asc \
echo "deb [arch=amd64] https://drake-apt.csail.mit.edu/${codename} ${codename} main" \
> /etc/apt/sources.list.d/drake.list

apt-get -qq update || (sleep 30; apt-get -qq update)
apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \
${maybe_sudo} apt-get -qq update || (sleep 30; apt-get -qq update)
${maybe_sudo} apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \
install drake-dev

0 comments on commit 9123909

Please sign in to comment.