From 35355a17a0ece986d3d8158172d5e74be31b7871 Mon Sep 17 00:00:00 2001 From: Gekko Wrld <108436933+gekkowrld@users.noreply.github.com> Date: Tue, 5 Sep 2023 14:55:51 +0000 Subject: [PATCH] Fix installation (#1) * fix: Use correct installation guide on various 'supported' distros * Restyle Fix installation (#2) * Restyled by shellcheck * Restyled by shellharden * Restyled by shfmt --------- Co-authored-by: Restyled.io --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io --- git-install.sh | 164 ++++++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 90 deletions(-) diff --git a/git-install.sh b/git-install.sh index fbf97fb..3813ca4 100644 --- a/git-install.sh +++ b/git-install.sh @@ -1,119 +1,103 @@ #/bin/sh -github_repo="https://github.com/git/git" +# Since this is mostly for linux devices, just install in it +# Some distro's (Saw this on antiX) that don't have the required headers +# I (or most of the people) cannot really resolve this. Plese refer to +# your distro instructions on how to get them -# Find the OS type and store it in a variable -# Some of the installations are nearly the same in different OS'es -# If you spot any, please combine to reduce redundancy -findOsType () { - - if [ $OSTYPE == "linux-gnu" ]; then - osType="Linux" - elif [ $OSTYPE == "darwin"* ]; then - osType="MacOS" - elif [ $OSTYPE == "cygwin" ]; then - osType="Cygwin" - elif [ $OSTYPE == "msys" ]; then - osType="MSYS" - elif [ $OSTYPE == "win32" ]; then - osType="Windows" - elif [ $OSTYPE == "freebsd"* ]; then - osType="FreeBSD" - else - echo "Your OS is not supported. Please install git manually." - echo "Head over to $github_repo for installation" - exit 1 - fi +# If you encounter any problem (apart from missing files and other niche errors) +# Please open a pull request on the repo that you found this file in -} +# This file and any related (specified by owners) are listed under the +# The MIT License -findOsType +# This piece of code is released in the hope of being helpful. +# It is given "AS IS" and no warranty whatsoever for any loss +# that may be encountered when use of this piece of code -# Find the distribution of the Linux system +# Any further modification to this particular file will be done here: +# https://gist.github.com/gekkowrld/77211531ae252c6c5b2abe201c696050 -function FindDiff(){ +# Set the git repo in Github +github_repo="https://github.com/git/git" - if [ $osType == "Linux" ]; then - linux_distro=$(cat /etc/*-release 2> /dev/null | grep -oP '^ID_LIKE=\K.*' | tr '[[:upper:]]' '[[:lower:]]' ) - fi +# Find the base distro e.g if you are using Linux Mint it will be +# Ubuntu and if Garuda Linux then arch +# This helps narrow down into "base" distro that are atleast well +# supported and documented -} +linux_distro=$(cat /etc/*-release 2>/dev/null | grep -oP '^ID_LIKE=\K.*' | tr '[[:upper:]]' '[[:lower:]]') # Install git on the Linux system make_git() { - # List the comands to be installed for the script to run - commands='curl, wget, tar, make, jq, sed' + # List the comands to be installed for the script to run + commands='curl, wget, tar, make, jq, sed' - # Set the delimeter to be used in seperating the commands - IFS=', ' + # Set the delimeter to be used in seperating the commands + IFS=', ' - # Loop over the commands and install each of them if unavailable - for install_command in $commands; do + # Loop over the commands and install each of them if unavailable + for install_command in "$commands"; do - if ! command -v $install_command > /dev/null 2>&1; then - sudo $1 install $install_command + if ! command -v "$install_command" >/dev/null 2>&1; then + sudo "$1" "$install_command" - if [ $? -ne 0 ]; then - echo "Could not install $install_command, please install it manually" - exit 1 - fi + if [ $? -ne 0 ]; then + echo "Could not install $install_command, please install it manually" + exit 1 + fi - fi + fi - done + done - git_version=$(curl "https://api.github.com/repos/git/git/tags" -s | jq -r '.[0].name') + git_version=$(curl "https://api.github.com/repos/git/git/tags" -s | jq -r '.[0].name') - # Download the latest "git tag" - if ! test -f "$git_version.tar.gz"; then - wget https://github.com/git/git/archive/refs/tags/$git_version.tar.gz - fi + # Download the latest "git tag" + if ! test -f "$git_version.tar.gz"; then + wget https://github.com/git/git/archive/refs/tags/"$git_version".tar.gz + fi - # Unarchive the file for use in the installation - tar -xf $git_version.tar.gz + # Unarchive the file for use in the installation + tar -xf "$git_version".tar.gz - # Switch to the git folder - git_folder=$(echo $git_version | sed -e s/v/git-/) - cd $git_folder + # Switch to the git folder + git_folder=$(echo "$git_version" | sed -e s/v/git-/) + cd "$git_folder" || exit - # This is a "faster" method of building git, if you prefer you can do a progile build - # Building profile takes a lot of time so I won't attempt to do it here - # Make them to usr/local/ for convenience instead of /usr/ because of distro upgrades - make prefix=/usr/local all doc info - sudo make prefix=/usr/local install install-doc install-html install-info + # This is a "faster" method of building git, if you prefer you can do a profile build + # Building profile takes a lot of time so I won't attempt to do it here + # Make them to usr/local/ for convenience instead of /usr/ because of distro upgrades + make prefix=/usr/local all doc info + sudo make prefix=/usr/local install install-doc install-html install-info } -if [ $osType == "Linux" ]; then - FindDiff - if [[ $linux_distro == "debian" || $linux_distro == "ubuntu" ]]; then - make_git apt-get - elif [ $linux_distro == "fedora" ]; then - if command -v dnf > /dev/null 2>&1; then - make_git dnf - else - make_git yum - fi - elif [[ $linux_distro == "arch" || $linux_distro == "arch linux" ]]; then - make_git pacman - elif [ $linux_distro == "gentoo" ]; then - make_git emerge - elif [ $linux_distro == "opensuse" ]; then - make_git zypper - elif [ $linux_distro == "alpine" ]; then - make_git apk - elif [ $linux_distro == "openbsd" ]; then - make_git pkg_add - elif [ $linux_distro == "slitaz" ]; then - make_git tazpkg - else - make_git "" 2>&1 - if [ $? -ne 0 ]; then - echo "Could not install git, head over to $github_repo for installation" - exit 1 - fi - fi - +# Try to install the required software on some distros. +# If you have the required software on any distro, then it should work + +if [ "$linux_distro" = 'debian' ] || [ "$linux_distro" = 'ubuntu' ]; then + make_git "apt-get install" +elif [ "$linux_distro" = "fedora" ]; then + if command -v dnf >/dev/null 2>&1; then + make_git dnf + else + make_git yum + fi +elif [ "$linux_distro" = 'arch' ] || [ "$linux_distro" = 'arch linux' ]; then + make_git "pacman -S" +elif [ "$linux_distro" = "gentoo" ]; then + make_git "emerge -uD" +elif [ "$linux_distro" = "opensuse" ]; then + make_git "zypper --non-interactive --auto-agree-with-licenses install" +elif [ "$linux_distro" = "alpine" ]; then + make_git "apk add" +else + make_git "" 2>&1 + if [ $? -ne 0 ]; then + echo "Could not install git, head over to $github_repo for installation" + exit 1 + fi fi