Wsl2DebianEnv/init.sh

140 lines
2.7 KiB
Bash
Raw 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
# 设置错误时立即退出
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 日志函数
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 检查是否为root用户
check_root() {
if [ "$EUID" -ne 0 ]; then
log_error "请使用root权限运行此脚本"
exit 1
fi
}
# 检查系统要求
check_system_requirements() {
log_info "检查系统要求..."
# 检查内存
local total_mem=$(free -m | awk '/^Mem:/{print $2}')
if [ "$total_mem" -lt 8192 ]; then
log_warn "系统内存小于8GB可能会影响性能"
fi
# 检查磁盘空间
local free_space=$(df -m / | awk 'NR==2 {print $4}')
if [ "$free_space" -lt 51200 ]; then
log_warn "可用磁盘空间小于50GB建议清理空间"
fi
# 检查网络连接
if ! ping -c 1 8.8.8.8 &> /dev/null; then
log_error "无法连接到网络,请检查网络连接"
exit 1
fi
}
# 安装基础系统
install_base_system() {
log_info "开始安装基础系统..."
bash scripts/system/base.sh
}
# 配置镜像源
configure_mirrors() {
log_info "配置镜像源..."
bash scripts/system/mirror.sh
}
# 安装Shell环境
install_shell() {
log_info "安装Shell环境..."
bash scripts/shell/zsh.sh
bash scripts/shell/plugins.sh
}
# 安装编辑器
install_editor() {
log_info "安装编辑器..."
bash scripts/editor/neovim.sh
bash scripts/editor/nvchad.sh
}
# 安装开发工具
install_devtools() {
log_info "安装开发工具..."
bash scripts/devtools/docker.sh
bash scripts/devtools/go.sh
bash scripts/devtools/node.sh
bash scripts/devtools/python.sh
}
# 安装PHP环境
install_php() {
log_info "安装PHP环境..."
bash scripts/php/dnmp.sh
}
# 安装系统工具
install_utils() {
log_info "安装系统工具..."
bash scripts/utils/git.sh
bash scripts/utils/tools.sh
}
# 主函数
main() {
log_info "开始安装开发环境..."
# 检查root权限
check_root
# 检查系统要求
check_system_requirements
# 安装基础系统
install_base_system
# 配置镜像源
configure_mirrors
# 安装Shell环境
install_shell
# 安装编辑器
install_editor
# 安装开发工具
install_devtools
# 安装PHP环境
install_php
# 安装系统工具
install_utils
log_info "安装完成!"
log_info "请重新登录以应用所有更改。"
}
# 执行主函数
main