Write boilerplate shell for managing Arch packages

This commit is contained in:
Alicia Sykes 2022-09-25 23:07:53 +01:00
parent 7d0eaabe49
commit 24fe1beffd

View File

@ -1,48 +1,99 @@
#!/usr/bin/env bash
# List of packages to be installed on Arch-based systems
# Desktop apps installed via Flatpak, PKGBUILDs via Pacman
# Apps are sorted by category, and arranged alphabetically
# Be sure to delete / comment out anything you do not need
set -e
###############################################################
# Installs listed packages on Arch-based systems via Pacman #
# Doesn't include desktop apps, that're managed via Flatpak #
# Apps are sorted by category, and arranged alphabetically #
# Be sure to delete / comment out anything you do not need #
# For more info, see: https://wiki.archlinux.org/title/Pacman #
###############################################################
# MIT Licensed (C) Alicia Sykes 2022 <https://aliciasykes.com>#
###############################################################
# Apps to be installed via Pacman
pacman_apps=(
# Apps
# Development
# Utils
# Security Utils
# Netowking
)
# Colors
CYAN_B='\033[1;96m'
YELLOW_B='\033[1;93m'
RED_B='\033[1;31m'
GREEN_B='\033[1;32m'
YELLOW='\033[0;93m'
RESET='\033[0m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
LIGHT='\x1b[2m'
echo "${CYAN_B}Installing Arch Packages...${RESET}"
PROMPT_TIMEOUT=15 # When user is prompted for input, skip after x seconds
# Pacman
if hash pacman 2> /dev/null; then
for app in ${pacman_apps[@]}; do
# If pacman -Qk ${app}
# And If: flatpak list --columns=ref | grep 'ch.protonmail.protonmail-bridge'
pacman -S ${app}
done
else
echo "${YELLOW_B}Pacman not present, skipping${RESET}"
# Print intro message
echo -e "${PURPLE}Starting Arch app install / update script"
echo -e "${LIGHT}The following script is for Arch / Arch-based headless systems, and will"
echo -e "update database, upgrade packages, clear cache then install all listed CLI apps."
echo -e "${YELLOW}Before proceeding, ensure your happy with all the packages listed in \e[4m${0##*/}"
echo -e "${RESET}"
# Check if running as root, and prompt for password if not
if [ "$EUID" -ne 0 ]; then
echo -e "${PURPLE}Elevated permissions are required to adjust system settings."
echo -e "${CYAN_B}Please enter your password...${RESET}"
sudo -v
if [ $? -eq 1 ]; then
echo -e "${YELLOW}Exiting, as not being run as sudo${RESET}"
exit 1
fi
fi
# Check pacman actually installed
if ! hash pacman 2> /dev/null; then
echo "${YELLOW_B}Pacman doesn't seem to be present on your system. Exiting...${RESET}"
exit 1
fi
# Prompt user to update package database
echo -e "${CYAN_B}Would you like to update package database? (y/N)${RESET}\n"
read -t $PROMPT_TIMEOUT -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${PURPLE}Updating dadatbase...${RESET}"
sudo pacman -Syy --noconfirm
fi
# Prompt user to upgrade currently installed packages
echo -e "${CYAN_B}Would you like to upgrade currently installed packages? (y/N)${RESET}\n"
read -t $PROMPT_TIMEOUT -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${PURPLE}Upgrading installed packages...${RESET}"
sudo pacman -Syu --noconfirm
fi
# Prompt user to clear old package caches
echo -e "${CYAN_B}Would you like to clear unused package caches? (y/N)${RESET}\n"
read -t $PROMPT_TIMEOUT -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${PURPLE}Freeing up disk space...${RESET}"
sudo pacman -Sc --noconfirm
fi
# Prompt user to install all listed apps
echo -e "${CYAN_B}Would you like to install listed apps? (y/N)${RESET}\n"
read -t $PROMPT_TIMEOUT -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${PURPLE}Starting install...${RESET}"
for app in ${pacman_apps[@]}; do
if hash "${app}" 2> /dev/null; then
echo -e "${YELLOW}[Skipping]${LIGHT} ${app} is already installed${RESET}"
elif hash flatpak 2> /dev/null && [[ ! -z $(echo $(flatpak list --columns=ref | grep $app)) ]]; then
echo -e "${YELLOW}[Skipping]${LIGHT} ${app} is already installed via Flatpak${RESET}"
else
echo -e "${PURPLE}[Installing]${LIGHT} Downloading ${app}...${RESET}"
# pacman -S ${app} --noconfirm
fi
done
fi
echo -e "${PURPLE}Finished installing / updating Arch packages.${RESET}"