Created
March 28, 2025 02:21
-
-
Save yumin9822/e377eb396c8e3f8a4474a814fe0e61c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ScriptName=${0##*/} | |
function print_usage() { | |
echo "Usage: $ScriptName <BDFileLocation/ISOFile> <BDINFO_TXT_NAME>" | |
echo "Example: $ScriptName \"/root/Downloads/Ray.Donovan/S1D1\" \"Ray.Donovan.S1\"" | |
echo " $ScriptName \"/root/Downloads/Ray.Donovan.S1D1.iso\" \"Ray.Donovan.S1\"" | |
echo "The output file will be saved in /root" | |
echo "Install Docker with \"wget -qO- https://get.docker.com/ | sh\"" | |
} | |
## Check the number of arguments. | |
if [ $# -ne 2 ]; then | |
print_usage | |
exit 1 | |
fi | |
LOCATION=$(realpath "$1") # 获取绝对路径 | |
BDINFO_TXT_NAME=$2 | |
MOUNT_POINT="/mnt/iso_mount" | |
MOUNTED=false | |
if [ -f "$LOCATION" ]; then | |
# The input is an ISO file, mount it | |
mkdir -p "$MOUNT_POINT" | |
if mount -o loop "$LOCATION" "$MOUNT_POINT"; then | |
LOCATION="$MOUNT_POINT" | |
MOUNTED=true | |
else | |
echo "Failed to mount ISO file. Exiting." | |
exit 1 | |
fi | |
elif [ ! -d "$LOCATION" ]; then | |
echo "Invalid input. Please provide a valid directory or ISO file." | |
exit 1 | |
fi | |
# Run BDInfo extraction, handling paths with spaces | |
docker run --rm -it \ | |
-v "$LOCATION":/mnt/bd \ | |
-v /root:/mnt/report \ | |
zoffline/bdinfocli-ng /mnt/bd /mnt/report | |
mv /root/BDINFO.bd.txt "/root/${BDINFO_TXT_NAME}.txt" | |
echo "The report is generated at \"/root/${BDINFO_TXT_NAME}.txt\"" | |
# Unmount if mounted | |
if [ "$MOUNTED" = true ]; then | |
umount "$MOUNT_POINT" | |
rmdir "$MOUNT_POINT" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment