#!/bin/bash # # ZDTT Terminal Installer # Downloads and installs ZDTT Terminal from zdtt-sources.zane.org # # Quick Install: # curl -O https://zdtt-sources.zane.org/install.sh && chmod +x install.sh && ./install.sh # set -e # Exit on error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo "=========================================" echo " ZDTT Terminal Installation Script" echo "=========================================" echo "" # Installation directories INSTALL_DIR="$HOME/.local/share/zdtt" BIN_DIR="$HOME/.local/bin" # Check if ZDTT is already installed if [ -f "$BIN_DIR/zdtt" ] || [ -d "$INSTALL_DIR" ]; then echo -e "${YELLOW}ZDTT Terminal is already installed!${NC}" echo "" echo "What would you like to do?" echo " 1) Reinstall ZDTT Terminal" echo " 2) Uninstall ZDTT Terminal" echo " 3) Cancel" echo "" read -p "Enter your choice (1-3): " -n 1 -r echo "" echo "" case $REPLY in 1) echo "Reinstalling ZDTT Terminal..." echo "" # Don't remove the directory if we're running from it # Just overwrite the files instead ;; 2) echo "Uninstalling ZDTT Terminal..." rm -rf "$INSTALL_DIR" rm -f "$BIN_DIR/zdtt" echo "" echo -e "${GREEN}✓${NC} ZDTT Terminal has been uninstalled successfully." echo "" echo "Press any key to exit..." read -n 1 -s -r exit 0 ;; 3) echo "Installation cancelled." echo "" echo "Press any key to exit..." read -n 1 -s -r exit 0 ;; *) echo -e "${RED}Invalid choice.${NC} Installation cancelled." echo "" echo "Press any key to exit..." read -n 1 -s -r exit 1 ;; esac fi # Check if running on a supported Linux distribution IS_DEBIAN=false IS_ARCH=false DETECTED_DISTRO="other" OS_ID="" OS_LIKE="" if [ -f /etc/os-release ]; then # shellcheck disable=SC1091 . /etc/os-release OS_ID=$(echo "${ID:-}" | tr '[:upper:]' '[:lower:]') OS_LIKE=$(echo "${ID_LIKE:-}" | tr '[:upper:]' '[:lower:]') fi if [ -f /etc/debian_version ]; then IS_DEBIAN=true DETECTED_DISTRO="debian" echo -e "${GREEN}✓${NC} Debian-based Linux detected" elif [ -f /etc/arch-release ] || [ -f /etc/artix-release ]; then IS_ARCH=true DETECTED_DISTRO="arch" echo -e "${GREEN}✓${NC} Arch Linux detected" elif [[ "$OS_ID" == "debian" || "$OS_ID" == "ubuntu" || "$OS_ID" == "linuxmint" || "$OS_ID" == "pop" || "$OS_ID" == "pop-os" || "$OS_ID" == "pop_os" || "$OS_ID" == "elementary" || "$OS_LIKE" == *"debian"* || "$OS_LIKE" == *"ubuntu"* ]]; then IS_DEBIAN=true DETECTED_DISTRO="debian" echo -e "${GREEN}✓${NC} Debian-based Linux detected (via os-release)" elif [[ "$OS_ID" == "arch" || "$OS_ID" == "archlinux" || "$OS_ID" == "manjaro" || "$OS_ID" == "endeavouros" || "$OS_ID" == "endeavour" || "$OS_ID" == "arcolinux" || "$OS_ID" == "garuda" || "$OS_ID" == "artix" || "$OS_ID" == "blackarch" || "$OS_LIKE" == *"arch"* ]]; then IS_ARCH=true DETECTED_DISTRO="arch" echo -e "${GREEN}✓${NC} Arch-based Linux detected (via os-release)" elif command -v apt-get &>/dev/null; then IS_DEBIAN=true DETECTED_DISTRO="debian" echo -e "${GREEN}✓${NC} Debian-based Linux detected (via package manager)" elif command -v pacman &>/dev/null; then IS_ARCH=true DETECTED_DISTRO="arch" echo -e "${GREEN}✓${NC} Arch-based Linux detected (via package manager)" else echo -e "${YELLOW}⚠${NC} Unsupported distribution detected" echo "" echo "ZDTT Terminal is optimized for Debian-based and Arch Linux systems." echo "" echo "Running on an unsupported system may result in:" echo " • Some commands may not work as expected" echo " • Auto-install features (like fastfetch) will not work" echo " • Reduced plugin compatibility" echo " • Package management commands unavailable" echo "" read -p "Continue installation anyway? (yes/no): " -r echo "" if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then echo "Installation cancelled." echo "" echo "Press any key to exit..." read -n 1 -s -r exit 0 fi fi echo "Detected distribution: ${DETECTED_DISTRO}" read -p "Override detection? (debian/arch/other, Enter to keep): " -r USER_OVERRIDE USER_OVERRIDE=$(echo "$USER_OVERRIDE" | tr '[:upper:]' '[:lower:]') case "$USER_OVERRIDE" in debian) IS_DEBIAN=true IS_ARCH=false DETECTED_DISTRO="debian" echo "Override applied: Debian-based system selected." ;; arch) IS_DEBIAN=false IS_ARCH=true DETECTED_DISTRO="arch" echo "Override applied: Arch-based system selected." ;; other) IS_DEBIAN=false IS_ARCH=false DETECTED_DISTRO="other" echo "Override applied: Unsupported/Other selected." ;; "") echo "Keeping detected distribution." ;; *) echo "Unknown override '$USER_OVERRIDE'. Keeping detected distribution." ;; esac # Check if Python 3 is installed if ! command -v python3 &> /dev/null; then echo -e "${RED}✗${NC} Python 3 is not installed" echo "" if [ "$IS_DEBIAN" = true ]; then echo "Installing Python 3..." # Update package list and install Python 3 sudo apt-get update sudo apt-get install -y python3 if [ $? -ne 0 ]; then echo -e "${RED}Failed to install Python 3${NC}" echo "Please install Python 3 manually: sudo apt-get install python3" echo "" echo "Press any key to exit..." read -n 1 -s -r exit 1 fi echo -e "${GREEN}✓${NC} Python 3 installed successfully" elif [ "$IS_ARCH" = true ]; then echo "Installing Python 3..." # Sync package databases and install Python sudo pacman -Sy --noconfirm python if [ $? -ne 0 ]; then echo -e "${RED}Failed to install Python 3${NC}" echo "Please install Python 3 manually: sudo pacman -S python" echo "" echo "Press any key to exit..." read -n 1 -s -r exit 1 fi echo -e "${GREEN}✓${NC} Python 3 installed successfully" else echo -e "${RED}Python 3 is required but auto-install is not supported on this distribution.${NC}" echo "" echo "Please install Python 3 manually using your package manager:" echo " • Debian/Ubuntu: sudo apt-get install python3" echo " • Arch/Manjaro: sudo pacman -S python" echo " • Fedora: sudo dnf install python3" echo " • openSUSE: sudo zypper install python3" echo "" echo "Press any key to exit..." read -n 1 -s -r exit 1 fi else PYTHON_VERSION=$(python3 --version 2>&1) echo -e "${GREEN}✓${NC} Python 3 is already installed: ${PYTHON_VERSION}" fi echo "" # Create directories if they don't exist mkdir -p "$INSTALL_DIR" mkdir -p "$BIN_DIR" mkdir -p "$HOME/.zdtt/plugins" echo "Installing ZDTT Terminal..." echo "Downloading files from zdtt-sources.zane.org..." echo "" # Base URL for ZDTT sources BASE_URL="https://zdtt-sources.zane.org" # Files to download declare -a FILES=("terminal.py" "version.txt") # Download files DOWNLOAD_SUCCESS=true for file in "${FILES[@]}"; do echo "Downloading $file..." if command -v wget &> /dev/null; then if wget -q "$BASE_URL/$file" -O "$INSTALL_DIR/$file" 2>/dev/null; then echo -e "${GREEN}✓${NC} $file downloaded" else echo -e "${RED}✗${NC} Failed to download $file" DOWNLOAD_SUCCESS=false break fi elif command -v curl &> /dev/null; then if curl -sSL "$BASE_URL/$file" -o "$INSTALL_DIR/$file" 2>/dev/null; then echo -e "${GREEN}✓${NC} $file downloaded" else echo -e "${RED}✗${NC} Failed to download $file" DOWNLOAD_SUCCESS=false break fi else echo -e "${RED}✗${NC} Neither wget nor curl found" echo "Please install wget or curl to proceed" echo "" echo "Press any key to exit..." read -n 1 -s -r exit 1 fi done if [ "$DOWNLOAD_SUCCESS" = false ]; then echo "" echo -e "${RED}Installation failed - unable to download required files${NC}" echo "Please check your internet connection and try again." echo "" echo "Press any key to exit..." read -n 1 -s -r exit 1 fi # Copy this installer to the installation directory for future use SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cp "$0" "$INSTALL_DIR/install.sh" # Set executable permissions chmod +x "$INSTALL_DIR/terminal.py" chmod +x "$INSTALL_DIR/install.sh" echo "" echo -e "${GREEN}✓${NC} ZDTT Terminal files installed to $INSTALL_DIR" # Download and install example plugin echo "" echo "Installing example plugin..." EXAMPLE_PLUGIN_URL="https://plugins.zane.org/example_plugin.py" PLUGIN_DEST="$HOME/.zdtt/plugins/example_plugin.py" # Try wget first (more reliable), then curl PLUGIN_DOWNLOADED=false if command -v wget &> /dev/null; then if wget -q "$EXAMPLE_PLUGIN_URL" -O "$PLUGIN_DEST" 2>/dev/null; then echo -e "${GREEN}✓${NC} Example plugin installed from plugins.zane.org" PLUGIN_DOWNLOADED=true fi fi if [ "$PLUGIN_DOWNLOADED" = false ] && command -v curl &> /dev/null; then # Suppress curl snap warnings and try download if curl -sSL "$EXAMPLE_PLUGIN_URL" -o "$PLUGIN_DEST" 2>/dev/null; then echo -e "${GREEN}✓${NC} Example plugin installed from plugins.zane.org" PLUGIN_DOWNLOADED=true fi fi if [ "$PLUGIN_DOWNLOADED" = false ]; then echo -e "${YELLOW}⚠${NC} Could not download example plugin" echo " You can install it later with: zps install $EXAMPLE_PLUGIN_URL" # Don't exit - continue with installation fi # Create the zdtt wrapper script cat > "$BIN_DIR/zdtt" << 'EOF' #!/bin/bash # # ZDTT Terminal Wrapper # ZDTT_DIR="$HOME/.local/share/zdtt" case "$1" in start) # Clear screen before starting ZDTT clear python3 "$ZDTT_DIR/terminal.py" ;; update) echo "Checking for updates..." echo "" # Get current version if [ -f "$ZDTT_DIR/version.txt" ]; then CURRENT_VERSION=$(cat "$ZDTT_DIR/version.txt") else CURRENT_VERSION="unknown" fi # Get remote version if command -v curl &> /dev/null; then REMOTE_VERSION=$(curl -sSL https://zdtt-sources.zane.org/version.txt 2>/dev/null) elif command -v wget &> /dev/null; then REMOTE_VERSION=$(wget -qO- https://zdtt-sources.zane.org/version.txt 2>/dev/null) else echo "Error: Neither curl nor wget found" exit 1 fi if [ -z "$REMOTE_VERSION" ]; then echo "Error: Could not fetch remote version" exit 1 fi echo "Current version: $CURRENT_VERSION" echo "Latest version: $REMOTE_VERSION" echo "" if [ "$CURRENT_VERSION" = "$REMOTE_VERSION" ]; then echo "✓ You're already running the latest version!" else echo "🔔 Update available!" echo "" read -p "Do you want to update now? (yes/no): " -r echo "" if [[ $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then echo "Updating ZDTT Terminal..." echo "" # Download updated files BASE_URL="https://zdtt-sources.zane.org" UPDATE_FAILED=false # Update terminal.py echo "Downloading terminal.py..." if command -v wget &> /dev/null; then wget -q "$BASE_URL/terminal.py" -O "$ZDTT_DIR/terminal.py" 2>/dev/null || UPDATE_FAILED=true elif command -v curl &> /dev/null; then curl -sSL "$BASE_URL/terminal.py" -o "$ZDTT_DIR/terminal.py" 2>/dev/null || UPDATE_FAILED=true fi if [ "$UPDATE_FAILED" = true ]; then echo "✗ Failed to download terminal.py" exit 1 fi echo "✓ terminal.py updated" # Update version.txt echo "Downloading version.txt..." if command -v wget &> /dev/null; then wget -q "$BASE_URL/version.txt" -O "$ZDTT_DIR/version.txt" 2>/dev/null || UPDATE_FAILED=true elif command -v curl &> /dev/null; then curl -sSL "$BASE_URL/version.txt" -o "$ZDTT_DIR/version.txt" 2>/dev/null || UPDATE_FAILED=true fi if [ "$UPDATE_FAILED" = true ]; then echo "✗ Failed to download version.txt" exit 1 fi echo "✓ version.txt updated" # Set permissions chmod +x "$ZDTT_DIR/terminal.py" echo "" echo "===========================================" echo "✓ Update complete!" echo "===========================================" echo "" echo "ZDTT Terminal has been updated to v$REMOTE_VERSION" echo "" echo "Your settings are preserved:" echo " • Command history: ~/.zdtt_history" echo " • Aliases: ~/.zdtt/aliases" echo " • Plugins: ~/.zdtt/plugins/" echo " • Custom banner: ~/.zdtt/banner.txt" echo "" echo "Run 'zdtt start' to use the updated version." else echo "Update cancelled." fi fi ;; installer|install|reinstall) # Run the installer for reinstalling/updating if [ -f "$ZDTT_DIR/install.sh" ]; then bash "$ZDTT_DIR/install.sh" else echo "Error: Installer not found at $ZDTT_DIR/install.sh" echo "Please download the installer from the ZDTT repository." exit 1 fi ;; uninstall) echo "Uninstalling ZDTT Terminal..." rm -rf "$ZDTT_DIR" rm -f "$HOME/.local/bin/zdtt" echo "ZDTT Terminal has been uninstalled." ;; version) if [ -f "$ZDTT_DIR/version.txt" ]; then VERSION=$(cat "$ZDTT_DIR/version.txt") echo "ZDTT Terminal v$VERSION" else echo "ZDTT Terminal v0.0.1.a" fi echo "" echo "Features:" echo " • Command history (↑/↓ navigation)" echo " • Tab completion" echo " • Colorized prompt" echo " • Plugin system" echo " • Native command support" ;; *) echo "ZDTT Terminal" echo "" echo "Usage:" echo " zdtt start - Start the ZDTT Terminal" echo " zdtt update - Check for and install updates" echo " zdtt installer - Run installer (for updates/reinstall)" echo " zdtt version - Display version information" echo " zdtt uninstall - Uninstall ZDTT Terminal" echo "" ;; esac EOF chmod +x "$BIN_DIR/zdtt" echo -e "${GREEN}✓${NC} ZDTT command installed to $BIN_DIR" # Check if ~/.local/bin is in PATH if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then echo "" echo -e "${YELLOW}Warning: $HOME/.local/bin is not in your PATH${NC}" echo "" echo "To use the 'zdtt' command, add the following line to your ~/.bashrc:" echo "" echo " export PATH=\"\$HOME/.local/bin:\$PATH\"" echo "" echo "Then run: source ~/.bashrc" echo "" # Ask if user wants to add it automatically read -p "Would you like to add it to your ~/.bashrc now? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then echo "" >> "$HOME/.bashrc" echo "# Added by ZDTT Terminal installer" >> "$HOME/.bashrc" echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$HOME/.bashrc" echo -e "${GREEN}✓${NC} Added to ~/.bashrc" echo "Please run: source ~/.bashrc" fi else echo -e "${GREEN}✓${NC} ~/.local/bin is already in your PATH" fi echo "" echo "=========================================" echo -e "${GREEN}Installation complete!${NC}" echo "=========================================" echo "" echo "To start ZDTT Terminal, run:" echo " zdtt start" echo "" echo "Press any key to exit..." read -n 1 -s -r