.dotfiles/utils/helpers.sh
tombdf 67a479973b
Update .chezmoiexternal.toml
Update README.md
Update .bashrc
Update .zshrc
Add .config/atuin/config.toml
Update scripts/shells.sh
Update utils/helpers.sh
Update utils/packages
2024-12-21 00:33:52 +01:00

119 lines
5.8 KiB
Bash

#!/bin/bash
# Check that the script is not run as root
function check_not_root() {
if [ "$(id -u)" -eq 0 ]; then
echo -e "${RED}[ERROR] This script shall not be executed as root${DEFAULT}" | tee -a "$LOG"
exit 1
fi
}
# Check that an internet connection is available
function check_internet() {
if ping -q -c 1 -W 1 archlinux.org >/dev/null; then
echo -e "${GREEN}Internet connection is available${DEFAULT}" | tee -a "$LOG"
else
echo -e "${RED}[ERROR] Internet connection is not available${DEFAULT}" | tee -a "$LOG"
exit 1
fi
}
# Check that the system is Arch Linux
function check_arch() {
if [ -f "/etc/arch-release" ]; then
echo -e "${GREEN}Arch Linux detected${DEFAULT}" | tee -a "$LOG"
else
echo -e "${RED}[ERROR] Arch Linux not detected${DEFAULT}" | tee -a "$LOG"
exit 1
fi
}
# Check that chezmoi is installed
function check_chezmoi() {
if ! command -v chezmoi &>/dev/null; then
echo -e "${RED}[ERROR] Chezmoi is not installed${DEFAULT}" | tee -a "$LOG"
exit 1
fi
}
# Secure installation of packages
function check_installation() {
local command=$1
local package=$2
echo -e "${BLUE}Installing $package...${DEFAULT}" | tee -a "$LOG"
if ! $command $package; then
echo -e "${RED}[ERROR] Installation of $package failed${DEFAULT}" | tee -a "$LOG"
return 1
fi
echo -e "${GREEN}$package installed successfully${DEFAULT}" | tee -a "$LOG"
return 0
}
# Final system configuration
function setup_final() {
echo -e "${BLUE}Performing final system configuration...${DEFAULT}" | tee -a "$LOG"
# Enable systemd services
systemctl --user enable --now pipewire.service
systemctl --user enable --now pipewire-pulse.service
# Enable Atuin
echo -e "${GREEN}Setting up Atuin...${DEFAULT}"
echo -e "${BLUE}Please enter your Atuin login${DEFAULT}"
read -p "Username: " atuin_user
atuin login -u $atuin_user
atuin sync
# Import GPG keys
gpg --import $HOME/.gpg/public-keys.asc
gpg --import $HOME/.gpg/private-keys.asc
gpg --update-trustdb
# Setting up Vim plugins
echo -e "${GREEN}Installing Vim plugins...${DEFAULT}"
vim -E -s -u "~/.vimrc" +PlugInstall +qall >/dev/null 2>&1
# Setting up NeoVim plugins
echo -e "${GREEN}Installing NeoVim plugins...${DEFAULT}"
nvim +Lazy +MasonInstallAll +MasonUpdate +180sleep +qall
# Clean up the system
echo -e "${BLUE}Cleaning up the system...${DEFAULT}" | tee -a "$LOG"
yay -Yc --noconfirm
}
# Display logo and information
function display_header() {
echo -e "${BLUE}"
cat <<"EOF"
▄█▄
▄███▄
▄█████▄ ██████ ██████ ████████ ███████ ██ ██ ███████ ███████
▄███████▄ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
▄ ▀▀██████▄ ██ ██ ██ ██ ██ █████ ██ ██ █████ ███████
▄██▄▄ ▀█████▄ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
▄█████████████▄ ██ ██████ ██████ ██ ██ ██ ███████ ███████ ███████
▄███████████████▄
▄█████████████████▄
▄███████████████████▄ ┌───────────────────────────────────────────────────────────┐
▄█████████▀▀▀▀████████▄ │ │
▄████████▀ ▀███████▄ │ • "Welcome to the Arch Linux DotFiles Setup Script!"
▄█████████ ████▀▀██▄ │ │
▄██████████ █████▄▄▄ │ • Created by Thomas Brasdefer │
▄██████████▀ ▀█████████▄ │ • Find me at hexasec.io or gitea.hexasec.io/tombdf │
▄██████▀▀▀ ▀▀██████▄ │ for more. │
▄███▀▀ ▀▀███▄ └───────────────────────────────────────────────────────────┘
▄▀▀ ▀▀▄
Notes.
- Operation on non-Arch Linux based is not guaranteed.
- NVIDIA GPUs are supported.
- Do not run this script as root.
- Do NOT interrupt the script, it will end by itself.
EOF
echo -e "${DEFAULT}"
}