AlphaLawless

arch.sh

Aug 17th, 2025
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.25 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. # Script simplificado para configurar XRDP no Manjaro para Hyper-V Enhanced Session
  4. # Baseado no script do Chris Titus Tech, mas corrigido para Manjaro
  5.  
  6. set -e  # Parar em caso de erro
  7.  
  8. echo "=== Configurando XRDP para Hyper-V Enhanced Session no Manjaro ==="
  9.  
  10. # Verificar se é root
  11. if [ "$(id -u)" -ne 0 ]; then
  12.     echo "❌ Este script deve ser executado como root"
  13.     echo "💡 Use: sudo $0"
  14.     exit 1
  15. fi
  16.  
  17. # Função para verificar se comando existe
  18. command_exists() {
  19.     command -v "$1" >/dev/null 2>&1
  20. }
  21.  
  22. # Verificar se yay está instalado (AUR helper)
  23. if ! command_exists yay; then
  24.     echo "📦 Instalando yay (AUR helper)..."
  25.     pacman -S --needed --noconfirm base-devel git
  26.    
  27.     # Criar usuário temporário para build se necessário
  28.     if [ ! -d "/tmp/yay-install" ]; then
  29.         mkdir -p /tmp/yay-install
  30.         cd /tmp/yay-install
  31.        
  32.         # Como root, precisamos fazer isso diferente
  33.         sudo -u nobody git clone https://aur.archlinux.org/yay.git || {
  34.             echo "⚠️  Erro ao clonar yay. Instalando pacotes AUR manualmente..."
  35.             MANUAL_INSTALL=1
  36.         }
  37.     fi
  38. fi
  39.  
  40. # Instalar XRDP
  41. echo "📦 Instalando XRDP e dependências..."
  42.  
  43. if [ "$MANUAL_INSTALL" = "1" ]; then
  44.     # Instalação manual dos pacotes necessários
  45.     pacman -S --needed --noconfirm openssh
  46.     echo "⚠️  XRDP precisa ser instalado manualmente do AUR"
  47.     echo "💡 Execute após este script: yay -S xrdp xorgxrdp-devel-git"
  48.     SKIP_XRDP_CONFIG=1
  49. else
  50.     # Tentar com yay
  51.     if command_exists yay; then
  52.         echo "📦 Instalando XRDP via yay..."
  53.         yay -S --needed --noconfirm xrdp xorgxrdp-devel-git || {
  54.             echo "⚠️  Erro na instalação via yay. Continuando..."
  55.             SKIP_XRDP_CONFIG=1
  56.         }
  57.     fi
  58. fi
  59.  
  60. # Instalar dependências básicas
  61. echo "📦 Instalando dependências do sistema..."
  62. pacman -S --needed --noconfirm \
  63.     openssh \
  64.     polkit \
  65.     xorg-server \
  66.     xorg-xinit
  67.  
  68. # Configurar XRDP (apenas se foi instalado com sucesso)
  69. if [ "$SKIP_XRDP_CONFIG" != "1" ] && [ -f "/etc/xrdp/xrdp.ini" ]; then
  70.     echo "⚙️  Configurando XRDP para Hyper-V..."
  71.    
  72.     # Backup das configurações originais
  73.     cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.backup
  74.     cp /etc/xrdp/sesman.ini /etc/xrdp/sesman.ini.backup
  75.    
  76.     # Configurar para vsock (Hyper-V Enhanced Session)
  77.     sed -i 's/port=3389/port=vsock:\/\/-1:3389/g' /etc/xrdp/xrdp.ini
  78.     sed -i 's/security_layer=negotiate/security_layer=rdp/g' /etc/xrdp/xrdp.ini
  79.     sed -i 's/crypt_level=high/crypt_level=none/g' /etc/xrdp/xrdp.ini
  80.     sed -i 's/bitmap_compression=true/bitmap_compression=false/g' /etc/xrdp/xrdp.ini
  81.    
  82.     # Configurar drives compartilhados
  83.     sed -i 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' /etc/xrdp/sesman.ini
  84.    
  85.     # Habilitar serviços
  86.     systemctl enable xrdp
  87.     systemctl enable xrdp-sesman
  88.    
  89.     echo "✅ XRDP configurado com sucesso!"
  90. else
  91.     echo "⚠️  XRDP não foi configurado automaticamente"
  92. fi
  93.  
  94. # Configurar X11
  95. echo "⚙️  Configurando X11..."
  96. echo "allowed_users=anybody" > /etc/X11/Xwrapper.config
  97.  
  98. # Configurar módulo Hyper-V
  99. echo "⚙️  Configurando módulo hv_sock..."
  100. if [ ! -e /etc/modules-load.d/hv_sock.conf ]; then
  101.     echo "hv_sock" > /etc/modules-load.d/hv_sock.conf
  102. fi
  103.  
  104. # Configurar polkit para evitar prompts de senha
  105. echo "⚙️  Configurando políticas de sistema..."
  106. cat > /etc/polkit-1/rules.d/02-allow-colord.rules <<EOF
  107. polkit.addRule(function(action, subject) {
  108.     if ((action.id == "org.freedesktop.color-manager.create-device" ||
  109.          action.id == "org.freedesktop.color-manager.modify-profile" ||
  110.          action.id == "org.freedesktop.color-manager.delete-device" ||
  111.          action.id == "org.freedesktop.color-manager.create-profile" ||
  112.          action.id == "org.freedesktop.color-manager.modify-profile" ||
  113.          action.id == "org.freedesktop.color-manager.delete-profile") &&
  114.         subject.isInGroup("users"))
  115.     {
  116.         return polkit.Result.YES;
  117.     }
  118. });
  119. EOF
  120.  
  121. # Configurar PAM para XRDP
  122. echo "⚙️  Configurando autenticação..."
  123. cat > /etc/pam.d/xrdp-sesman <<EOF
  124. #%PAM-1.0
  125. auth        include     system-remote-login
  126. account     include     system-remote-login
  127. password    include     system-remote-login
  128. session     include     system-remote-login
  129. EOF
  130.  
  131. # Habilitar SSH
  132. echo "⚙️  Habilitando SSH..."
  133. systemctl enable sshd
  134.  
  135. echo ""
  136. echo "🎉 Configuração básica concluída!"
  137. echo ""
  138. echo "📋 PRÓXIMOS PASSOS:"
  139. echo ""
  140.  
  141. if [ "$SKIP_XRDP_CONFIG" = "1" ]; then
  142.     echo "1. ⚠️  Instalar XRDP manualmente:"
  143.     echo "   yay -S xrdp xorgxrdp-devel-git"
  144.     echo ""
  145.     echo "2. 🔄 Executar este script novamente após instalar XRDP"
  146.     echo ""
  147. fi
  148.  
  149. echo "3. 🖥️  Configurar .xinitrc para seu desktop environment:"
  150. echo "   echo 'exec startxfce4' > ~/.xinitrc    # Para XFCE"
  151. echo "   echo 'exec i3' > ~/.xinitrc           # Para i3"
  152. echo "   echo 'exec gnome-session' > ~/.xinitrc # Para GNOME"
  153. echo ""
  154. echo "4. 🔄 Reiniciar a VM:"
  155. echo "   sudo reboot"
  156. echo ""
  157. echo "5. 🔗 Conectar via Enhanced Session Mode no Hyper-V Manager"
  158. echo ""
  159. echo "💡 Para Hyprland (Wayland), use i3 ou outro WM X11 para XRDP!"
  160. echo ""
Advertisement
Add Comment
Please, Sign In to add comment