This commit is contained in:
deathbybandaid 2022-03-11 13:05:01 -05:00
parent e10d990f1c
commit 41493df3c7

View File

@ -1,24 +1,84 @@
#!/bin/bash
is_command() {
local check_command="$1"
command -v "${check_command}" >/dev/null 2>&1
}
git_update() {
local git_name="$1"
local git_path="$2"
local git_repo="$3"
if [ ! -d "$git_path" ]; then
echo "* Installing $git_name"
git clone --quiet $git_repo $git_path
else
echo "* Updating $git_name"
git -C $git_path pull
fi
}
should_apt_last_update() {
LAST_UPDATED=$( stat --format="%X" /var/cache/apt/pkgcache.bin )
UNIX_TIME=$( date +%s )
TIME_DIFF=$(( UNIX_TIME - LAST_UPDATED ))
if [[ "${TIME_DIFF}" -gt 43200 ]]
then
# 0 = true
return 0
else
# 1 = false
return 1
fi
}
get_pkg_mgr() {
if is_command apt-get ; then
echo "apt-get"
elif is_command rpm ; then
# Then check if dnf or yum is the package manager
if is_command dnf ; then
echo "dnf"
else
echo "yum"
fi
fi
}
install_pkg() {
# package to install
local pkg_to_install="$1"
# Get Command language
PKG_MANAGER=$( get_pkg_mgr )
# Run apt-get update for distros that use apt-get
if [ "$PKG_MANAGER" == "apt-get" ] ; then
if should_apt_last_update ; then
"${PKG_MANAGER} update"
fi
fi
# Install the package
local PKG_INSTALL=("${PKG_MANAGER}" install -y)
"${PKG_INSTALL[@]}" "${pkg_to_install}"
}
echo "Checking For git"
if which git >/dev/null;
if is_command git;
then
echo "* git Is Already Installed."
else
echo "* Running Update command and Installing git"
apt update && apt install -y git
install_pkg git
fi
echo "Checking for installation script"
template_setup_path="/etc/template_setup"
template_setup_git="https://git.deathbybandaid.net/deathbybandaid/template_setup.git"
if [ ! -d "$template_setup_path" ]; then
echo "* Installing Bash Aliases"
git clone --quiet $template_setup_git $template_setup_path
else
echo "* Updating Bash Aliases"
git -C $template_setup_path pull
fi
git_update "template_setup" "$template_setup_path" "$template_setup_git"
echo "Running installation"
bash "$template_setup_path/template_setup.sh"