#!/usr/bin/env bash

set -e

echo "== 更新软件源 =="
sudo apt update
sudo apt upgrade

echo "== 安装基础工具 + SSH =="
sudo apt install -y \
  openssh-server nano rsync flex bison texinfo gawk net-tools zsh \
  libncurses-dev libtinfo-dev ncurses-term zstd unrar

echo "== 安装构建工具链 =="
sudo apt install -y \
  cmake build-essential git pkg-config ninja-build gdb \
  linux-tools-common linux-tools-generic linux-tools-$(uname -r) valgrind

echo "== 安装 Qt 基础组件 =="
sudo apt install -y \
  qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools

echo "== 安装 Qt 全量开发库 =="
QT_PKGS=$(apt-cache search '^libqt5.*-dev$' | awk '{print $1}')
sudo apt install -y $QT_PKGS

echo "== 安装 Qt 开发工具（QtCreator等） =="
sudo apt install -y \
  qttools5-dev qttools5-dev-tools qtcreator

echo "== 安装 mingw 交叉编译工具链 =="
sudo apt install -y \
  mingw-w64 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64

echo "== 安装 Python 环境 =="
sudo apt install -y \
  python3 python3-dev python3-pip python3-venv \
  python3-setuptools python3-wheel python3-distutils

echo "== 安装桌面相关组件 =="
sudo apt install -y gsettings-desktop-schemas

echo "== 启用 SSH 服务 =="
sudo systemctl enable ssh
sudo systemctl start ssh

echo "== 安装完成 =="

echo ""
echo "⚠️ 提示："
echo "1. SSH 连接时需要在麒麟系统界面允许连接"
echo "2. 如果只能单向 ping，检查防火墙设置"
echo "3. 输入法配置：ibus-setup"