#!/bin/bash # RDP Client Complete Installation Script # This script clones the repository and installs all dependencies set -e # Exit on any error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration REPO_URL="ssh://git@gitea.egonetix.de:222/root/rdp_client.git" INSTALL_DIR="$HOME/rdp-client" DESKTOP_FILE="$HOME/.local/share/applications/rdp-client.desktop" BIN_LINK="$HOME/.local/bin/rdp-client" echo -e "${BLUE}=== RDP Client Complete Installation ===${NC}" echo "This script will:" echo "1. Install system dependencies (freerdp, python3, git)" echo "2. Clone the RDP client repository" echo "3. Install Python dependencies" echo "4. Create desktop entry and launcher" echo "5. Set up the application for easy access" echo # Function to check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Function to detect package manager and install packages install_system_deps() { echo -e "${YELLOW}Installing system dependencies...${NC}" if command_exists apt-get; then # Debian/Ubuntu echo "Detected apt package manager (Debian/Ubuntu)" sudo apt-get update sudo apt-get install -y freerdp2-x11 python3 python3-pip python3-venv git python3-tk xrandr elif command_exists dnf; then # Fedora echo "Detected dnf package manager (Fedora)" sudo dnf install -y freerdp python3 python3-pip git python3-tkinter xrandr elif command_exists yum; then # RHEL/CentOS echo "Detected yum package manager (RHEL/CentOS)" sudo yum install -y freerdp python3 python3-pip git tkinter xrandr elif command_exists zypper; then # openSUSE echo "Detected zypper package manager (openSUSE)" sudo zypper install -y freerdp python3 python3-pip git python3-tk xrandr elif command_exists pacman; then # Arch Linux echo "Detected pacman package manager (Arch Linux)" sudo pacman -S --noconfirm freerdp python python-pip git tk xorg-xrandr else echo -e "${RED}Error: Could not detect package manager. Please install manually:${NC}" echo "- freerdp2-x11 (or freerdp)" echo "- python3" echo "- python3-pip" echo "- python3-tk (or python3-tkinter)" echo "- git" echo "- xrandr" exit 1 fi } # Function to setup SSH key if needed setup_ssh_key() { if [[ "$REPO_URL" == ssh://* ]] || [[ "$REPO_URL" == git@* ]]; then if [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "$HOME/.ssh/id_ed25519" ]; then echo -e "${YELLOW}No SSH key found. You may need to set up SSH access to the repository.${NC}" echo "You can:" echo "1. Generate an SSH key: ssh-keygen -t ed25519 -C \"your_email@example.com\"" echo "2. Add it to your Gitea account" echo "3. Or change the repository URL to HTTPS" echo read -p "Continue anyway? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi fi } # Function to clone or update repository clone_or_update_repo() { echo -e "${YELLOW}Setting up repository...${NC}" if [ -d "$INSTALL_DIR" ]; then echo "Directory $INSTALL_DIR already exists. Updating..." cd "$INSTALL_DIR" git pull origin main else echo "Cloning repository to $INSTALL_DIR..." git clone "$REPO_URL" "$INSTALL_DIR" cd "$INSTALL_DIR" fi } # Function to setup Python environment setup_python_env() { echo -e "${YELLOW}Setting up Python environment...${NC}" cd "$INSTALL_DIR" # Create virtual environment if it doesn't exist if [ ! -d ".venv" ]; then python3 -m venv .venv fi # Activate virtual environment source .venv/bin/activate # Upgrade pip pip install --upgrade pip # Install Python dependencies echo "Installing Python dependencies..." pip install cryptography # Create requirements.txt for future reference cat > requirements.txt << EOF cryptography>=3.4.8 EOF echo -e "${GREEN}Python environment setup complete${NC}" } # Function to create desktop entry create_desktop_entry() { echo -e "${YELLOW}Creating desktop entry...${NC}" # Ensure directories exist mkdir -p "$(dirname "$DESKTOP_FILE")" mkdir -p "$(dirname "$BIN_LINK")" # Create desktop file cat > "$DESKTOP_FILE" << EOF [Desktop Entry] Version=1.0 Type=Application Name=RDP Client Comment=Professional RDP Client with Multi-Monitor Support Exec=$INSTALL_DIR/.venv/bin/python $INSTALL_DIR/rdp_client.py Icon=preferences-desktop-remote-desktop Terminal=false Categories=Network;RemoteAccess; Keywords=rdp;remote;desktop;connection; StartupNotify=true EOF # Create launcher script in PATH cat > "$BIN_LINK" << EOF #!/bin/bash cd "$INSTALL_DIR" source .venv/bin/activate python rdp_client.py "\$@" EOF chmod +x "$BIN_LINK" echo -e "${GREEN}Desktop entry created${NC}" } # Function to test installation test_installation() { echo -e "${YELLOW}Testing installation...${NC}" cd "$INSTALL_DIR" source .venv/bin/activate # Test Python imports python -c "import tkinter; import cryptography; print('All Python dependencies OK')" # Test xfreerdp if command_exists xfreerdp; then echo "xfreerdp found: $(which xfreerdp)" else echo -e "${RED}Warning: xfreerdp not found in PATH${NC}" fi # Test xrandr if command_exists xrandr; then echo "xrandr found: $(which xrandr)" else echo -e "${RED}Warning: xrandr not found in PATH${NC}" fi } # Main installation process main() { echo -e "${BLUE}Starting installation process...${NC}" # Check if running as root if [[ $EUID -eq 0 ]]; then echo -e "${RED}Error: Don't run this script as root!${NC}" exit 1 fi # Install system dependencies install_system_deps # Setup SSH if needed setup_ssh_key # Clone or update repository clone_or_update_repo # Setup Python environment setup_python_env # Create desktop entry create_desktop_entry # Test installation test_installation echo echo -e "${GREEN}=== Installation Complete! ===${NC}" echo echo "The RDP Client has been installed to: $INSTALL_DIR" echo echo "You can now run it in several ways:" echo "1. From command line: rdp-client" echo "2. From applications menu: Search for 'RDP Client'" echo "3. Directly: $INSTALL_DIR/.venv/bin/python $INSTALL_DIR/rdp_client.py" echo echo "Configuration files will be stored in: ~/.config/rdp-client/" echo echo -e "${YELLOW}Note: You may need to log out and back in for the desktop entry to appear.${NC}" echo echo "Enjoy your new RDP client! 🚀" } # Handle script arguments case "${1:-}" in --help|-h) echo "RDP Client Complete Installation Script" echo echo "Usage: $0 [options]" echo echo "Options:" echo " --help, -h Show this help message" echo " --uninstall Remove the RDP client installation" echo echo "This script will install all dependencies and set up the RDP client." exit 0 ;; --uninstall) echo -e "${YELLOW}Uninstalling RDP Client...${NC}" rm -rf "$INSTALL_DIR" rm -f "$DESKTOP_FILE" rm -f "$BIN_LINK" echo -e "${GREEN}RDP Client uninstalled successfully${NC}" exit 0 ;; *) main ;; esac