setup scripts: do not use sudo if already running under root

Reworked variant of https://github.com/termux/termux-packages/pull/4753.
This commit is contained in:
Leonid Pliushch 2020-01-06 18:33:55 +02:00
parent 975d29b5ed
commit 99236ea338
2 changed files with 35 additions and 16 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e -u
PACKAGES=""
@ -43,9 +43,14 @@ PACKAGES+=" lua" # Needed to build luarocks package.
PACKAGES+=" python-recommonmark" # Needed for LLVM-8 documentation.
PACKAGES+=" jre8-openjdk-headless"
sudo pacman -Syq --noconfirm $PACKAGES
sudo mkdir -p /data/data/com.termux/files/usr
sudo chown -R $(whoami) /data
# Do not require sudo if already running as root.
if [ "$(id -u)" = "0" ]; then
SUDO=""
else
SUDO="sudo"
fi
$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"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e -u
PACKAGES=""
@ -58,11 +58,18 @@ PACKAGES+=" zip" # For smalltalk.
PACKAGES+=" libssl-dev:i386" # Needed by swi-prolog 32-bit
PACKAGES+=" zlib1g-dev:i386"
# Allow 32-bit packages.
sudo dpkg --add-architecture i386
sudo apt-get -yq update
# Do not require sudo if already running as root.
if [ "$(id -u)" = "0" ]; then
SUDO=""
else
SUDO="sudo"
fi
sudo DEBIAN_FRONTEND=noninteractive \
# Allow 32-bit packages.
$SUDO dpkg --add-architecture i386
$SUDO apt-get -yq update
$SUDO DEBIAN_FRONTEND=noninteractive \
apt-get install -yq --no-install-recommends $PACKAGES
# Find and assign UBUNTU_VERSION
@ -77,11 +84,18 @@ 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
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 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 locale-gen --purge en_US.UTF-8
echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' | sudo tee -a /etc/default/locale
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 locale-gen --purge en_US.UTF-8
echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' | $SUDO tee -a /etc/default/locale
$SUDO mkdir -p /data/data/com.termux/files/usr
$SUDO chown -R $(whoami) /data