compliance/README-WSL-Windows.md
2025-08-27 16:55:39 +08:00

158 lines
3.5 KiB
Markdown
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.

# DMS合规性测试工具 - WSL/Windows部署脚本
## 问题说明
在WSL中运行原始的 `create-compose-package-multiplatform.sh` 脚本时出现以下错误:
```bash
./create-compose-package-multiplatform.sh: line 2: $'\r': command not found
./create-compose-package-multiplatform.sh: line 6: $'\r': command not found
: invalid option-package-multiplatform.sh: line 7: set: -
```
这是由于文件使用了Windows格式的行结束符CRLF `\r\n`而Linux/WSL期望Unix格式的行结束符LF `\n`)。
## 解决方案
我们提供了三种解决方案:
### 方案1: 修复原始脚本的行结束符
运行修复脚本:
```bash
# 在WSL中运行
bash fix-line-endings.sh
```
然后运行原始脚本:
```bash
./create-compose-package-multiplatform.sh
```
### 方案2: 使用WSL优化版本
直接使用专门为WSL优化的脚本
```bash
# 在WSL中运行
bash create-compose-package-wsl.sh
```
### 方案3: 使用Windows批处理版本
在Windows命令提示符或PowerShell中运行
```cmd
create-compose-package-windows.bat
```
## 脚本特性对比
| 特性 | 原始脚本 | WSL版本 | Windows版本 |
|------|----------|---------|-------------|
| 多平台构建 | ✅ | ❌ (简化) | ❌ (简化) |
| 双服务架构 | ✅ | ❌ | ❌ |
| FastAPI支持 | ✅ | ✅ | ✅ |
| Flask支持 | ✅ | ✅ | ✅ |
| WSL兼容性 | ❌ | ✅ | N/A |
| Windows兼容性 | ❌ | ❌ | ✅ |
| 环境检测 | 基础 | 增强 | 增强 |
| 错误处理 | 基础 | 增强 | 增强 |
## 使用建议
### 在WSL环境中
1. **推荐使用WSL版本**
```bash
bash create-compose-package-wsl.sh
```
2. **或者修复原始脚本**
```bash
bash fix-line-endings.sh
./create-compose-package-multiplatform.sh
```
### 在Windows环境中
1. **使用Windows批处理版本**
```cmd
create-compose-package-windows.bat
```
2. **或者在PowerShell中使用WSL**
```powershell
wsl bash create-compose-package-wsl.sh
```
## 环境要求
### WSL环境
- Windows 10/11 with WSL2
- Docker Desktop for Windows (启用WSL集成)
- bash, tar, gzip等基础工具
### Windows环境
- Windows 10/11
- Docker Desktop for Windows
- PowerShell (用于压缩)
## 常见问题
### Q: 为什么会出现 `$'\r': command not found` 错误?
A: 这是因为文件使用了Windows格式的行结束符CRLF在Linux/WSL中被解释为命令的一部分。
### Q: 如何检查文件的行结束符格式?
A: 可以使用以下命令:
```bash
file create-compose-package-multiplatform.sh
# 或者
hexdump -C create-compose-package-multiplatform.sh | head
```
### Q: 手动修复行结束符的方法?
A: 可以使用以下任一命令:
```bash
# 使用dos2unix (推荐)
dos2unix create-compose-package-multiplatform.sh
# 使用sed
sed -i 's/\r$//' create-compose-package-multiplatform.sh
# 使用tr
tr -d '\r' < input_file > output_file
```
### Q: WSL版本和原始版本有什么区别
A: WSL版本进行了以下优化
- 增强的环境检测
- 更好的错误处理
- 简化的平台选择(专注常用平台)
- WSL特定的路径处理
- 更友好的用户界面
### Q: 如何在不同环境间传输文件?
A: 注意保持正确的行结束符格式:
- 从Windows到WSL使用 `dos2unix` 转换
- 从WSL到Windows通常不需要转换
- 使用Git时配置 `core.autocrlf` 选项
## 技术支持
如果遇到问题:
1. 检查Docker是否正常运行
2. 确认脚本有执行权限
3. 验证行结束符格式
4. 查看详细错误信息
更多帮助请查看各脚本生成的README文档。