228 lines
4.7 KiB
Bash
228 lines
4.7 KiB
Bash
RED="\e[31m"
|
|
GREEN="\e[32m"
|
|
|
|
DEFAULT_MIRRORLIST="/etc/pacman.d/mirrorlist"
|
|
DEFAULT_KERNEL="linux-cachyos"
|
|
PROPAGATE_MANJARO="Keep all currently installed Manjaro kernels"
|
|
|
|
# yes, they're hard-coded. For now at least.
|
|
KNOWN_KERNELS=(
|
|
"$PROPAGATE_MANJARO",
|
|
"linux",
|
|
"linux-lts",
|
|
"linux-hardened",
|
|
"linux-rt",
|
|
"linux-cachyos",
|
|
"linux-cachyos-lts",
|
|
"linux-cachyos-hardened",
|
|
"linux-cachyos-bore",
|
|
"linux-cachyos-eevdf",
|
|
"linux-cachyos-bmq",
|
|
"linux-cachyos-deckify",
|
|
"linux-cachyos-rc",
|
|
"linux-cachyos-rt-bore",
|
|
"linux-cachyos-server",
|
|
"linux-zen"
|
|
#"linux-cachyos-cacule",
|
|
#"linux-cachyos-debug",
|
|
#"linux-cachyos-gcc",
|
|
)
|
|
|
|
assert() {
|
|
if ! $1; then
|
|
echo "Script depends on $2 to function, please resolve manually."
|
|
fi
|
|
|
|
# Yes, this is always true, but anyway.
|
|
return $1
|
|
}
|
|
|
|
is_installed() {
|
|
return ! which "$1" > /dev/null
|
|
}
|
|
|
|
run_unprivileged() {
|
|
sudo -u "$USERNAME" "$@"
|
|
}
|
|
|
|
log() {
|
|
if "$1"; then
|
|
echo -e "$2...${GREEN}yes $3"
|
|
else
|
|
echo -e "$2...${RED}no"
|
|
fi
|
|
}
|
|
|
|
# Credit to NaN on StackOverflow for this solution.
|
|
# https://stackoverflow.com/questions/29436275/how-to-prompt-for-yes-or-no-in-bash
|
|
prompt_bool() {
|
|
if $2; then
|
|
options="[Y/n]"
|
|
default="y"
|
|
else
|
|
options="[y/N]"
|
|
default="n"
|
|
fi
|
|
|
|
echo -n "$1 $options"
|
|
read -r tmp
|
|
tmp=${tmp:-${default}}
|
|
|
|
if [[ "$tmp" =~ ^[yY]$ ]]; then
|
|
return true
|
|
else
|
|
return false
|
|
fi
|
|
}
|
|
|
|
# CHECKS
|
|
if ! $?; then
|
|
echo "Script must be run with elevated permissions."
|
|
exit 1
|
|
fi
|
|
|
|
refresh_checks() {
|
|
[ $(id -u) = 0 ]
|
|
ROOT_PERMS=$?
|
|
log $ROOT_PERMS "root_perms"
|
|
|
|
LSPCI=$(is_installed lspci)
|
|
log $LSPCI "lspci"
|
|
|
|
PACMAN=$(is_installed pacman)
|
|
log $PACMAN "pacman"
|
|
|
|
MHWD_KERNEL=$(is_installed mhwd-kernel)
|
|
log $MHWD_KERNEL "mhwd-kernel"
|
|
|
|
SUDO=$(is_installed sudo)
|
|
log $SUDO "sudo"
|
|
|
|
CURL=$(is_installed curl)
|
|
log $CURL "curl"
|
|
|
|
REFLECTOR=$(is_installed reflector)
|
|
log $REFLECTOR "reflector"
|
|
|
|
YAY=$(is_installed yay)
|
|
log $YAY "yay"
|
|
|
|
USERNAME=$(logname)
|
|
log $? "unprivileged_user" $USERNAME
|
|
|
|
# Identify installed Manjaro kernels
|
|
re="linux\d+"
|
|
mhwd_dump=$(mhwd-kernel -li | grep "linux")
|
|
|
|
ACTIVE_KERNEL=$(echo "$mhwd_dump" | grep "running" | grep -Po "$re" )
|
|
[ ${#ACTIVE_KERNEL} > 0 ]
|
|
log $? "active_kernel" $ACTIVE_KERNEL
|
|
|
|
ALTERNATE_KERNELS=$(echo "$mhwd_dump" | grep -Po "$re" | grep -v "$ACTIVE_KERNEL")
|
|
[ ${#ALTERNATE_KERNELS} > 0 ]
|
|
log $? "alternate_kernels"
|
|
}
|
|
|
|
refresh_checks
|
|
|
|
assert $ROOT_PERMS "elevated permissions"
|
|
assert $LSPCI "lspci"
|
|
assert $PACMAN "pacman"
|
|
assert $MHWD_KERNEL "mhwd-kernel"
|
|
assert $SUDO "sudo"
|
|
|
|
# Attempt to recover from failing checks
|
|
deps=()
|
|
|
|
if ! $YAY; then
|
|
deps+=("yay")
|
|
fi
|
|
|
|
if ! $CURL; then
|
|
deps+=("curl")
|
|
fi
|
|
|
|
if [[ ${#deps} > 0 ]]; then
|
|
pacman -Syy "${deps[@]}"
|
|
fi
|
|
|
|
if ! $REFLECTOR; then
|
|
run_unprivileged yay -Syy "${deps[@]}"
|
|
fi
|
|
|
|
refresh_checks
|
|
|
|
assert $CURL "curl"
|
|
assert $REFLECTOR "reflector"
|
|
|
|
# OPTIONAL OPERATIONS
|
|
prompt_bool "Remove all kernels (excepting active)?" true
|
|
if $?; then
|
|
# Remove alternate kernels
|
|
# mhwd?
|
|
fi
|
|
|
|
# REPOS
|
|
# Install CachyOS Repos
|
|
# See: https://wiki.cachyos.org/features/optimized_repos/#adding-our-repositories-to-an-existing-arch-linux-install
|
|
cd $(mktemp -d)
|
|
curl https://mirror.cachyos.org/cachyos-repo.tar.xz -o cachyos-repo.tar.xz
|
|
tar xvf cachyos-repo.tar.xz
|
|
cd cachyos-repo
|
|
|
|
# Just in case, ensure the script can be executed.
|
|
if [[ ! -x "cachyos-repo.sh" ]]; then
|
|
chmod +x cachyos-repo.sh
|
|
fi
|
|
|
|
./cachyos-repo.sh
|
|
|
|
# Backup Manjaro Repos
|
|
mv "$DEFAULT_MIRRORLIST" "$DEFAULT_MIRRORLIST.bak"
|
|
|
|
# Install Arch Repos
|
|
curl -o "$DEFAULT_MIRRORLIST" "https://archlinux.org/mirrorlist/all/"
|
|
reflector\
|
|
--fastest "32"\
|
|
--protocol "https"\
|
|
--sort "rate"\
|
|
--country "CA,NZ,DE,NL,PL,SE"\
|
|
--save "$DEFAULT_MIRRORLIST"
|
|
pacman -Syy
|
|
|
|
if ! is_installed chwd; then
|
|
pacman -S chwd
|
|
assert $(is_installed chwd) "chwd"
|
|
fi
|
|
|
|
# INSTALL NEW KERNEL(S)
|
|
|
|
# List available kernels
|
|
for idx in "${!KNOWN_KERNELS[@]}"; do
|
|
printf "%s\t%s\n" "$idx" "${KNOWN_KERNELS[$idx]}"
|
|
done
|
|
|
|
echo -n "Kernel(s): "
|
|
read -r tmp
|
|
|
|
if [[ ${#tmp} > 0 ]]; then
|
|
# Credit to bgoldst on StackOverflow for this solution.
|
|
# https://stackoverflow.com/questions/10586153/how-to-split-a-string-into-an-array-in-bash
|
|
kernels=$(readarray -td, a <<< "$tmp,"; unset 'a[-1]'; declare -p a)
|
|
else
|
|
kernels="$DEFAULT_KERNEL"
|
|
fi
|
|
|
|
# TODO: Install kernels
|
|
|
|
# Handle propagations
|
|
# DKMS propagations
|
|
# Nvidia drivers migration from DKMS to -nvidia-open
|
|
# Arch and Zen kernels?
|
|
chwd --autoconfigure
|
|
|
|
# Kill Orphans
|
|
# DKMS && !PROPAGATE_DKMS, but maybe CHWD will remove the need for this???
|
|
# MHWD
|
|
# Pamac
|