2022-05-27 21:07:07 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Default variables
|
|
|
|
#
|
|
|
|
UPGRADE_PACKAGES=false
|
|
|
|
SCRIPT_NAME="$(basename -- "$0")"
|
|
|
|
SCRIPT_DIR="$(
|
|
|
|
cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1
|
|
|
|
pwd -P
|
|
|
|
)"
|
|
|
|
|
|
|
|
function _acpib() {
|
|
|
|
acpi -b | grep -Fv ' 0%'
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_laptop() {
|
|
|
|
[[ $(_acpib | wc -l) -gt 0 ]] && return 0 || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "Usage: $SCRIPT_NAME [OPTIONS]"
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " -h Display help."
|
|
|
|
echo " -u Upgrade existing packages."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts ":uh" arg; do
|
|
|
|
case $arg in
|
|
|
|
h) usage ;;
|
|
|
|
u) UPGRADE_PACKAGES=true ;;
|
|
|
|
:)
|
|
|
|
echo "$0: Must supply an argument to -$OPTARG." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
?)
|
|
|
|
echo "Invalid option: -${OPTARG}."
|
|
|
|
echo
|
|
|
|
usage
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# 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() {
|
|
|
|
local packages pkg_file="$SCRIPT_DIR/.installer/packages"
|
|
|
|
|
|
|
|
for target in "$@"; do
|
|
|
|
while read -r row; do
|
|
|
|
for package in ${row//,/ }; do
|
|
|
|
echo "$package"
|
|
|
|
done
|
|
|
|
done <<<"$(grep "^${target:?}:" "$pkg_file" | cut -d':' -f2)"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function configure_sddm() {
|
|
|
|
local sddm_config_dir="/etc/sddm.conf.d"
|
2022-05-28 23:12:06 +02:00
|
|
|
local theme_dir="/usr/share/sddm/themes/aerial"
|
2022-05-27 21:07:07 +02:00
|
|
|
|
|
|
|
echo "Setting up '$sddm_config_dir'."
|
|
|
|
|
|
|
|
if ! [ -d "$sddm_config_dir" ]; then
|
|
|
|
sudo mkdir "$sddm_config_dir"
|
|
|
|
sudo chown root:root -R "$sddm_config_dir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
{
|
|
|
|
echo "[Theme]"
|
|
|
|
echo "Current=aerial"
|
|
|
|
} | sudo tee "$sddm_config_dir/theme" >/dev/null
|
|
|
|
|
|
|
|
{
|
|
|
|
echo "[X11]"
|
|
|
|
echo "DisplayCommand=/usr/share/sddm/scripts/Xsetup"
|
|
|
|
} | sudo tee "$sddm_config_dir/xsetup" >/dev/null
|
2022-05-28 23:12:06 +02:00
|
|
|
|
|
|
|
echo "Setting up '$theme_dir'."
|
|
|
|
mv "$theme_dir/theme.conf.user" "$theme_dir/theme.conf.user.disabled"
|
2022-05-27 21:07:07 +02:00
|
|
|
}
|
|
|
|
|
2022-05-28 22:43:08 +02:00
|
|
|
function prepare_arch() {
|
|
|
|
which pamac >/dev/null && return 0
|
|
|
|
sudo pacman -S pamac --noconfirm || return 1
|
|
|
|
}
|
|
|
|
|
2022-05-27 21:07:07 +02:00
|
|
|
function setup_arch_with_pamac() {
|
|
|
|
local targets=("pacman-any") packages
|
|
|
|
is_laptop && targets+=("pacman-laptop")
|
|
|
|
|
|
|
|
packages="$(get_packages "${targets[@]}")"
|
|
|
|
# shellcheck disable=SC2086
|
2022-05-28 22:43:08 +02:00
|
|
|
sudo pamac install $packages --no-confirm || return 1
|
2022-05-27 21:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup_arch_with_yay() {
|
|
|
|
local targets=("aur-any") packages
|
|
|
|
is_laptop && targets+=("aur-laptop")
|
|
|
|
|
2022-05-28 22:43:08 +02:00
|
|
|
for package in $(get_packages "${targets[@]}"); do
|
2022-05-27 21:07:07 +02:00
|
|
|
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
|
|
|
|
|
2022-05-28 22:43:08 +02:00
|
|
|
sudo pamac build "$package" --no-confirm || return 1
|
|
|
|
done
|
2022-05-27 21:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup_arch() {
|
2022-05-28 22:43:08 +02:00
|
|
|
prepare_arch || return 1
|
|
|
|
setup_arch_with_pamac || return 2
|
|
|
|
setup_arch_with_yay || return 3
|
|
|
|
configure_sddm || return 4
|
2022-05-27 21:07:07 +02:00
|
|
|
}
|
|
|
|
|
2022-05-28 22:43:08 +02:00
|
|
|
ID_LIKE="$(grep ID_LIKE= </etc/os-release | cut -d= -f2)"
|
|
|
|
|
|
|
|
echo "Setting up ${ID_LIKE^:?}-like OS."
|
2022-05-27 21:07:07 +02:00
|
|
|
|
|
|
|
if [[ "$ID_LIKE" == "arch" ]]; then
|
|
|
|
setup_arch
|
|
|
|
else
|
|
|
|
echo "ERROR: Unsupported system: ID_LIKE=$ID_LIKE"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Setup finished."
|