person-share/install_server.sh
zgqq 2673b12a8d 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
2024-10-31 14:09:54 +08:00

60 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 "系统已更新,常用配置已应用。"