Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional sudo use in scripts (and README consistency) #362

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `$HOME/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 `$HOME/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 @@ -60,4 +60,4 @@ tar -xf drake.tar.gz -C $HOME
echo -e "\ndrake VERSION.TXT: $(cat $HOME/drake/share/doc/drake/VERSION.TXT)\n"

# Install the source prereqs
$HOME/drake/share/drake/setup/install_prereqs
${maybe_sudo} ${HOME}/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
drake-master/setup/install_prereqs --with-bazel
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
drake-master/setup/install_prereqs --with-bazel
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
drake-master/setup/install_prereqs
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 $HOME/drake/ and
# install various system dependencies
sudo setup/install_prereqs
setup/install_prereqs

###############################################################
# Alternative Drake Versions
Expand Down
47 changes: 10 additions & 37 deletions drake_cmake_installed/setup/install_prereqs
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
#!/bin/bash

# Copyright (c) 2020, Massachusetts Institute of Technology.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# SPDX-License-Identifier: MIT-0

set -euxo pipefail

maybe_sudo=

case "$OSTYPE" in
darwin*)
# Mac specific installations
Expand All @@ -47,20 +22,19 @@ case "$OSTYPE" in

linux*)
# Ubuntu specific installations
if [[ "${EUID:-}" -ne 0 ]]; then
echo 'This script must be run as root' >&2
exit 2
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 @@ -72,8 +46,7 @@ EOF
trap 'rm -f drake.tar.gz' EXIT
tar -xf drake.tar.gz -C $HOME

apt-get update
apt-get install --no-install-recommends $(cat <<EOF
${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
python3-all-dev
EOF
)
Expand All @@ -84,4 +57,4 @@ esac
echo -e "\ndrake VERSION.TXT: $(cat $HOME/drake/share/doc/drake/VERSION.TXT)\n"

# Install the source prereqs
$HOME/drake/share/drake/setup/install_prereqs
${maybe_sudo} ${HOME}/drake/share/drake/setup/install_prereqs
6 changes: 1 addition & 5 deletions private/test/file_sync_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
"drake_bazel_external/.github/ubuntu_setup",
"drake_cmake_external/.github/ubuntu_setup",
),
(
"drake_bazel_external/setup/install_prereqs",
"drake_cmake_external/setup/install_prereqs",
),
(
"drake_bazel_download/.bazelversion",
"drake_bazel_external/.bazelversion",
Expand Down Expand Up @@ -149,7 +145,7 @@ def check(index: int, paths: tuple[str]):


def gha_workflow_check(workflow_name: str):
"""Enforces the subdir_ci to have the contents of root_ci up until
"""Enforces the subdir_ci to have the contents of root_ci up until
it reaches the jobs: line plus the content in the subdir_ workflow
after jobs: is mentioned.
"""
Expand Down
Loading