Skip to content

Commit

Permalink
setup: Use a Single Script for all currently supported Distros
Browse files Browse the repository at this point in the history
Signed-off-by: Sushrut1101 <guptasushrut@gmail.com>
  • Loading branch information
Sushrut1101 committed Aug 1, 2022
1 parent 980e6d1 commit 4dad9fe
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 188 deletions.
9 changes: 5 additions & 4 deletions README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Then, run these commands
```bash
$ git clone https://github.com/akhilnarang/scripts
$ cd scripts
$ bash setup/<name of script>
$ bash setup/android_build_env.sh
```

`android_build_env.sh` is for Ubuntu/Linux Mint/other distributions using the `apt` package manager.
The rest are named as per the distro.
OR

Please run the correct script depending on the distro you have installed!
```bash
$ bash -c "$(curl -sL https://raw.githubusercontent.com/akhilnarang/scripts/master/setup/android_build_env.sh)"
```

Enjoy!

Expand Down
3 changes: 0 additions & 3 deletions files
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ rr/crowdin.sh
rr/copy_ftp.sh
rr/push_json.sh
setup/android_build_env.sh
setup/arch-manjaro.sh
setup/ccache.sh
setup/create_user.sh
setup/crowdin-cli.sh
setup/fedora.sh
setup/git.sh
setup/hub.sh
setup/install_android_sdk.sh
setup/make.sh
setup/solus.sh
zsh/setup.sh
228 changes: 168 additions & 60 deletions setup/android_build_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,174 @@

# Script to setup an AOSP Build environment on Ubuntu and Linux Mint

LATEST_MAKE_VERSION="4.3"
UBUNTU_16_PACKAGES="libesd0-dev"
UBUNTU_20_PACKAGES="libncurses5 curl python-is-python3"
DEBIAN_10_PACKAGES="libncurses5"
DEBIAN_11_PACKAGES="libncurses5"
PACKAGES=""

sudo apt install software-properties-common -y
sudo apt update

# Install lsb-core packages
sudo apt install lsb-core -y

LSB_RELEASE="$(lsb_release -d | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//')"

if [[ ${LSB_RELEASE} =~ "Mint 18" || ${LSB_RELEASE} =~ "Ubuntu 16" ]]; then
PACKAGES="${UBUNTU_16_PACKAGES}"
elif [[ ${LSB_RELEASE} =~ "Ubuntu 20" || ${LSB_RELEASE} =~ "Ubuntu 21" || ${LSB_RELEASE} =~ "Ubuntu 22" ]]; then
PACKAGES="${UBUNTU_20_PACKAGES}"
elif [[ ${LSB_RELEASE} =~ "Debian GNU/Linux 10" ]]; then
PACKAGES="${DEBIAN_10_PACKAGES}"
elif [[ ${LSB_RELEASE} =~ "Debian GNU/Linux 11" ]]; then
PACKAGES="${DEBIAN_11_PACKAGES}"
fi
tput reset 2>/dev/null || clear

# Ubuntu/Debian Based Distros
if [[ "$(command -v apt)" != "" ]]; then

echo "Debian/Ubuntu Based Distro Detected"
sleep 1

LATEST_MAKE_VERSION="4.3"
UBUNTU_16_PACKAGES="libesd0-dev"
UBUNTU_20_PACKAGES="libncurses5 curl python-is-python3"
DEBIAN_10_PACKAGES="libncurses5"
DEBIAN_11_PACKAGES="libncurses5"
PACKAGES=""

sudo apt install software-properties-common -y
sudo apt update

sudo DEBIAN_FRONTEND=noninteractive \
apt install \
adb autoconf automake axel bc bison build-essential \
ccache clang cmake curl expat fastboot flex g++ \
g++-multilib gawk gcc gcc-multilib git gnupg gperf \
htop imagemagick lib32ncurses5-dev lib32z1-dev libtinfo5 libc6-dev libcap-dev \
libexpat1-dev libgmp-dev '^liblz4-.*' '^liblzma.*' libmpc-dev libmpfr-dev libncurses5-dev \
libsdl1.2-dev libssl-dev libtool libxml2 libxml2-utils '^lzma.*' lzop \
maven ncftp ncurses-dev patch patchelf pkg-config pngcrush \
pngquant python2.7 python-all-dev re2c schedtool squashfs-tools subversion \
texinfo unzip w3m xsltproc zip zlib1g-dev lzip \
libxml-simple-perl libswitch-perl apt-utils \
${PACKAGES} -y

echo -e "Installing GitHub CLI"
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install -y gh

echo -e "Setting up udev rules for adb!"
sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules
sudo chmod 644 /etc/udev/rules.d/51-android.rules
sudo chown root /etc/udev/rules.d/51-android.rules
sudo systemctl restart udev

if [[ "$(command -v make)" ]]; then
makeversion="$(make -v | head -1 | awk '{print $3}')"
if [[ ${makeversion} != "${LATEST_MAKE_VERSION}" ]]; then
echo "Installing make ${LATEST_MAKE_VERSION} instead of ${makeversion}"
bash "$(dirname "$0")"/make.sh "${LATEST_MAKE_VERSION}"
# Install lsb-core packages
sudo apt install lsb-core -y

LSB_RELEASE="$(lsb_release -d | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//')"

if [[ ${LSB_RELEASE} =~ "Mint 18" || ${LSB_RELEASE} =~ "Ubuntu 16" ]]; then
PACKAGES="${UBUNTU_16_PACKAGES}"
elif [[ ${LSB_RELEASE} =~ "Ubuntu 20" || ${LSB_RELEASE} =~ "Ubuntu 21" || ${LSB_RELEASE} =~ "Ubuntu 22" ]]; then
PACKAGES="${UBUNTU_20_PACKAGES}"
elif [[ ${LSB_RELEASE} =~ "Debian GNU/Linux 10" ]]; then
PACKAGES="${DEBIAN_10_PACKAGES}"
elif [[ ${LSB_RELEASE} =~ "Debian GNU/Linux 11" ]]; then
PACKAGES="${DEBIAN_11_PACKAGES}"
fi
fi

echo "Installing repo"
sudo curl --create-dirs -L -o /usr/local/bin/repo -O -L https://storage.googleapis.com/git-repo-downloads/repo
sudo chmod a+rx /usr/local/bin/repo
sudo DEBIAN_FRONTEND=noninteractive \
apt install \
adb autoconf automake axel bc bison build-essential \
ccache clang cmake curl expat fastboot flex g++ \
g++-multilib gawk gcc gcc-multilib git gnupg gperf \
htop imagemagick lib32ncurses5-dev lib32z1-dev libtinfo5 libc6-dev libcap-dev \
libexpat1-dev libgmp-dev '^liblz4-.*' '^liblzma.*' libmpc-dev libmpfr-dev libncurses5-dev \
libsdl1.2-dev libssl-dev libtool libxml2 libxml2-utils '^lzma.*' lzop \
maven ncftp ncurses-dev patch patchelf pkg-config pngcrush \
pngquant python2.7 python-all-dev re2c schedtool squashfs-tools subversion \
texinfo unzip w3m xsltproc zip zlib1g-dev lzip \
libxml-simple-perl libswitch-perl apt-utils \
${PACKAGES} -y

echo -e "Installing GitHub CLI"
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install -y gh

echo -e "Setting up udev rules for adb!"
sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules
sudo chmod 644 /etc/udev/rules.d/51-android.rules
sudo chown root /etc/udev/rules.d/51-android.rules
sudo systemctl restart udev

if [[ "$(command -v make)" ]]; then
makeversion="$(make -v | head -1 | awk '{print $3}')"
if [[ ${makeversion} != "${LATEST_MAKE_VERSION}" ]]; then
echo "Installing make ${LATEST_MAKE_VERSION} instead of ${makeversion}"
bash "$(dirname "$0")"/make.sh "${LATEST_MAKE_VERSION}"
fi
fi

echo "Installing repo"
sudo curl --create-dirs -L -o /usr/local/bin/repo -O -L https://storage.googleapis.com/git-repo-downloads/repo
sudo chmod a+rx /usr/local/bin/repo

echo 'Setup completed, enjoy'
exit 0

# Arch Based Distros
elif [[ "$(command -v pacman)" != "" ]]; then

echo "Arch Based Distro Detected"
sleep 1

echo 'Starting Arch-based Android build setup'
# Uncomment the multilib repo, incase it was commented out
echo '[1/4] Enabling multilib repo'
sudo sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf
# Sync, update, and prepare system
echo '[2/4] Syncing repositories and updating system packages'
sudo pacman -Syyu --noconfirm --needed multilib-devel
# Install android build prerequisites
echo '[3/4] Installing Android building prerequisites'
packages="ncurses5-compat-libs lib32-ncurses5-compat-libs aosp-devel xml2 lineageos-devel libxcrypt-compat"
for package in $packages; do
echo "Installing $package"
git clone https://aur.archlinux.org/"$package"
cd "$package" || exit
makepkg -si --skippgpcheck --noconfirm --needed
cd - || exit
rm -rf "$package"
done

# Install adb and associated udev rules
echo '[4/4] Installing adb convenience tools'
sudo pacman -S --noconfirm --needed android-tools android-udev

echo 'Setup completed, enjoy'
exit 0

# Fedora/RHEL Based Distros
elif [[ "$(command -v dnf)" != "" ]]; then

echo "Fedora Based Distro Detected"
sleep 1

# Packages
sudo dnf install \
android-tools autoconf213 bison bzip2 ccache curl patch \
flex gawk gcc-c++ git glibc-devel glibc-static libstdc++-static \
libX11-devel make mesa-libGL-devel ncurses-devel openssl \
zlib-devel ncurses-devel.i686 readline-devel.i686 zlib-devel.i686 \
libX11-devel.i686 mesa-libGL-devel.i686 glibc-devel.i686 \
libstdc++.i686 libXrandr.i686 zip perl-Digest-SHA python2 wget \
lzop openssl-devel java-1.8.0-openjdk-devel ImageMagick \
ncurses-compat-libs schedtool lzip vboot-utils vim

# The package libncurses5 is not available, so we need to hack our way by symlinking the required library.
sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5
sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libtinfo.so.5

# Repo
echo "Installing Git Repository Tool"
sudo curl --create-dirs -L -o /usr/local/bin/repo -O -L https://storage.googleapis.com/git-repo-downloads/repo
sudo chmod a+rx /usr/local/bin/repo

echo -e "Setting up udev rules for ADB!"
sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules
sudo chmod 644 /etc/udev/rules.d/51-android.rules
sudo chown root /etc/udev/rules.d/51-android.rules
sudo udevadm control --reload-rules

echo 'Setup completed, enjoy'
exit 0

# Solus
elif [[ "$(command -v eopkg)" != "" ]]; then

echo "Solus Detected"
sleep 1

sudo eopkg it -c system.devel
sudo eopkg it openjdk-8-devel curl-devel git gnupg gperf libgcc-32bit libxslt-devel lzop ncurses-32bit-devel ncurses-devel readline-32bit-devel rsync schedtool sdl1-devel squashfs-tools unzip wxwidgets-devel zip zlib-32bit-devel lzip

# ADB/Fastboot
sudo eopkg bi --ignore-safety https://raw.githubusercontent.com/solus-project/3rd-party/master/programming/tools/android-tools/pspec.xml
sudo eopkg it android-tools*.eopkg
sudo rm android-tools*.eopkg

# udev rules
echo "Setting up udev rules for adb!"
sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules
sudo chmod 644 /etc/udev/rules.d/51-android.rules
sudo chown root /etc/udev/rules.d/51-android.rules
sudo usysconf run -f

echo "Installing repo"
sudo curl --create-dirs -L -o /usr/local/bin/repo -O -L https://storage.googleapis.com/git-repo-downloads/repo
sudo chmod a+x /usr/local/bin/repo

echo "You are now ready to build Android!"
exit 0

fi
29 changes: 0 additions & 29 deletions setup/arch-manjaro.sh

This file was deleted.

65 changes: 0 additions & 65 deletions setup/fedora.sh

This file was deleted.

27 changes: 0 additions & 27 deletions setup/solus.sh

This file was deleted.

0 comments on commit 4dad9fe

Please sign in to comment.