214 lines
5.1 KiB
Bash
Executable File
214 lines
5.1 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
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"
|
|
)
|
|
|
|
RED="\e[31m"
|
|
GREEN="\e[32m"
|
|
ERASE='\033[0m'
|
|
|
|
run_unprivileged() {
|
|
sudo -u "$USERNAME" "$@"
|
|
}
|
|
|
|
is_installed() {
|
|
which "$1" > /dev/null
|
|
[ $? -eq 0 ]
|
|
return $?
|
|
}
|
|
|
|
assert() {
|
|
if ! $1; then
|
|
echo "Script depends on $2 to function, please resolve manually."
|
|
fi
|
|
|
|
# Yes, this is always true, but anyway.
|
|
return $1
|
|
}
|
|
|
|
# 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 -ne "$1 $options: "
|
|
read -r tmp
|
|
tmp=${tmp:-${default}}
|
|
|
|
[[ "$tmp" =~ ^[yY]$ ]]
|
|
return $?
|
|
}
|
|
|
|
log() {
|
|
echo -e "${GREEN}[INFO] $1$ERASE"
|
|
}
|
|
|
|
if [[ $(id -u) > 0 ]]; then
|
|
echo -e "${RED}[ERROR] Script requires elevated permissions.${ERASE}"
|
|
exit 1
|
|
fi
|
|
|
|
log "Checking for reflector..."
|
|
if ! is_installed reflector; then
|
|
pacman -S yay
|
|
assert $(is_installed yay) "yay"
|
|
|
|
run_unprivileged yay -S reflector
|
|
assert $(is_installed reflector) "reflector"
|
|
fi
|
|
|
|
# REPOS
|
|
# Install CachyOS Repos
|
|
# See: https://wiki.cachyos.org/features/optimized_repos/#adding-our-repositories-to-an-existing-arch-linux-install
|
|
log "Installing CachyOS repos..."
|
|
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
|
|
log "Backing up Manjaro mirrorlist..."
|
|
mv "$DEFAULT_MIRRORLIST" "$DEFAULT_MIRRORLIST.bak"
|
|
|
|
# Install Arch Repos
|
|
log "Installing Arch Linux repos..."
|
|
curl -o "$DEFAULT_MIRRORLIST" "https://archlinux.org/mirrorlist/all/"
|
|
|
|
log "Refreshing Arch mirrors..."
|
|
reflector\
|
|
--fastest "32"\
|
|
--protocol "https"\
|
|
--sort "rate"\
|
|
--save "$DEFAULT_MIRRORLIST"
|
|
pacman -Syy
|
|
|
|
log "Checking for chwd..."
|
|
if ! is_installed chwd; then
|
|
pacman -Sdd chwd
|
|
assert $(is_installed chwd) "chwd"
|
|
fi
|
|
|
|
# INSTALL NEW KERNEL(S)
|
|
log "Installing new kernel(s)..."
|
|
# List available kernels
|
|
for idx in "${!KNOWN_KERNELS[@]}"; do
|
|
printf "%s\t%s\n" "$idx" "${KNOWN_KERNELS[$idx]}"
|
|
done
|
|
|
|
echo
|
|
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
|
|
readarray -td, kernels <<< "$tmp,"
|
|
unset 'kernels[-1]'
|
|
declare -p kernels
|
|
|
|
tmp=()
|
|
for idx in "${kernels[@]}"; do
|
|
if [[ $idx != 0 ]]; then
|
|
tmp+=("${KNOWN_KERNELS[$idx]}")
|
|
fi
|
|
done
|
|
kernels=(${tmp[@]})
|
|
else
|
|
kernels="$DEFAULT_KERNEL"
|
|
fi
|
|
|
|
# TODO: Install kernels
|
|
log "Installing desired kernels..."
|
|
if [[ ${#kernels} != 0 ]]; then
|
|
pacman -S --noconfirm ${kernels[@]}
|
|
else
|
|
echo "No new kernels, skipping."
|
|
fi
|
|
|
|
log "Running additional installs, package migrations, and orphan removals..."
|
|
deps_install=(
|
|
"protonup-qt"
|
|
"proton-cachyos-slr"
|
|
)
|
|
deps_remove=(
|
|
"manjaro-release"
|
|
"mhwd"
|
|
)
|
|
|
|
log "Checking for KDE..."
|
|
if [[ $(echo $XDG_CURRENT_DESKTOP | grep -i "kde") ]]; then
|
|
prompt_bool "Replace sddm with plasma-login-manager?" true
|
|
if [[ $? ]]; then
|
|
deps_install+=("plasma-login-manager")
|
|
deps_remove+=("sddm")
|
|
deps_remove+=("sddm-kcm")
|
|
fi
|
|
fi
|
|
|
|
log "Checking for Pamac..."
|
|
if [[ $(is_installed pamac-manager) || $(is_installed pamac) ]]; then
|
|
prompt_bool "Uninstall Pamac?" true
|
|
if [[ $? ]]; then
|
|
# TODO: Uninstall pamac deps.
|
|
echo -n
|
|
fi
|
|
fi
|
|
|
|
log "Removing old packages and Manjaro orphans..."
|
|
pacman -R ${deps_remove[@]}
|
|
|
|
log "Fetching all system packages to replace with CachyOS+Arch packages..."
|
|
# Credit to https://insrt.uk/post/pacman-reinstall for this solution.
|
|
deps_install+=($(comm -12 <(pacman -Slq | sort -u) <(pacman -Qq | sort -u)))
|
|
|
|
log "Installing new packages..."
|
|
pacman -Sdd ${deps_install[@]}
|
|
|
|
log "Done."
|
|
echo "Quick reminder: Be prepared to fix things!"
|
|
echo "Many orphaned packages will still exist on the system, and should be"
|
|
echo "removed to reduce the system's attack surface. This may also prevent"
|
|
echo "issues down the line due to incompatibilities between CachyOS+Arch and"
|
|
echo "various Manjaro hacks."
|
|
echo
|
|
echo "It is recommended to install Octopi and look for packages prefixed with"
|
|
echo "'manjaro-' and remove them. Also check packages which have fallen back"
|
|
echo "to being sourced from the AUR."
|