Last active
May 6, 2024 18:05
-
-
Save alexolinux/63c9b0c9bd3da09decc4f1368640dd93 to your computer and use it in GitHub Desktop.
Script to install ZSH specific version via compilation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ZSH_VER="zsh-5.9" | |
| ZSH_URL="https://www.zsh.org/pub/${ZSH_VER}.tar.xz" | |
| TMP_DIR="/tmp" | |
| # Check if the script is run as root | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "Error: This script should not be run as root." | |
| exit 1 | |
| fi | |
| # Determine package manager and required packages | |
| if [ -x "$(command -v yum)" ]; then | |
| PACKAGE_MANAGER="yum" | |
| required_packages=("gcc" "make" "ncurses-devel") | |
| elif [ -x "$(command -v apt)" ]; then | |
| PACKAGE_MANAGER="apt" | |
| required_packages=("gcc" "make" "libncurses5-dev") | |
| else | |
| echo "Error: Unsupported package manager by the script. Exiting." | |
| exit 1 | |
| fi | |
| # Check required packages | |
| for package in "${required_packages[@]}"; do | |
| # Check if the package is installed | |
| if [ "$PACKAGE_MANAGER" == "yum" ]; then | |
| if ! rpm -q "$package" &>/dev/null; then | |
| echo "Installing $package..." | |
| sudo yum install -y "$package" | |
| # Check if installation was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Failed to install $package. Exiting." | |
| exit 1 | |
| fi | |
| else | |
| echo "$package is already installed." | |
| fi | |
| elif [ "$PACKAGE_MANAGER" == "apt" ]; then | |
| if ! dpkg -s "$package" &>/dev/null; then | |
| echo "Installing $package..." | |
| sudo apt update | |
| sudo apt install -y "$package" | |
| # Check if installation was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Failed to install $package. Exiting." | |
| exit 1 | |
| fi | |
| else | |
| echo "$package is already installed." | |
| fi | |
| fi | |
| done | |
| echo "Downloading ZSH package..." | |
| curl -sL ${ZSH_URL} | tar -xJ -C ${TMP_DIR} | |
| if [ "$?" -eq 0 ]; then | |
| sudo chown -R root:root "${TMP_DIR}/${ZSH_VER}" | |
| cd "${TMP_DIR}/${ZSH_VER}" | |
| echo "ZSH Downloaded. Start compilation..." | |
| ./configure && \ | |
| make && make check | |
| if [ "$?" -ne 0 ]; then | |
| echo "Check of compilation has failed. Check logs." | |
| exit 1 | |
| else | |
| echo "Successful make tests. Proceeding with the installation..." | |
| sudo make install | |
| if [ "$?" -eq 0 ]; then | |
| echo "ZSH installed successfully!" | |
| /usr/local/bin/zsh --version | |
| echo "Make ensure the ZSH binary is in PATH configuration." | |
| cd /tmp && rm -rf "${TMP_DIR}/${ZSH_VER}" | |
| else | |
| echo "Unknown failure during ZSH Installation via make install." | |
| exit 1 | |
| fi | |
| fi | |
| else | |
| echo "ZSH installation has failed." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment