doti/std.sh

91 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Intendet to be sourced
function error() {
echo "ERROR [${PROGRAM}] " $@
exit 1
}
function info() {
echo "INFO [${PROGRAM}] " $@
}
function verbose() {
if [[ -n "${DOTI_VERBOSE}" ]]; then
echo "VERBOSE [${PROGRAM}] " $@
fi
}
function pacinstall() {
local program=$1
pacman -Q ${program} &> /dev/null
if [[ "$?" -ne "0" ]]; then
info "Installing ${program}"
sudo pacman -S --noconfirm ${program}
else
verbose "${program} already installed."
fi
}
function yayinstall() {
local program=$1
yay -Q ${program} &> /dev/null
if [[ "$?" -ne "0" ]]; then
info "Installing ${program}"
yay -S --noconfirm ${program}
else
verbose "${program} already installed."
fi
}
# function install_config_file() {
# local file=$1
# local dir=$1
#
# mkdir -p "${dir}"
#
# cp -v "configs/${file}" "${dir}/${file}"
# }
function config_url_install() {
local file=$1
local url=$2
local dir=$(dirname "${file}")
mkdir -v -p "${dir}"
curl -s -o "${file}" -L "${url}"
verbose "${url} -> ${file}"
}
function config_from_nixos_config() {
local file=$1
local dir=$2
if [[ -z "${dir}" ]]; then
dir="${file}"
fi
config_url_install "${HOME}/.config/${dir}" "https://raw.githubusercontent.com/RoBaertschi/nixos-config/refs/heads/master/configs/${file}"
}
function unit_enable() {
sudo systemctl enable $1
}
function user_unit_enable() {
systemctl enable --user $1
}
function program_begin() {
if [[ -n "${PROGRAM}" ]]; then
error "${PROGRAM} still on the program stack"
fi
export PROGRAM=$1
info "Installing and configuring ${PROGRAM}"
}
function program_end() {
verbose "${PROGRAM} done"
PROGRAM=""
}