Skip to content

Commit

Permalink
add maybe_sudo logic to non-CI scripts, update READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-yankee committed Jan 27, 2025
1 parent 775a247 commit c675165
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 39 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
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
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
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
16 changes: 8 additions & 8 deletions drake_cmake_installed/setup/install_prereqs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ case "$OSTYPE" in

linux*)
# Ubuntu specific installations
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 @@ -78,8 +78,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 Down

0 comments on commit c675165

Please sign in to comment.