Skip to content

Commit 35355a1

Browse files
gekkowrldrestyled-io[bot]restyled-commits
authored
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 <commits@restyled.io> --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent ab98a65 commit 35355a1

File tree

1 file changed

+74
-90
lines changed

1 file changed

+74
-90
lines changed

git-install.sh

Lines changed: 74 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,103 @@
11
#/bin/sh
22

3-
github_repo="https://github.com/git/git"
3+
# Since this is mostly for linux devices, just install in it
4+
# Some distro's (Saw this on antiX) that don't have the required headers
5+
# I (or most of the people) cannot really resolve this. Plese refer to
6+
# your distro instructions on how to get them
47

5-
# Find the OS type and store it in a variable
6-
# Some of the installations are nearly the same in different OS'es
7-
# If you spot any, please combine to reduce redundancy
8-
findOsType () {
9-
10-
if [ $OSTYPE == "linux-gnu" ]; then
11-
osType="Linux"
12-
elif [ $OSTYPE == "darwin"* ]; then
13-
osType="MacOS"
14-
elif [ $OSTYPE == "cygwin" ]; then
15-
osType="Cygwin"
16-
elif [ $OSTYPE == "msys" ]; then
17-
osType="MSYS"
18-
elif [ $OSTYPE == "win32" ]; then
19-
osType="Windows"
20-
elif [ $OSTYPE == "freebsd"* ]; then
21-
osType="FreeBSD"
22-
else
23-
echo "Your OS is not supported. Please install git manually."
24-
echo "Head over to $github_repo for installation"
25-
exit 1
26-
fi
8+
# If you encounter any problem (apart from missing files and other niche errors)
9+
# Please open a pull request on the repo that you found this file in
2710

28-
}
11+
# This file and any related (specified by owners) are listed under the
12+
# The MIT License
2913

30-
findOsType
14+
# This piece of code is released in the hope of being helpful.
15+
# It is given "AS IS" and no warranty whatsoever for any loss
16+
# that may be encountered when use of this piece of code
3117

32-
# Find the distribution of the Linux system
18+
# Any further modification to this particular file will be done here:
19+
# https://gist.github.com/gekkowrld/77211531ae252c6c5b2abe201c696050
3320

34-
function FindDiff(){
21+
# Set the git repo in Github
22+
github_repo="https://github.com/git/git"
3523

36-
if [ $osType == "Linux" ]; then
37-
linux_distro=$(cat /etc/*-release 2> /dev/null | grep -oP '^ID_LIKE=\K.*' | tr '[[:upper:]]' '[[:lower:]]' )
38-
fi
24+
# Find the base distro e.g if you are using Linux Mint it will be
25+
# Ubuntu and if Garuda Linux then arch
26+
# This helps narrow down into "base" distro that are atleast well
27+
# supported and documented
3928

40-
}
29+
linux_distro=$(cat /etc/*-release 2>/dev/null | grep -oP '^ID_LIKE=\K.*' | tr '[[:upper:]]' '[[:lower:]]')
4130

4231
# Install git on the Linux system
4332

4433
make_git() {
4534

46-
# List the comands to be installed for the script to run
47-
commands='curl, wget, tar, make, jq, sed'
35+
# List the comands to be installed for the script to run
36+
commands='curl, wget, tar, make, jq, sed'
4837

49-
# Set the delimeter to be used in seperating the commands
50-
IFS=', '
38+
# Set the delimeter to be used in seperating the commands
39+
IFS=', '
5140

52-
# Loop over the commands and install each of them if unavailable
53-
for install_command in $commands; do
41+
# Loop over the commands and install each of them if unavailable
42+
for install_command in "$commands"; do
5443

55-
if ! command -v $install_command > /dev/null 2>&1; then
56-
sudo $1 install $install_command
44+
if ! command -v "$install_command" >/dev/null 2>&1; then
45+
sudo "$1" "$install_command"
5746

58-
if [ $? -ne 0 ]; then
59-
echo "Could not install $install_command, please install it manually"
60-
exit 1
61-
fi
47+
if [ $? -ne 0 ]; then
48+
echo "Could not install $install_command, please install it manually"
49+
exit 1
50+
fi
6251

63-
fi
52+
fi
6453

65-
done
54+
done
6655

67-
git_version=$(curl "https://api.github.com/repos/git/git/tags" -s | jq -r '.[0].name')
56+
git_version=$(curl "https://api.github.com/repos/git/git/tags" -s | jq -r '.[0].name')
6857

69-
# Download the latest "git tag"
70-
if ! test -f "$git_version.tar.gz"; then
71-
wget https://github.com/git/git/archive/refs/tags/$git_version.tar.gz
72-
fi
58+
# Download the latest "git tag"
59+
if ! test -f "$git_version.tar.gz"; then
60+
wget https://github.com/git/git/archive/refs/tags/"$git_version".tar.gz
61+
fi
7362

74-
# Unarchive the file for use in the installation
75-
tar -xf $git_version.tar.gz
63+
# Unarchive the file for use in the installation
64+
tar -xf "$git_version".tar.gz
7665

77-
# Switch to the git folder
78-
git_folder=$(echo $git_version | sed -e s/v/git-/)
79-
cd $git_folder
66+
# Switch to the git folder
67+
git_folder=$(echo "$git_version" | sed -e s/v/git-/)
68+
cd "$git_folder" || exit
8069

81-
# This is a "faster" method of building git, if you prefer you can do a progile build
82-
# Building profile takes a lot of time so I won't attempt to do it here
83-
# Make them to usr/local/ for convenience instead of /usr/ because of distro upgrades
84-
make prefix=/usr/local all doc info
85-
sudo make prefix=/usr/local install install-doc install-html install-info
70+
# This is a "faster" method of building git, if you prefer you can do a profile build
71+
# Building profile takes a lot of time so I won't attempt to do it here
72+
# Make them to usr/local/ for convenience instead of /usr/ because of distro upgrades
73+
make prefix=/usr/local all doc info
74+
sudo make prefix=/usr/local install install-doc install-html install-info
8675

8776
}
8877

89-
if [ $osType == "Linux" ]; then
90-
FindDiff
91-
if [[ $linux_distro == "debian" || $linux_distro == "ubuntu" ]]; then
92-
make_git apt-get
93-
elif [ $linux_distro == "fedora" ]; then
94-
if command -v dnf > /dev/null 2>&1; then
95-
make_git dnf
96-
else
97-
make_git yum
98-
fi
99-
elif [[ $linux_distro == "arch" || $linux_distro == "arch linux" ]]; then
100-
make_git pacman
101-
elif [ $linux_distro == "gentoo" ]; then
102-
make_git emerge
103-
elif [ $linux_distro == "opensuse" ]; then
104-
make_git zypper
105-
elif [ $linux_distro == "alpine" ]; then
106-
make_git apk
107-
elif [ $linux_distro == "openbsd" ]; then
108-
make_git pkg_add
109-
elif [ $linux_distro == "slitaz" ]; then
110-
make_git tazpkg
111-
else
112-
make_git "" 2>&1
113-
if [ $? -ne 0 ]; then
114-
echo "Could not install git, head over to $github_repo for installation"
115-
exit 1
116-
fi
117-
fi
118-
78+
# Try to install the required software on some distros.
79+
# If you have the required software on any distro, then it should work
80+
81+
if [ "$linux_distro" = 'debian' ] || [ "$linux_distro" = 'ubuntu' ]; then
82+
make_git "apt-get install"
83+
elif [ "$linux_distro" = "fedora" ]; then
84+
if command -v dnf >/dev/null 2>&1; then
85+
make_git dnf
86+
else
87+
make_git yum
88+
fi
89+
elif [ "$linux_distro" = 'arch' ] || [ "$linux_distro" = 'arch linux' ]; then
90+
make_git "pacman -S"
91+
elif [ "$linux_distro" = "gentoo" ]; then
92+
make_git "emerge -uD"
93+
elif [ "$linux_distro" = "opensuse" ]; then
94+
make_git "zypper --non-interactive --auto-agree-with-licenses install"
95+
elif [ "$linux_distro" = "alpine" ]; then
96+
make_git "apk add"
97+
else
98+
make_git "" 2>&1
99+
if [ $? -ne 0 ]; then
100+
echo "Could not install git, head over to $github_repo for installation"
101+
exit 1
102+
fi
119103
fi

0 commit comments

Comments
 (0)