From 2673b12a8d00029ce474cf67a307b047876bcf96 Mon Sep 17 00:00:00 2001 From: zgqq Date: Thu, 31 Oct 2024 14:09:54 +0800 Subject: [PATCH] chore(install_server.sh): add script to detect virtualization platform and install corresponding guest services chore(install_server.sh): set system timezone to Asia/Shanghai chore(install_server.sh): update and upgrade system packages --- install_server.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 install_server.sh diff --git a/install_server.sh b/install_server.sh new file mode 100755 index 0000000..80d49a6 --- /dev/null +++ b/install_server.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# 确保以 root 身份运行 +if [ "$(id -u)" -ne 0 ]; then + echo "请以 root 权限运行此脚本,或使用 sudo。" + exit 1 +fi + +# 检测虚拟化平台 +if command -v systemd-detect-virt &> /dev/null; then + VIRT_PLATFORM=$(systemd-detect-virt) + if [ "$VIRT_PLATFORM" = "none" ]; then + echo "未检测到虚拟化环境。" + exit 1 + fi +else + echo "无法找到 systemd-detect-virt,无法检测虚拟化平台。" + exit 1 +fi + +# 根据平台安装相应的 guest service +case $VIRT_PLATFORM in + microsoft) + echo "检测到 Hyper-V 虚拟化环境。" + apt update + apt install -y linux-cloud-tools-$(uname -r) linux-tools-$(uname -r) + ;; + oracle) + echo "检测到 VirtualBox 虚拟化环境。" + apt update + apt install -y virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11 + ;; + kvm) + echo "检测到 KVM 虚拟化环境。" + apt update + apt install -y qemu-guest-agent + ;; + vmware) + echo "检测到 VMware 虚拟化环境。" + apt update + apt install -y open-vm-tools + ;; + xen) + echo "检测到 Xen 虚拟化环境。" + apt update + apt install -y xen-tools + ;; + *) + echo "虚拟化平台 $VIRT_PLATFORM 未识别,或无需安装 guest service。" + ;; +esac + +# 设置时区为上海 +timedatectl set-timezone Asia/Shanghai +echo "时区已设置为 Asia/Shanghai。" + +# 执行常用配置,例如更新系统 +apt update && apt upgrade -y + +echo "系统已更新,常用配置已应用。" \ No newline at end of file