Haciendo mas facil el distrohop :D

Después de haberme estrellado con un muro llamado Slackware, me dispuse a terminar un script que había empezado ayer por la tarde, justo antes del desastre…
Se me vino a la mente la brillante idea (ya sé que es común delegarle esta tarea a Bash) de hacer un script para automatizar un par de cosas con las que perdía, no sé, quizá unos 15 minutos cada vez que cambio de distribución de Linux~

NOTAS:

  • Solo lo he probado en Void GNU/Linux.
  • El nombre de los paquetes puede variar en otras distros

Puedes enviar parches aca :DD

#!/bin/bash
set -e

# Script to set some basic things for a GNU/Linux distro
# "$1" will be the package manager of the distribution

if [[ "$#" -ne 1 ]]; then # validates arguments
    echo -e "Usage \n
    	    $./savannah.sh <pkg manager>.
	    \n For example: xbps, apt, pacman"
    exit 1
fi

declare -a programs=(
    "git"
    "mpv"
    "ffmpeg"
    "emacs-gtk3"
    "shellcheck"
    "telegram-desktop"
)

declare -a zh_input=(
    "fcitx5"
    "fcitx5-configtool"
    "fcitx5-chinese-addons"
    "noto-fonts-cjk"
    "wqy-microhei"
    # Something extra?
)

declare -a not_installed=()

check_packages() {
    for pkg in "${programs[@]}"; do
        if command -v "$pkg" >/dev/null 2>&1
	then
	    echo "$pkg" is installed
	else
	    not_installed+=("$pkg")
	fi
    done
    if ! command -v "fcitx" >/dev/null 2>&1
    then
	not_installed+=("${zh_input[@]}")
    fi

}

adcmd="sudo" # admin command
define_admin_command() {
    if ! command -v sudo >/dev/null 2>&1
    then
	adcmd="doas"
    fi
}

define_admin_command # Check admin command before the installation
install_packages() {
    # switch case that depends on the first argument
    case "$1" in
	"xbps")
	    "$adcmd" xbps-install -Sy "${not_installed[@]}"
	    ;;
	"apt")
	     "$adcmd" apt install -y "${not_installed[@]}"
	    ;;
	"pacman")
	     "$adcmd" pacman -S --noconfirm "${not_installed[@]}"
	    ;;
	*)
	    echo "pkg manager not supported: $1"
    esac
}

fcitx_env_setup() {
    mkdir -pv ~/.config/autostart
    cp /etc/xdg/autostart/org.fcitx.Fcitx5.desktop .config/autostart
    # Add necessary variables to /etc/environment to set the input method modules
    echo -e "export GTK_IM_MODULE=fcitx\nexport QT_IM_MODULE=fcitx\nexport XMODIFIERS=@im=fcitx" | "$adcmd" tee -a /etc/environment
}

emacs_config="$HOME/.emacs.d"
build_church() {
    echo -e "\n This will bomb your current church ~/.emacs.d"
    read -r -p "Do you want to proceed? [y/N] " -n 1
    echo
    if [[ "$REPLY" =~ ^[Yy]$ ]]; then
	rm -rf "$emacs_config"
	git clone https://codeberg.org/aisak/.emacs.d.git "$emacs_config"
    else
	echo "Aborted"
    fi
}

install_holy_font() {
    echo -e "\n Cloning Aporetic font"
	git clone --depth 1 https://github.com/protesilaos/aporetic ~/.local/share/fonts
	rm ~/.local/share/fonts/{LICENSE.md,README.md,private-build-plans.toml}
}

# func calls
check_packages
install_packages "$1"
build_church
install_holy_font
fcitx_env_setup

echo -e "\n ALL DONE! \n"
5 Me gusta