lefteros_by SomniusX
EN ↗Πες ένα γεια

22 Οκτωβρίου 2025 / Lefteris Iliadis (SomniusX)

Εγκατάσταση Termbin σε όλα τα Distro με Bash script

Για όσους δεν το ξέρετε, το termbin.com είναι ένα pastebin service που δουλεύει από το terminal. Αντί να ανοίγεις browser κάθε φορά που θέλεις να μοιραστείς κάποιο log ή κομμάτι κώ

Script για Εγκατάσταση Termbin σε Όλα τα Distros

Για όσους δεν το ξέρετε, το termbin.com είναι ένα pastebin service που δουλεύει από το terminal. Αντί να ανοίγεις browser κάθε φορά που θέλεις να μοιραστείς κάποιο log ή κομμάτι κώδικα, απλά στέλνεις τα δεδομένα με netcat στο termbin.com:9999 και παίρνεις πίσω ένα URL.

Το πρόβλημα είναι ότι κανείς δεν θυμάται να γράφει nc termbin.com 9999 κάθε φορά, οπότε έφτιαξα αυτό το script που κάνει την εγκατάσταση και configuration αυτόματα.

Τι κάνει

Το script ανιχνεύει το distribution που έχεις (Arch, Fedora, Debian, openSUSE κλπ) και εγκαθιστά το netcat με τον κατάλληλο package manager. Μετά ψάχνει για όλα τα shells που έχεις configured - bash, zsh, fish, ksh και άλλα - και προσθέτει σε όλα ένα alias που λέγεται tb.

Υποστηρίζει περίπου 15 διαφορετικά distributions και 12 shells, οπότε δεν χρειάζεται να σκέφτεσαι τίποτα. Απλά το τρέχεις και κάνει όλη τη δουλειά.

Χρήση

bash ./install-termbin_all-distro.sh

Μόλις τρέξει, μπορείς να στέλνεις οτιδήποτε στο termbin με:

cat myfile.txt | tb

dmesg | tb

pacman -Q | tb

Αν τρέχεις bash, κάνει και source αυτόματα το ~/.bashrc οπότε το alias είναι διαθέσιμο αμέσως. Για τα άλλα shells σου λέει τι πρέπει να τρέξεις.

Γιατί το έφτιαξα

Έχω πολλά συστήματα με διαφορετικά distros και shells, και με είχε κουράσει να θυμάμαι κάθε φορά πού πρέπει να προσθέσω το alias και πώς λέγεται το πακέτο του netcat σε κάθε distro. Οπότε το αυτοματοποίησα.

Αν το βρείτε χρήσιμο, feel free να το χρησιμοποιήσετε.


Δικό σας

#!/bin/bash

# Function to check if a command exists
command_exists() {
    command -v "$1" >/dev/null 2>&1
}

# Function to detect system and package manager
detect_system() {
    if [ -f /etc/os-release ]; then
        . /etc/os-release
        OS=$NAME
    else
        OS=$(uname -s)
    fi

    case $OS in
        "Arch Linux"|"CachyOS"|"EndeavourOS"|"Manjaro Linux"|"Garuda Linux"|"ArcoLinux"|"Artix Linux")
            echo "arch"
            ;;
        "Fedora Linux"|"Fedora"|"Nobara Linux"|"Nobara")
            echo "fedora"
            ;;
        "Ubuntu"|"Debian GNU/Linux"|"Linux Mint"|"Pop!_OS"|"Zorin OS"|"elementary OS"|"Kali GNU/Linux"|"Parrot OS")
            echo "debian"
            ;;
        "openSUSE"*|"SUSE"*)
            echo "opensuse"
            ;;
        "Gentoo")
            echo "gentoo"
            ;;
        "Alpine Linux")
            echo "alpine"
            ;;
        "Void")
            echo "void"
            ;;
        "Solus")
            echo "solus"
            ;;
        "Clear Linux"*)
            echo "clearlinux"
            ;;
        "NixOS")
            echo "nixos"
            ;;
        "Red Hat"*|"CentOS"*|"Rocky Linux"|"AlmaLinux"|"Oracle Linux")
            echo "rhel"
            ;;
        *)
            echo "unknown"
            ;;
    esac
}

# Function to install netcat based on system
install_netcat() {
    local system=$1
    echo "Installing netcat..."
    
    case $system in
        "arch")
            sudo pacman -S --noconfirm netcat
            ;;
        "fedora"|"rhel")
            sudo dnf install -y nmap-ncat
            ;;
        "debian")
            sudo apt-get update && sudo apt-get install -y netcat
            ;;
        "opensuse")
            sudo zypper install -y netcat-openbsd
            ;;
        "gentoo")
            sudo emerge -av net-analyzer/netcat
            ;;
        "alpine")
            sudo apk add netcat-openbsd
            ;;
        "void")
            sudo xbps-install -y openbsd-netcat
            ;;
        "solus")
            sudo eopkg install netcat
            ;;
        "clearlinux")
            sudo swupd bundle-add network-basic
            ;;
        "nixos")
            echo "On NixOS, add 'netcat' to your configuration.nix or use: nix-env -iA nixos.netcat"
            echo "You can also use: nix-shell -p netcat"
            read -p "Press Enter to continue after installing netcat..."
            ;;
        *)
            echo "Unsupported system: $OS"
            echo "Please install netcat manually"
            exit 1
            ;;
    esac
}

# Function to add alias to bash
add_bash_alias() {
    if ! grep -q 'alias tb="nc termbin.com 9999"' ~/.bashrc; then
        echo 'alias tb="nc termbin.com 9999"' >> ~/.bashrc
        echo "Alias 'tb' added to .bashrc"
    else
        echo "Alias 'tb' is already present in .bashrc"
    fi
}

# Function to add alias to fish
add_fish_alias() {
    if ! grep -q 'alias tb="nc termbin.com 9999"' ~/.config/fish/config.fish; then
        echo 'alias tb="nc termbin.com 9999"' >> ~/.config/fish/config.fish
        echo "Alias 'tb' added to fish config"
    else
        echo "Alias 'tb' is already present in fish config"
    fi
}

# Function to add alias to zsh
add_zsh_alias() {
    if ! grep -q 'alias tb="nc termbin.com 9999"' ~/.zshrc; then
        echo 'alias tb="nc termbin.com 9999"' >> ~/.zshrc
        echo "Alias 'tb' added to .zshrc"
    else
        echo "Alias 'tb' is already present in .zshrc"
    fi
}

# Function to add alias to ksh
add_ksh_alias() {
    if ! grep -q 'alias tb="nc termbin.com 9999"' ~/.kshrc; then
        echo 'alias tb="nc termbin.com 9999"' >> ~/.kshrc
        echo "Alias 'tb' added to .kshrc"
    else
        echo "Alias 'tb' is already present in .kshrc"
    fi
}

# Function to add alias to tcsh
add_tcsh_alias() {
    if ! grep -q 'alias tb "nc termbin.com 9999"' ~/.tcshrc; then
        echo 'alias tb "nc termbin.com 9999"' >> ~/.tcshrc
        echo "Alias 'tb' added to .tcshrc"
    else
        echo "Alias 'tb' is already present in .tcshrc"
    fi
}

# Function to add alias to csh
add_csh_alias() {
    if ! grep -q 'alias tb "nc termbin.com 9999"' ~/.cshrc; then
        echo 'alias tb "nc termbin.com 9999"' >> ~/.cshrc
        echo "Alias 'tb' added to .cshrc"
    else
        echo "Alias 'tb' is already present in .cshrc"
    fi
}

# Function to add alias to dash (uses .profile)
add_dash_alias() {
    if ! grep -q 'alias tb="nc termbin.com 9999"' ~/.profile; then
        echo 'alias tb="nc termbin.com 9999"' >> ~/.profile
        echo "Alias 'tb' added to .profile"
    else
        echo "Alias 'tb' is already present in .profile"
    fi
}

# Function to add alias to nushell
add_nushell_alias() {
    local nu_config="$HOME/.config/nushell/config.nu"
    if [ -f "$nu_config" ]; then
        if ! grep -q 'alias tb = nc termbin.com 9999' "$nu_config"; then
            echo 'alias tb = nc termbin.com 9999' >> "$nu_config"
            echo "Alias 'tb' added to nushell config"
        else
            echo "Alias 'tb' is already present in nushell config"
        fi
    fi
}

# Function to add alias to xonsh
add_xonsh_alias() {
    if ! grep -q "aliases\['tb'\] = 'nc termbin.com 9999'" ~/.xonshrc; then
        echo "aliases['tb'] = 'nc termbin.com 9999'" >> ~/.xonshrc
        echo "Alias 'tb' added to .xonshrc"
    else
        echo "Alias 'tb' is already present in .xonshrc"
    fi
}

# Function to add alias to elvish
add_elvish_alias() {
    local elvish_config="$HOME/.config/elvish/rc.elv"
    if [ -f "$elvish_config" ]; then
        if ! grep -q "fn tb { nc termbin.com 9999 }" "$elvish_config"; then
            echo 'fn tb { nc termbin.com 9999 }' >> "$elvish_config"
            echo "Alias 'tb' added to elvish config"
        else
            echo "Alias 'tb' is already present in elvish config"
        fi
    fi
}

# Function to add alias to ion
add_ion_alias() {
    if ! grep -q 'alias tb = "nc termbin.com 9999"' ~/.config/ion/initrc; then
        mkdir -p ~/.config/ion
        echo 'alias tb = "nc termbin.com 9999"' >> ~/.config/ion/initrc
        echo "Alias 'tb' added to ion config"
    else
        echo "Alias 'tb' is already present in ion config"
    fi
}

# Function to add alias to oil
add_oil_alias() {
    if ! grep -q 'alias tb="nc termbin.com 9999"' ~/.config/oil/oshrc; then
        mkdir -p ~/.config/oil
        echo 'alias tb="nc termbin.com 9999"' >> ~/.config/oil/oshrc
        echo "Alias 'tb' added to oil config"
    else
        echo "Alias 'tb' is already present in oil config"
    fi
}

# Function to detect current shell
detect_current_shell() {
    echo $SHELL
}

# Function to detect all available shells
detect_available_shells() {
    local shells=()
    
    # Check for bash
    if [ -f "$HOME/.bashrc" ]; then
        shells+=("bash")
    fi
    
    # Check for fish
    if [ -f "$HOME/.config/fish/config.fish" ]; then
        shells+=("fish")
    fi
    
    # Check for zsh
    if [ -f "$HOME/.zshrc" ]; then
        shells+=("zsh")
    fi
    
    # Check for ksh
    if [ -f "$HOME/.kshrc" ]; then
        shells+=("ksh")
    fi
    
    # Check for tcsh
    if [ -f "$HOME/.tcshrc" ]; then
        shells+=("tcsh")
    fi
    
    # Check for csh
    if [ -f "$HOME/.cshrc" ]; then
        shells+=("csh")
    fi
    
    # Check for dash (uses .profile)
    if [ -f "$HOME/.profile" ]; then
        shells+=("dash")
    fi
    
    # Check for nushell
    if [ -f "$HOME/.config/nushell/config.nu" ]; then
        shells+=("nushell")
    fi
    
    # Check for xonsh
    if [ -f "$HOME/.xonshrc" ]; then
        shells+=("xonsh")
    fi
    
    # Check for elvish
    if [ -f "$HOME/.config/elvish/rc.elv" ]; then
        shells+=("elvish")
    fi
    
    # Check for ion
    if [ -f "$HOME/.config/ion/initrc" ]; then
        shells+=("ion")
    fi
    
    # Check for oil
    if [ -f "$HOME/.config/oil/oshrc" ]; then
        shells+=("oil")
    fi
    
    echo "${shells[@]}"
}

# Main script
echo "Detecting system..."
SYSTEM=$(detect_system)
echo "Detected system: $SYSTEM"

# Check for netcat installation
if ! command_exists nc && ! command_exists netcat; then
    install_netcat "$SYSTEM"
else
    echo "netcat is already installed."
fi

# Detect current shell
CURRENT_SHELL=$(detect_current_shell)
echo "Current shell: $CURRENT_SHELL"

# Detect and configure available shells
echo "Detecting available shells..."
AVAILABLE_SHELLS=($(detect_available_shells))

if [ ${#AVAILABLE_SHELLS[@]} -eq 0 ]; then
    echo "No shell configurations found. Please create a shell configuration file first."
    exit 1
fi

echo "Found shells: ${AVAILABLE_SHELLS[*]}"

# Configure each detected shell
for shell in "${AVAILABLE_SHELLS[@]}"; do
    case $shell in
        "bash")
            echo "Configuring bash..."
            add_bash_alias
            ;;
        "fish")
            echo "Configuring fish..."
            add_fish_alias
            ;;
        "zsh")
            echo "Configuring zsh..."
            add_zsh_alias
            ;;
        "ksh")
            echo "Configuring ksh..."
            add_ksh_alias
            ;;
        "tcsh")
            echo "Configuring tcsh..."
            add_tcsh_alias
            ;;
        "csh")
            echo "Configuring csh..."
            add_csh_alias
            ;;
        "dash")
            echo "Configuring dash..."
            add_dash_alias
            ;;
        "nushell")
            echo "Configuring nushell..."
            add_nushell_alias
            ;;
        "xonsh")
            echo "Configuring xonsh..."
            add_xonsh_alias
            ;;
        "elvish")
            echo "Configuring elvish..."
            add_elvish_alias
            ;;
        "ion")
            echo "Configuring ion..."
            add_ion_alias
            ;;
        "oil")
            echo "Configuring oil..."
            add_oil_alias
            ;;
        *)
            echo "Unsupported shell: $shell"
            ;;
    esac
done

# Source the current shell's configuration file
echo ""
echo "Attempting to source the current shell configuration..."
case "$CURRENT_SHELL" in
    */bash)
        if [ -f "$HOME/.bashrc" ]; then
            echo "Sourcing .bashrc..."
            source "$HOME/.bashrc"
            echo "✓ Bash configuration reloaded"
        fi
        ;;
    */zsh)
        if [ -f "$HOME/.zshrc" ]; then
            echo "Sourcing .zshrc..."
            # Note: sourcing in subshell won't affect parent, user needs to restart shell or source manually
            echo "✓ Zsh configuration updated (restart your shell or run: source ~/.zshrc)"
        fi
        ;;
    */fish)
        if [ -f "$HOME/.config/fish/config.fish" ]; then
            echo "✓ Fish configuration updated (restart your shell or run: source ~/.config/fish/config.fish)"
        fi
        ;;
    */ksh)
        if [ -f "$HOME/.kshrc" ]; then
            echo "✓ Ksh configuration updated (restart your shell or run: source ~/.kshrc)"
        fi
        ;;
    */tcsh)
        if [ -f "$HOME/.tcshrc" ]; then
            echo "✓ Tcsh configuration updated (restart your shell or run: source ~/.tcshrc)"
        fi
        ;;
    */csh)
        if [ -f "$HOME/.cshrc" ]; then
            echo "✓ Csh configuration updated (restart your shell or run: source ~/.cshrc)"
        fi
        ;;
    */dash)
        if [ -f "$HOME/.profile" ]; then
            echo "✓ Dash configuration updated (restart your shell or run: . ~/.profile)"
        fi
        ;;
    */nu|*/nushell)
        echo "✓ Nushell configuration updated (restart your shell to apply changes)"
        ;;
    */xonsh)
        if [ -f "$HOME/.xonshrc" ]; then
            echo "✓ Xonsh configuration updated (restart your shell to apply changes)"
        fi
        ;;
    */elvish)
        echo "✓ Elvish configuration updated (restart your shell to apply changes)"
        ;;
    */ion)
        echo "✓ Ion configuration updated (restart your shell to apply changes)"
        ;;
    */oil|*/osh)
        echo "✓ Oil configuration updated (restart your shell to apply changes)"
        ;;
    *)
        echo "Current shell not recognized. Please source your shell's configuration manually."
        ;;
esac

echo ""
echo "Termbin setup complete! You can now use 'tb' to send input to Termbin."
echo "Example usage: echo 'Hello World' | tb"
echo ""
echo "If the alias is not working, try:"
echo "  - Opening a new terminal window"
echo "  - Or manually sourcing your shell's configuration file"