Shift functions around

This commit is contained in:
dabruh 2022-11-10 15:43:45 +01:00
parent 96c8473efe
commit 279fcecbf1

View file

@ -3,6 +3,7 @@
#
# Default variables
#
UPGRADE_PACKAGES=false
SCRIPT_NAME="$(basename -- "$0")"
SCRIPT_DIR="$(
@ -10,13 +11,9 @@ SCRIPT_DIR="$(
pwd -P
)"
function _acpib() {
acpi -b | grep -Fv ' 0%'
}
function is_laptop() {
[[ $(_acpib | wc -l) -gt 0 ]] && return 0 || return 1
}
#
# Argument parsing and help
#
function usage() {
echo "Usage: $SCRIPT_NAME [OPTIONS]"
@ -44,6 +41,18 @@ while getopts ":uh" arg; do
esac
done
#
# Distribution-agnostic functions
#
function _acpib() {
acpi -b | grep -Fv ' 0%'
}
function is_laptop() {
[[ $(_acpib | wc -l) -gt 0 ]] && return 0 || return 1
}
# Returns a comma-separated list of packages for one or more targets.
# The packages file may contain multiple rows with the same target name.
function get_packages() {
@ -58,48 +67,6 @@ function get_packages() {
done
}
function prepare_arch() {
which pamac >/dev/null && return 0
sudo pacman -S pamac --noconfirm || return 1
}
function setup_arch_with_pamac() {
local targets=("pacman-any") packages
is_laptop && targets+=("pacman-laptop")
packages="$(get_packages "${targets[@]}")"
# shellcheck disable=SC2086
sudo pamac install $packages --no-confirm || return 1
}
function setup_arch_with_yay() {
local targets=("aur-any") packages
is_laptop && targets+=("aur-laptop")
for package in $(get_packages "${targets[@]}"); do
if pacman -Qs "^$package$" >/dev/null; then
if $UPGRADE_PACKAGES; then
echo "Package '$package' will be upgraded."
else
echo "Package '$package' already exists."
continue
fi
else
echo "Package '$package' will be installed."
fi
sudo pamac build "$package" --no-confirm || return 1
done
}
function setup_arch_with_pip(){
local targets=("pip-any") packages
packages="$(get_packages "${targets[@]}")"
# shellcheck disable=SC2086
sudo pip3 install $packages --no-input || return 1
}
function install_sddm_aerial_theme() {
local theme_dir="/usr/share/sddm/themes/aerial"
@ -147,6 +114,68 @@ function configure_ufw() {
sudo ufw allow ssh || return 4
}
function install_picom() {
local tmp=/tmp/picom
echo "Installing Picom."
rm -Rf "$tmp"
git clone https://github.com/yshui/picom.git "$tmp" || return 1
cd "$tmp" || return 2
git submodule update --init --recursive || return 3
meson --buildtype=release . build || return 4
ninja -C build || return 5
sudo ninja -C build install || return 6
cd || return 7
rm -Rf "$tmp"
}
#
# Setup for Arch-like systems
#
function prepare_arch() {
which pamac >/dev/null && return 0
sudo pacman -S pamac --noconfirm || return 1
}
function setup_arch_with_pamac() {
local targets=("pacman-any") packages
is_laptop && targets+=("pacman-laptop")
packages="$(get_packages "${targets[@]}")"
# shellcheck disable=SC2086
sudo pamac install $packages --no-confirm || return 1
}
function setup_arch_with_yay() {
local targets=("aur-any") packages
is_laptop && targets+=("aur-laptop")
for package in $(get_packages "${targets[@]}"); do
if pacman -Qs "^$package$" >/dev/null; then
if $UPGRADE_PACKAGES; then
echo "Package '$package' will be upgraded."
else
echo "Package '$package' already exists."
continue
fi
else
echo "Package '$package' will be installed."
fi
sudo pamac build "$package" --no-confirm || return 1
done
}
function setup_arch_with_pip(){
local targets=("pip-any") packages
packages="$(get_packages "${targets[@]}")"
# shellcheck disable=SC2086
sudo pip3 install $packages --no-input || return 1
}
function setup_arch() {
prepare_arch || return 1
setup_arch_with_pamac || return 2
@ -156,6 +185,10 @@ function setup_arch() {
configure_ufw || return 6
}
#
# Setup for Debian-like systems
#
function setup_debian_repo_i3gaps() {
echo "Setting up repository for i3-gaps."
sudo add-apt-repository -y ppa:regolith-linux/release
@ -193,22 +226,6 @@ function setup_debian_with_pip(){
sudo pip3 install $packages --no-input || return 1
}
function install_picom() {
local tmp=/tmp/picom
echo "Installing Picom."
rm -Rf "$tmp"
git clone https://github.com/yshui/picom.git "$tmp" || return 1
cd "$tmp" || return 2
git submodule update --init --recursive || return 3
meson --buildtype=release . build || return 4
ninja -C build || return 5
sudo ninja -C build install || return 6
cd || return 7
rm -Rf "$tmp"
}
function setup_debian_with_git() {
install_picom || return 1
install_sddm_aerial_theme || return 2