#!/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' USERNAME=$(logname) 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." exit 1 fi # Yes, this is always true, but anyway. return 0 } # 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 # Needs to be this funky to avoid fetching ase, base-devel, and filesystem. # For some reason, pacman -Qqs "manjaro" will do that. log "Checking for soon-to-be Manjaro orphans..." deps_remove=( $(pacman -Qqs "manjaro-") $(pacman -Qqs "\-manjaro") $(pacman -Qqs "\-breath") pacman-mirrors ) printf "Found:\n${deps_remove[@]}\n" log "Checking for Pamac..." deps_pamac=$(pacman -Qqs pamac) deps_remove+=($deps_pamac) printf "Found:\n${deps_pamac[@]}\n" log "Checking for mhwd..." deps_mhwd=$(pacman -Qqs mhwd) deps_remove+=($deps_mhwd) printf "Found:\n${deps_mhwd[@]}\n" log "Checking additional installs and package migrations..." deps_install=() prompt_bool "Install proton-cachyos-slr?" true if [[ $? ]]; then deps_install+=("proton-cachyos-slr") fi prompt_bool "Install protonup-qt?" true if [[ $? ]]; then deps_install+=("protonup-qt") fi log "Checking for KDE..." if [[ $(echo $XDG_CURRENT_DESKTOP | grep -i "kde") ]]; then # Default to not changing because it doesn't work for shit on # either of the systems I've tried it on. prompt_bool "Replace sddm with plasma-login-manager?" false if [[ $? ]]; then deps_install+=("plasma-login-manager") deps_remove+=("sddm") deps_remove+=("sddm-kcm") fi fi log "Checking for Octopi..." if ! is_installed octopi; then prompt_bool "Install Octopi (to replace Pamac)?" true if [[ $? ]]; then deps_install+=("octopi") fi fi log "Removing old packages and Manjaro orphans..." pacman -Rdd "${deps_remove[@]}" 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 "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[@]} chwd --autoconfigure if [[ $(is_installed plasmalogin) && $(systemctl is-enabled sddm) ]]; then systemctl disable sddm systemctl enable plasmalogin fi 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."