Up.
This commit is contained in:
parent
8ff56e3660
commit
dc3f2d5136
@ -1,19 +1,11 @@
|
|||||||
#!{{ lookPath "bash" }}
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Logging function
|
FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[-1]}")"
|
||||||
log() {
|
SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")"
|
||||||
printf "$(tput setaf 4)$(tput bold)>>>>> %s <<<<<$(tput sgr0)\n" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
inf() {
|
# include lib
|
||||||
printf "$(tput setaf 2)╚═══ᐳ $(tput sgr 0 1)$(tput setaf 2)%s$(tput sgr0)\n" "$1"
|
. $SCRIPT_DIRECTORY/utils.sh
|
||||||
}
|
|
||||||
|
|
||||||
err() {
|
|
||||||
printf "$(tput setaf 9)$(tput bold)>>>>> %s ! <<<<<$(tput sgr0)\n" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
log "Executing $0..."
|
|
||||||
|
|
||||||
# Packages to install
|
# Packages to install
|
||||||
packages=(
|
packages=(
|
||||||
@ -33,7 +25,6 @@ packages=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
{{ if ne .chezmoi.username "root" -}}
|
|
||||||
## Update system
|
## Update system
|
||||||
inf "updating system..."
|
inf "updating system..."
|
||||||
sudo pacman -Syu --noconfirm --quiet
|
sudo pacman -Syu --noconfirm --quiet
|
||||||
@ -41,25 +32,13 @@ packages=(
|
|||||||
## Install yay
|
## Install yay
|
||||||
if [ ! $(command -v yay) ]; then
|
if [ ! $(command -v yay) ]; then
|
||||||
inf "installing yay..."
|
inf "installing yay..."
|
||||||
sudo pacman -S --needed --noconfirm --quiet git base-devel
|
install_binary "yay"
|
||||||
git clone https://aur.archlinux.org/yay.git /tmp/yay
|
|
||||||
cd /tmp/yay
|
|
||||||
makepkg -si --noconfirm
|
|
||||||
rm -rf /tmp/yay
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Install packages
|
## Install packages
|
||||||
for package in ${packages[@]}; do
|
for package in ${packages[@]}; do
|
||||||
if [ "$(yay -Qq $package 2> /dev/null)" != $package ]; then
|
if [ "$(yay -Qq $package 2> /dev/null)" != $package ]; then
|
||||||
inf "installing ${package}..."
|
inf "installing ${package}..."
|
||||||
yay -S --noconfirm --removemake --quiet $package
|
install_binary $package "yay"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
{{ else -}}
|
|
||||||
err "you may not run this script as root"
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
83
scripts/utils.sh
Normal file
83
scripts/utils.sh
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Logging function
|
||||||
|
log() {
|
||||||
|
printf "$(tput setaf 4)$(tput bold)>>>>> %s <<<<<$(tput sgr0)\n" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
inf() {
|
||||||
|
printf "$(tput setaf 2)$(tput bold)>>>>> %s <<<<<$(tput sgr0)\n" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
err() {
|
||||||
|
printf "$(tput setaf 9)$(tput bold)>>>>> %s ! <<<<<$(tput sgr0)\n" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_binary() {
|
||||||
|
##
|
||||||
|
# Simple abstraction to install a binary using a supported package manager
|
||||||
|
# Example usage:
|
||||||
|
# install_binary "fzf"
|
||||||
|
# install_binary "fzf" "dnf"
|
||||||
|
|
||||||
|
local package_name="${1}"
|
||||||
|
local package_manager="${2}"
|
||||||
|
|
||||||
|
# Function to determine the package manager if not specified
|
||||||
|
determine_package_manager() {
|
||||||
|
if [ command -v apt-get &>/dev/null ]; then
|
||||||
|
echo "apt-get"
|
||||||
|
elif [ command -v pamac &>/dev/null ]; then
|
||||||
|
echo "pamac"
|
||||||
|
elif [ command -v yay &>/dev/null ]; then
|
||||||
|
echo "yay"
|
||||||
|
elif [ command -v pacman &>/dev/null ]; then
|
||||||
|
echo "pacman"
|
||||||
|
else
|
||||||
|
err "No supported package manager found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# If the package manager is not specified, determine it
|
||||||
|
if [[ -z "${package_manager}" ]]; then
|
||||||
|
package_manager=$(determine_package_manager)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install the package using the determined or specified package manager
|
||||||
|
inf "Installing ${package_name} using ${package_manager}..."
|
||||||
|
|
||||||
|
case "${package_manager}" in
|
||||||
|
apt-get)
|
||||||
|
sudo apt-get install --yes --no-install-recommends --ignore-missing --fix-broken -qq "${package_name}" || {
|
||||||
|
err "Installation failed."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
pacman)
|
||||||
|
sudo pacman -S --needed --noconfirm --quiet "${package_name}" || {
|
||||||
|
err "ERROR" "Installation failed."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
pamac)
|
||||||
|
sudo pamac --no-confirm "${package_name}" || {
|
||||||
|
err "Installation failed."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
yay)
|
||||||
|
yay -S --noconfirm --removemake --quiet "${package_name}" || {
|
||||||
|
err "Installation failed."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "Unsupported package manager: ${package_manager}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
inf "Installation of ${package_name} completed successfully."
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user