Skip to content

Commit

Permalink
setup scripts: do not use sudo if already running under root
Browse files Browse the repository at this point in the history
Reworked variant of #4753.

Copied from 99236ea commit in `master` branch.
  • Loading branch information
agnostic-apollo committed Dec 22, 2024
1 parent a779e25 commit bcc922f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
15 changes: 11 additions & 4 deletions scripts/setup-archlinux.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e -u

PACKAGES=""
Expand Down Expand Up @@ -43,9 +43,16 @@ PACKAGES+=" lua" # Needed to build luarocks package.
PACKAGES+=" python-recommonmark" # Needed for LLVM-8 documentation.
PACKAGES+=" jre8-openjdk-headless"

sudo pacman -Syq --noconfirm $PACKAGES
# Do not require sudo if already running as root.
if [ "$(id -u)" = "0" ]; then
SUDO=""
else
SUDO="sudo"
fi

sudo mkdir -p /data/data/com.termux/files/usr
sudo chown -R $(whoami) /data
$SUDO pacman -Syq --noconfirm $PACKAGES

$SUDO mkdir -p /data/data/com.termux/files/usr
$SUDO chown -R $(whoami) /data

echo "Please also install ncurses5-compat-libs and makedepend packages from the AUR before continuing"
21 changes: 14 additions & 7 deletions scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e -u

PACKAGES=""
Expand Down Expand Up @@ -57,11 +57,18 @@ PACKAGES+=" zip" # For smalltalk.
PACKAGES+=" libssl-dev:i386" # Needed by swi-prolog 32-bit
PACKAGES+=" zlib1g-dev:i386"

# Do not require sudo if already running as root.
if [ "$(id -u)" = "0" ]; then
SUDO=""
else
SUDO="sudo"
fi

# Allow 32-bit packages.
sudo dpkg --add-architecture i386
sudo apt-get -yq update
$SUDO dpkg --add-architecture i386
$SUDO apt-get -yq update

sudo DEBIAN_FRONTEND=noninteractive \
$SUDO DEBIAN_FRONTEND=noninteractive \
apt-get install -yq --no-install-recommends $PACKAGES

# Find and assign UBUNTU_VERSION
Expand All @@ -76,8 +83,8 @@ curl -O http://security.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jd
curl -O http://security.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jdk_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb
curl -O http://security.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb
curl -O http://security.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb
sudo dpkg -i openjdk-8-jre-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jre_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jdk_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jdk-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb || sudo apt install -f -y
$SUDO dpkg -i openjdk-8-jre-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jre_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jdk_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jdk-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb || $SUDO apt install -f -y
rm openjdk-8-jre-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jre_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jdk_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb openjdk-8-jdk-headless_8u212-b03-0ubuntu1."$UBUNTU_VERSION"_amd64.deb

sudo mkdir -p /data/data/com.termux/files/usr
sudo chown -R $(whoami) /data
$SUDO mkdir -p /data/data/com.termux/files/usr
$SUDO chown -R $(whoami) /data

0 comments on commit bcc922f

Please sign in to comment.