-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·157 lines (133 loc) · 5.08 KB
/
install.sh
File metadata and controls
executable file
·157 lines (133 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env bash
# Echo to stderr
echoerr() { echo "$@" 1>&2; }
# Display an error message and quit
error() {
echoerr "Error, $1"
exit 1
}
is_command() {
# Checks to see if the given command (passed as a string argument) exists on the system.
# Returns 0 (success) if the command exists, and 1 if it doesn't.
local check_command="$1"
command -v "${check_command}" >/dev/null 2>&1
}
# Check distro and determine what packages to install, then install.
install_packages() {
# If apt-get is installed, then we know it's part of the Debian family
if is_command apt-get; then
PKG_MANAGER="apt-get"
PKG_INSTALL=("${PKG_MANAGER}" -qq --no-install-recommends install)
INSTALLER_DEPS=(cmake curl gcc git libcurl4-openssl-dev make zsh jq)
DEPS=(emacs fzf g++ lolcat ripgrep shellcheck shfmt tmux vim wget xclip xdg-utils)
# If apt-get is not found, check for rpm to see if it's a Red Hat family OS
elif is_command rpm; then
# Then check if dnf or yum is the package manager
if is_command dnf; then
PKG_MANAGER="dnf"
else
PKG_MANAGER="yum"
fi
# These variable names match the ones in the Debian family. See above for an explanation of what they are for.
PKG_INSTALL=("${PKG_MANAGER}" install -y)
INSTALLER_DEPS=(cmake curl gcc git libcurl libcurl-devel make zsh jq)
DEPS=(ShellCheck fzf g++ lolcat ripgrep shfmt tmux vim wget xclip xdg-utils)
# If the host OS is Fedora,
if grep -qiE 'fedora|fedberry' /etc/redhat-release; then
# all required packages should be available by default with the latest fedora release
: # continue
# or if host OS is CentOS,
elif grep -qiE 'centos|scientific' /etc/redhat-release; then
# Pi-Hole currently supports CentOS 7+ with PHP7+
SUPPORTED_CENTOS_VERSION=7
# Check current CentOS major release version
CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release)
# Check if CentOS version is supported
if [[ $CURRENT_CENTOS_VERSION -lt $SUPPORTED_CENTOS_VERSION ]]; then
printf " %b CentOS %s is not supported.\\n" "${CROSS}" "${CURRENT_CENTOS_VERSION}"
printf " Please update to CentOS release %s or later.\\n" "${SUPPORTED_CENTOS_VERSION}"
# exit the installer
exit
fi
# CentOS requires the EPEL repository to gain access to Fedora packages
EPEL_PKG="epel-release"
rpm -q ${EPEL_PKG} &>/dev/null || rc=$?
if [[ $rc -ne 0 ]]; then
printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}"
"${PKG_INSTALL[@]}" ${EPEL_PKG} &>/dev/null
printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}"
fi
fi
elif is_command pacman; then
PKG_MANAGER="pacman"
PKG_INSTALL=("${PKG_MANAGER}" -S --noconfirm --needed)
INSTALLER_DEPS=(cmake curl gcc git make zsh jq)
DEPS=(fzf ripgrep vim wget xclip xdg-utils)
elif is_command emerge; then
echo "=============================================="
echo "= Ensure your use flags are set correctly!!! ="
echo "=============================================="
sleep 5
sudo emerge -n --ask $(< gentoo.pkglist)
return
else
# If not apt-get, yum/dnf, pacman, or emerge, not supported.
# it's not an OS we can support,
printf " %b OS distribution not supported\\n" "${CROSS}"
# so exit the installer
exit 2
fi
# We've determined that we have a valid package manager, and set the necessary packages for this specific distro.
# Go ahead and install everything.
for package in "${INSTALLER_DEPS[@]}"; do
if ! is_command "${package}"; then
sudo "${PKG_INSTALL[@]}" "${package}"
fi
done
for package in "${DEPS[@]}"; do
if ! is_command "${package}"; then
sudo "${PKG_INSTALL[@]}" "${package}"
fi
done
}
install_dotEngine() {
local api_endpoint
local dest_dir
local download_link
local dotEngine_path
local dotEngine_vers
api_endpoint="https://api.github.com/repos/jarulsamy/dotEngine/releases/latest"
dest_dir="$HOME/.local/bin"
download_link=$(curl --silent "$api_endpoint" | jq -r ".assets[0].browser_download_url")
if [ ! "$?" -eq 0 ]; then
echoerr "Failed to find latest dotEngine release."
return
fi
mkdir -pv "$dest_dir"
dotEngine_path="${dest_dir}/dotEngine"
printf "Downloading dotEngine...\n"
curl -L "$download_link" -o "${dotEngine_path}"
if [ ! "$?" -eq 0 ]; then
echoerr "Failed to download dotEngine."
return
fi
dotEngine_vers="$(${dotEngine_path} --version)"
chmod +x "$dest_dir"/dotEngine
printf "Installed dotEngine v%s to %s\n" "$dotEngine_vers" "$dest_dir"
}
install_ohmyzsh() {
# Install oh-my-zsh, if not already present
# https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
export RUNZSH="no"
export CHSH="yes"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
else
echoerr "Skipping oh-my-zsh install, $HOME/.oh-my-zsh already exists."
fi
}
CWD="$(pwd)"
install_packages
install_dotEngine
install_ohmyzsh
cd "$CWD" || exit 0