fixes/after.sh
Baltrust dc3bbcff0f Add speed
speedtest and the result with image in terminal with chafa by running speed
2026-10-28 22:59:51 +02:00

223 lines
No EOL
8.1 KiB
Bash

#!/bin/bash
set -e
#read -rp "Enter your username: " USERNAME
# Detect the normal user created by archinstall
USERNAME=$(awk -F: '$3 >= 1000 && $3 < 60000 && $6 ~ /^\/home\// {print $1; exit}' /etc/passwd)
# Error in case there is no normal user created
[[ -z "$USERNAME" ]] && { echo "Error: Could not detect the normal user."; exit 1; }
USER_HOME="/home/$USERNAME"
# ─────────────────────────────────────
# Temporarily enable passwordless sudo
# ─────────────────────────────────────
install -m 440 /dev/stdin "/etc/sudoers.d/00_$USERNAME" <<< "$USERNAME ALL=(ALL:ALL) NOPASSWD: ALL"
visudo -c
# ─────────────────────────────────────
# Misc
# ─────────────────────────────────────
# PACMAN LOVES CANDY
sed -i '/^# Misc options/a ILoveCandy' /etc/pacman.conf
# DISABLE KWALLETD
mkdir -p "$USER_HOME/.config"
cat > "$USER_HOME/.config/kwalletrc" <<'EOF'
[Wallet]
Enabled=false
EOF
# ENABLE DOLPHIN STORAGE INFO
kwriteconfig6 --file "$USER_HOME/.config/dolphinrc" --group General --key ShowStatusBar FullWidth
# CONFIGURE KEYBOARD LAYOUTS
cat > "$USER_HOME/.config/kxkbrc" <<'EOF'
[Layout]
DisplayNames=,
LayoutList=us,lt
Use=true
VariantList=,
EOF
# SWITCH KDE TO DARK MODE
kwriteconfig6 --file "$USER_HOME/.config/kdeglobals" --group General --key ColorScheme BreezeDark
# ADD DAC CONFIGURATOR TO LOCAL BINARIES FOLDER
su - "$USERNAME" <<'EOF'
mkdir -p ~/.local/bin
curl -fsSL https://git.baltrust.eu.org/Baltrust/fixes/raw/branch/main/dac-config -o ~/.local/bin/dac-config
chmod +x ~/.local/bin/dac-config
EOF
# ─────────────────────────────────────
# Install yay
# ─────────────────────────────────────
install -d -o "$USERNAME" -g "$USERNAME" "/home/$USERNAME/.config/yay"
su - "$USERNAME" <<'EOF'
git clone https://aur.archlinux.org/yay-bin.git
cd yay-bin && makepkg -si --noconfirm
cd "$OLDPWD" && rm -rf yay-bin
# Set up yay to not ask for password multiple times during installation / upgrading later
yay --sudoloop --save
# Instal AUR packages
yay -S --needed --noconfirm --removemake zsh-theme-powerlevel10k ttf-meslo-nerd-font-powerlevel10k coolercontrol-bin \
mangojuice-bin heroic-games-launcher-bin polymc-qt5-bin open-video-downloader-bin brave-bin onlyoffice-bin \
zenpower5-dkms-git zenergy-dkms-git game-devices-udev
EOF
# ─────────────────────────────────────
# Configure Konsole
# ─────────────────────────────────────
mkdir -p "$USER_HOME/.local/share/konsole"
cat > "$USER_HOME/.local/share/konsole/ZSH_Profile.profile" <<'EOF'
[Appearance]
Font=MesloLGS NF,10,-1,5,400,0,0,0,0,0,0,0,0,0,0,1,,0,0
[Cursor Options]
CursorShape=1
[General]
Name=ZSH Profile
Parent=FALLBACK/
[Terminal Features]
AnimatingCursorEnabled=true
BlinkingCursorEnabled=true
EOF
# Set the profile as default
kwriteconfig6 --file "$USER_HOME/.config/konsolerc" --group "Desktop Entry" --key "DefaultProfile" "ZSH_Profile.profile"
# ─────────────────────────────────────
# ZSH
# ─────────────────────────────────────
chsh -s /bin/zsh "$USERNAME"
cat > "$USER_HOME/.zshrc" <<'EOF'
# ─────────────────────────────────────
# Local binaries path
# ─────────────────────────────────────
export PATH="$HOME/.local/bin:$PATH"
# ─────────────────────────────────────
# Powerlevel10k
# ─────────────────────────────────────
source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme
# ─────────────────────────────────────
# Plugins
# ─────────────────────────────────────
# Autosuggestions
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
# Syntax highlighting
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# ─────────────────────────────────────
# Powerlevel10k configuration
# ─────────────────────────────────────
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# ─────────────────────────────────────
# Completion
# ─────────────────────────────────────
autoload -Uz compinit
compinit
setopt CORRECT
setopt AUTO_CD
zstyle ':completion:*' completer _complete _approximate
zstyle ':completion:*' menu select
# ─────────────────────────────────────
# History
# ─────────────────────────────────────
HISTFILE="$HOME/.zsh_history"
SAVEHIST=10000
setopt APPEND_HISTORY
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
# ─────────────────────────────────────
# Manual to pdf
# ─────────────────────────────────────
manual() {
local pdf=$(mktemp --suffix=.pdf) || return 1
man -Tpdf "$1" > "$pdf" 2>/dev/null || { rm -f "$pdf"; echo "No manual entry for $1"; return 1; }
okular "$pdf"
rm -f "$pdf"
}
speed() {
local output url exit_code
output=$(mktemp) || return # Create temporary file
script -q -c 'speedtest -A' /dev/null | tee "$output" # Run speedtest and save output
exit_code=$? # Save exit status
url=$(awk '/Result URL:/ {print $NF ".png"; exit}' "$output" | tr -d '\r') # Extract result image URL
rm -f "$output" # Remove temporary file
[[ $exit_code -eq 0 && -n $url ]] && curl -sL --compressed "$url" | chafa - # Display result image
return "$exit_code" # Return exit status
}
EOF
# Make everything we created belong to the user
chown -R "$USERNAME:$USERNAME" "$USER_HOME"
# ─────────────────────────────────────
# Grub
# ─────────────────────────────────────
# Enable windblows / other OS detection
sed -i 's/^#\?GRUB_DISABLE_OS_PROBER=.*/GRUB_DISABLE_OS_PROBER=false/' /etc/default/grub
# Install grub theme
su - "$USERNAME" <<'EOF'
curl -O https://git.baltrust.eu.org/Baltrust/fixes/raw/branch/main/Graphite-grub2-theme.tar.xz
tar -xf Graphite-grub2-theme.tar.xz && rm Graphite-grub2-theme.tar.xz
cd grub2 && ./install.sh
cd "$OLDPWD" && rm -rf grub2
EOF
# ─────────────────────────────────────
# Restore password requirement after successful installation
# ─────────────────────────────────────
install -m 440 /dev/stdin "/etc/sudoers.d/00_$USERNAME" <<< "$USERNAME ALL=(ALL) ALL"
visudo -c
# ─────────────────────────────────────
# Remove the script from root folder after successfull installation and exit
# ─────────────────────────────────────
rm -f after.sh
exit 0