gongxiangp2/install-recovery-tools-truenas.sh

105 lines
2.8 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
# 在TrueNAS上安装数据恢复工具的脚本
# 注意:TrueNAS系统可能限制包管理器使用
set -e
echo "=========================================="
echo "TrueNAS数据恢复工具安装脚本"
echo "=========================================="
echo ""
# 检查系统类型
echo "🔍 检查系统信息..."
OS_RELEASE=$(cat /etc/os-release 2>/dev/null | grep -i "ID=" | head -1)
echo "系统: $OS_RELEASE"
echo ""
# 检查apt是否可用
if ! command -v apt-get &> /dev/null; then
echo "❌ apt-get不可用"
echo "TrueNAS系统可能禁用了包管理器"
exit 1
fi
echo "✅ apt-get可用"
echo ""
# 尝试更新包列表
echo "📦 更新包列表..."
if apt-get update -qq 2>&1 | grep -q "E:"; then
echo "⚠️ 警告: 包列表更新可能失败,但继续尝试安装"
else
echo "✅ 包列表更新成功"
fi
echo ""
# 检查testdisk是否可用
echo "🔍 检查testdisk/photorec..."
if apt-cache search testdisk 2>&1 | grep -q "testdisk"; then
echo "✅ testdisk在仓库中可用"
PACKAGE_NAME=$(apt-cache search testdisk 2>&1 | grep "^testdisk " | awk '{print $1}')
echo " 包名: $PACKAGE_NAME"
else
echo "❌ testdisk在仓库中不可用"
exit 1
fi
echo ""
# 询问是否安装
echo "⚠️ 警告:"
echo " 1. TrueNAS系统可能不推荐安装额外软件"
echo " 2. 系统更新可能会覆盖这些工具"
echo " 3. 数据恢复工具在ZFS文件系统上效果有限"
echo ""
read -p "是否继续安装testdisk/photorec? (y/N) " CONFIRM
if [ "$CONFIRM" != "y" ] && [ "$CONFIRM" != "Y" ]; then
echo "❌ 安装已取消"
exit 0
fi
echo ""
echo "📦 安装testdisk/photorec..."
if apt-get install -y testdisk 2>&1; then
echo "✅ testdisk/photorec安装成功"
else
echo "❌ 安装失败"
echo ""
echo "可能的原因:"
echo " 1. TrueNAS系统限制了包管理器"
echo " 2. 网络连接问题"
echo " 3. 软件仓库不可用"
exit 1
fi
echo ""
echo "✅ 验证安装..."
if command -v testdisk &> /dev/null; then
TESTDISK_VERSION=$(testdisk -v 2>&1 | head -1)
echo "✅ testdisk: $TESTDISK_VERSION"
else
echo "❌ testdisk未正确安装"
fi
if command -v photorec &> /dev/null; then
PHOTOREC_VERSION=$(photorec -v 2>&1 | head -1)
echo "✅ photorec: $PHOTOREC_VERSION"
else
echo "❌ photorec未正确安装"
fi
echo ""
echo "=========================================="
echo "✅ 安装完成"
echo "=========================================="
echo ""
echo "⚠️ 重要提示:"
echo " 1. ZFS文件系统限制了底层数据恢复"
echo " 2. 这些工具在ZFS上的效果可能有限"
echo " 3. 建议优先使用备份恢复或专业服务"
echo ""
echo "使用方法:"
echo " sudo photorec /dev/sdX # 需要识别正确的设备"
echo " 注意:raidz2配置需要所有硬盘才能完整恢复"