Files
Compose-Files/Backups/Miker/Bookstack/scripts.md
T
2026-07-20 09:23:17 -04:00

17 KiB

tags
tags
Documentation
Bookstack
Notes

Scripts

Universal Linux install script

You nailed it! That is exactly how everything pieces together.

I see only two very minor things in the final version you pasted that could use a quick tweak before you run it live:

  1. The Leftover Note: At the bottom of your Arch section, you still have the old echo lines saying "Note: AirVPN (eddie-ui) requires the AUR... install it later via: yay -S eddie-ui". Since the script now installs yay and runs that command automatically right above it, you can safely remove those lines so it doesn't give you a confusing warning.
  2. set -e Risk with Flatpak: At the very top, we have set -e enabled, which forces the script to crash and stop if any command fails. Flatpak can sometimes return a non-zero exit code if an application is already installed or partially skips. To prevent the script from stopping right at the very end over a harmless Flatpak message, we can append || true to the flatpak command.

Here is the 100% clean, finalized version ready for your /usr/local/bin or dotfiles repository:

Bash
``` #!/bin/sh set -e # Exit immediately if a command exits with a non-zero status

1. OS DETECTION & VARIABLES

CURRENT_USER=$(whoami) USER_HOME="/home/$CURRENT_USER"

if [ -f /etc/os-release ]; then . /etc/os-release DISTRO_NAME=$ID else echo "Cannot determine OS distribution. /etc/os-release missing." exit 1 fi

echo "Starting deployment script for user: $CURRENT_USER on $DISTRO_NAME"

2. SHARED TASKS (Runs on both systems)

echo "-----------------------------------------------" echo "Resetting SSH directory permissions..." echo "-----------------------------------------------" if [ -d "$USER_HOME/.ssh" ]; then chmod 700 "$USER_HOME/.ssh" if ls "$USER_HOME/.ssh"/.pub > /dev/null 2>&1; then chmod 644 "$USER_HOME/.ssh"/.pub fi if [ -f "$USER_HOME/.ssh/id_rsa" ]; then chmod 600 "$USER_HOME/.ssh/id_rsa" fi fi

3. DISTRO SPECIFIC APPLICATIONS

if [ "$DISTRO_NAME" = "ubuntu" ] || [ "$DISTRO_NAME" = "debian" ]; then echo "-----------------------------------------------" echo "Running Ubuntu/Debian Setup Tasks" echo "-----------------------------------------------"

# Prerequisite updates
sudo apt update && sudo apt install -y curl wget git gpg software-properties-common ca-certificates

# AirVPN Eddie repository
curl -fsSL https://eddie.website/repository/keys/eddie_maintainer_gpg.key | sudo tee /usr/share/keyrings/eddie.website-keyring.asc > /dev/null
echo "deb [signed-by=/usr/share/keyrings/eddie.website-keyring.asc] http://eddie.website/repository/apt stable main" | sudo tee /etc/apt/sources.list.d/eddie.website.list

# Eza repository
sudo mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list

# Fastfetch PPA
sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch

# Refresh and Bulk Install Native APT Apps
sudo apt update
sudo apt install -y \
    eddie-ui eza fastfetch bat zsh build-essential autoconf make \
    libssl-dev htop blender vlc filezilla inotify-tools fzf \
    docker-compose ansible zsh-autosuggestions zsh-syntax-highlighting flatpak

# Snap fallback for Alacritty
sudo apt install -y snapd
sudo snap install alacritty --classic

# Cleanup
sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y

elif [ "$DISTRO_NAME" = "arch" ]; then echo "-----------------------------------------------" echo "Running Arch Linux Setup Tasks" echo "-----------------------------------------------"

sudo pacman -Syu --noconfirm

# Native Arch Equivalents 
sudo pacman -S --noconfirm --needed \
    curl wget git bat zsh base-devel openssl ca-certificates \
    htop blender vlc filezilla inotify-tools eza fzf docker-compose \
    ansible zsh-autosuggestions zsh-syntax-highlighting flatpak fastfetch alacritty

# Automated Yay Installation
if ! command -v yay >/dev/null 2>&1; then
    echo "-----------------------------------------------"
    echo "Installing YAY (AUR Helper)..."
    echo "-----------------------------------------------"
    
    YAY_BUILD_DIR=$(mktemp -d)
    git clone https://aur.archlinux.org/yay-bin.git "$YAY_BUILD_DIR"
    
    # Build and install as user
    (cd "$YAY_BUILD_DIR" && makepkg -si --noconfirm)
    rm -rf "$YAY_BUILD_DIR"
else
    echo "yay is already installed. Skipping..."
fi

# Use Yay for AirVPN Eddie
echo "-----------------------------------------------"
echo "Installing AirVPN Eddie via AUR..."
echo "-----------------------------------------------"
yay -S --noconfirm eddie-ui

fi

4. UNIVERSAL INDEPENDENT BINARIES

echo "-----------------------------------------------" echo "Installing Zoxide..." echo "-----------------------------------------------" curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh

Configure shell scripts safely

for rc in ".zshrc" ".bashrc"; do if [ -f "$USER_HOME/$rc" ]; then shell_name=$(echo "$rc" | sed 's/.//;s/rc//') if ! grep -q "zoxide init $shell_name" "$USER_HOME/$rc"; then echo "eval "$(zoxide init $shell_name)"" >> "$USER_HOME/$rc" fi fi done

echo "-----------------------------------------------" echo "Installing Starship..." echo "-----------------------------------------------" curl -sS https://starship.rs/install.sh | sh -s -- -y

echo "-----------------------------------------------" echo "Installing Powerlevel10k..." echo "-----------------------------------------------" if [ ! -d "$USER_HOME/powerlevel10k" ]; then git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$USER_HOME/powerlevel10k" fi

if [ -f "$USER_HOME/.zshrc" ]; then if ! grep -q "powerlevel10k.zsh-theme" "$USER_HOME/.zshrc"; then echo "source ~/powerlevel10k/powerlevel10k.zsh-theme" >> "$USER_HOME/.zshrc" fi fi

5. FLATPAK APPLICATIONS

echo "-----------------------------------------------" echo "Installing Flatpak Applications..." echo "-----------------------------------------------" flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

Appending '|| true' ensures the script finishes even if Flatpak encounters minor warnings

flatpak install -y flathub
com.obsproject.Studio
org.tenacityaudio.Tenacity
md.obsidian.Obsidian
org.gimp.GIMP
com.github.zadam.trilium
com.spotify.Client
io.github.shiftey.Desktop
com.brave.Browser
com.visualstudio.code
org.qbittorrent.qBittorrent
org.wezfurlong.wezterm || true

echo "-----------------------------------------------" echo "Deployment Complete! Please restart your terminal." echo "-----------------------------------------------"


<div class="code-block ng-tns-c2069566202-467 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation" id="bkmrk--1"><div class="formatted-code-block-internal-container ng-tns-c2069566202-467"><div class="animated-opacity ng-tns-c2069566202-467"></div></div></div>Save this to a file (like `setup.sh`), make it executable with `chmod +x setup.sh`, and you are ready to distro-hop completely friction-free!

# BASH Files for Arch

The good news is that most of your configuration is already compatible with **Arch Linux**! Bash is Bash, regardless of the distribution.

However, Arch is a "minimalist" rolling release, so the main differences lie in **package names** and **binary locations**. I've identified a few spots where your current scripts assume a Debian/Ubuntu-like environment (e.g., specific paths like `/usr/bin/starship`).

Here is the "Arch-optimized" version of your files with the necessary corrections.

## 1. `.bashrc`

**Key Changes:**

- **Pathing:** Changed `/usr/bin/starship` to a simple `command -v` check. On Arch, binaries are usually in `/usr/bin/`, but it's safer to let the shell find them.
- **Initialization:** Cleaned up the double `eval` at the bottom (you had `starship` and `zoxide` mashed together).
- **Safety:** Added checks for `fzf` and `zoxide`.

<div class="code-block ng-tns-c2069566202-494 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation" id="bkmrk-bash"><div class="formatted-code-block-internal-container ng-tns-c2069566202-494"><div class="animated-opacity ng-tns-c2069566202-494"><div class="code-block-decoration header-formatted gds-emphasized-body-m ng-tns-c2069566202-494 ng-star-inserted"><span class="ng-tns-c2069566202-494">Bash</span><div class="buttons ng-tns-c2069566202-494 ng-star-inserted"></div></div></div></div></div>```
# If not running interactively, don't do anything
case $- in
   *i*) ;;
     *) return;;
esac

# Load fastfetch (Ensure 'fastfetch' is installed via pacman)
if command -v fastfetch &> /dev/null; then
    fastfetch
fi

# Starship Prompt Logic
if command -v starship &> /dev/null; then
    eval "$(starship init bash)"
else
    echo "Starship not found. Install with: sudo pacman -S starship"
fi

# History Settings
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=20000
HISTFILESIZE=10000
shopt -s checkwinsize
shopt -s cmdhist

# Lesspipe (On Arch, install 'lesspipe' from AUR or use the core version)
[ -x /usr/bin/lesspipe.sh ] && eval "$(SHELL=/bin/sh /usr/bin/lesspipe.sh)"

# Load Aliases and Functions
[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases
[[ -f ~/.bash_functions ]] && . ~/.bash_functions

# Bash Completion (Arch path)
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  fi
fi

# Default Editor
export EDITOR='nano'

# FZF (Install via: sudo pacman -S fzf)
if command -v fzf &> /dev/null; then
    eval "$(fzf --bash)"
fi

# LM Studio Path
export PATH="$PATH:$HOME/.lmstudio/bin"

# Zoxide (Install via: sudo pacman -S zoxide)
if command -v zoxide &> /dev/null; then
    eval "$(zoxide init bash)"
fi

# Cargo/Rust
[[ -f "$HOME/.cargo/env" ]] && . "$HOME/.cargo/env"

# Auto-ls on cd
cd() {
    builtin cd "$@" && ls -lA
}

## 2. `.bash_aliases`

Key Changes:

  • Netstat: Arch uses iproute2 by default. netstat is part of net-tools (deprecated). I updated the alias to use ss, which is the modern Arch way, but kept the name ports.
  • Typo Fix: Fixed lias addup to alias addup.
  • Eza: Ensure you run sudo pacman -S eza first.
Bash
``` # EZA Aliases alias ls='eza --all --long --group --group-directories-first --icons --header --time-style long-iso' alias l='eza -lahF --icons --sort=size --group-directories-first' alias lss='eza -hF --icons --sort=size --group-directories-first' alias la='eza -ahF --icons --sort=size --group-directories-first' alias lst='eza -lahT --icons --sort=size --group-directories-first' alias lt='eza -aT --icons --group-directories-first --sort=size'

Navigation

alias ..='cd ..' alias ...='cd ../../../' alias ....='cd ../../../../' alias .4='cd ../../../../' alias .5='cd ../../../../..'

Disk Usage

alias used='du -sch .[!.]* * 2>/dev/null | sort -h' alias totalusage='df -hl --total | grep total' alias partusage='df -hlT --exclude-type=tmpfs --exclude-type=devtmpfs' alias most='du -hsx * | sort -rh | head -10' alias mnt="mount | awk -F' ' '{ printf "%s\t%s\n",$1,$3; }' | column -t | grep ^/dev/ | sort"

System Tools

alias c='clear' alias h='history' alias path='echo -e ${PATH//:/\n}' alias ports='ss -tulanp' # Modern Arch replacement for netstat alias jctl="journalctl -p 3 -xb"

Power Management

alias reboot='sudo reboot' alias poweroff='sudo poweroff'

Git Aliases

alias addup='git add -u' alias addall='git add .' alias branch='git branch' alias checkout='git checkout' alias stat='git status' alias commit='git commit -m' alias push='git push origin' alias pull='git pull origin'

Apps

alias n=nano alias sn='sudo nano' alias bashrc="nano ~/.bashrc && source ~/.bashrc"


<div class="code-block ng-tns-c2069566202-495 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation" id="bkmrk--4"><div class="formatted-code-block-internal-container ng-tns-c2069566202-495"><div class="animated-opacity ng-tns-c2069566202-495"></div></div></div>## 3. `.bash_functions`

**Key Changes:**

- **xtract:** Added a check for `7z` (p7zip) vs `unzip`.
- **Prompt Logic:** Your `set_bash_prompt` was being overwritten by `starship` in the `.bashrc`. If you use Starship, you don't actually need the `set_bash_prompt` or `git_branch` functions anymore—Starship handles that much more efficiently. I've left them here just in case you want to toggle Starship off.

<div class="code-block ng-tns-c2069566202-496 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation" id="bkmrk-bash-2"><div class="formatted-code-block-internal-container ng-tns-c2069566202-496"><div class="animated-opacity ng-tns-c2069566202-496"><div class="code-block-decoration header-formatted gds-emphasized-body-m ng-tns-c2069566202-496 ng-star-inserted"><span class="ng-tns-c2069566202-496">Bash</span><div class="buttons ng-tns-c2069566202-496 ng-star-inserted"></div></div></div></div></div>```
# Extract archives
xtract() {
    if [ -z "$1" ]; then
        echo "Usage: xtract <archive>"
    else
        case "$1" in
            *.tar.bz2|*.tbz2|*.tbz) tar xvjf "$1" ;;
            *.tgz|*.tar.gz)         tar xvf "$1"  ;;
            *.tar.xz|*.txz)         tar xvJf "$1" ;;
            *.tar)                  tar xvf "$1"  ;;
            *.rar)                  unp "$1"      ;; # Install 'unp' or use 7z
            *.zip)                  unzip "$1"    ;;
            *.7z)                   7z x "$1"     ;;
            *) echo "Sorry, '$1' could not be decompressed." ;;
        esac
    fi
}

# Go up N directories
up(){
  local d=""
  limit=${1:-1}
  for ((i=1 ; i <= limit ; i++)); do d=$d/..; done
  d=$(echo $d | sed 's/^\///')
  cd "$d"
}

# Create and enter dir
mkcd() {
    mkdir -p "$1" && cd "$1"
}

# External IP
myip() {
    curl -s https://ifconfig.me
}

# Colored Man Pages
man() {
    LESS_TERMCAP_md=$'\e[1;31m' \
    LESS_TERMCAP_me=$'\e[0m' \
    LESS_TERMCAP_se=$'\e[0m' \
    LESS_TERMCAP_so=$'\e[1;44;33m' \
    LESS_TERMCAP_ue=$'\e[0m' \
    LESS_TERMCAP_us=$'\e[1;32m' \
    command man "$@"
}

### Arch Linux Checklist

To make sure all these aliases work, run this command to install the necessary dependencies:

Bash
``` sudo pacman -S starship fastfetch eza fzf zoxide bat p7zip unzip

<div class="code-block ng-tns-c2069566202-497 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation" id="bkmrk--10"><div class="formatted-code-block-internal-container ng-tns-c2069566202-497"><div class="animated-opacity ng-tns-c2069566202-497"></div></div></div>*(Note: `bat` is used in your `finddoc` alias, and `eza` is used for all your `ls` replacements.)*