#!/bin/bash # purpose: this scripts purpose is to get sourced by other scripts it'll be served online at https://scripts.flouda.net/base # it should be sourced like this: source <(curl -fsSL https://scripts.flouda.net/base) # color definitions BLUE='\033[0;34m' GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m' RESET='\033[0m' function debug() { echo -e "${BLUE}[DEBUG]${RESET} $1" } function info() { echo -e "${GREEN}[INFO]${RESET} $1" } function warning() { echo -e "${YELLOW}[WARNING]${RESET} $1" } function error() { echo -e "${RED}[ERROR]${RESET} $1" } function check_command_availability() { local command=$1 if ! command -v $command &> /dev/null; then error "$command not found" return 1 fi debug "$command found" } function check_arch_based_system() { if ! grep -q "Arch Linux" /etc/os-release; then error "This script is designed for Arch Linux and requires Arch Linux." exit 1 fi debug "Arch Linux based system detected" } function ensure_yay() { check_command_availability "yay" if [[ $? -ne 0 ]]; then warning "yay not found, installing..." check_user_privileges if [[ $? -ne 0 ]]; then error "You don't have sudo privileges to install yay" return 1 fi sudo pacman -Sy --noconfirm --needed git wget base-devel git clone https://aur.archlinux.org/yay.git /tmp/yay cd /tmp/yay makepkg -si --noconfirm cd - rm -rf /tmp/yay else debug "yay found" fi debug "yay installed" } function check_user_privileges() { if [[ $EUID -eq 0 ]]; then error "This script should not be run as root or using sudo!" exit 1 fi if ! sudo -i true 2>/dev/null; then error "You don't have sudo privileges. Please run this script with a user that has sudo access." exit 1 fi debug "User privileges checked" } function set_nopasswd() { echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/nopasswd > /dev/null debug "NOPASSWD set for $USER" trap 'remove_nopasswd' EXIT } function remove_nopasswd() { sudo rm /etc/sudoers.d/nopasswd debug "NOPASSWD removed" } function ask_for_confirmation() { local message=$1 read -p "$message [Y/n] : " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ || $REPLY == "" ]]; then return 0 else return 1 fi } function reboot_prompt() { if ! ask_for_confirmation "Your system will reboot in 5 seconds. Are you sure you want to reboot?"; then return 1 fi echo -e "${RED}Your system will reboot in 5 seconds.${RESET}" for i in {5..1}; do echo -ne "${YELLOW}Rebooting in ${i} seconds...\r" sleep 1 done echo -e "\n${RED}Rebooting now...${RESET}" sudo reboot } function ensure_packages() { local packages=$@ yay -Sy --noconfirm --needed $packages if [[ $? -ne 0 ]]; then error "Failed to install packages: $packages" return 1 fi debug "Packages installed: $packages" }