按 deb 包软件实际信息修改文件名
#!/usr/bin/env bash
set -eu
if ! which dpkg-buildpackage >/dev/null 2>&1; then
echo "dpkg-dev is not installed."
exit 1
fi
FULL_FILENAME="${1}"
FILE_FOLDER=$(dirname "$FULL_FILENAME")
if [[ ! -f "$FULL_FILENAME" ]]; then
echo "file not found"
exit 1
fi
# 使用 dpkg-deb --info 获取软件包信息,并将输出通过 awk 提取所需信息
PACKAGE_INFO=$(dpkg-deb --info "$FULL_FILENAME" | awk '/Package:|Architecture:|Version:|Maintainer:/ {print}')
# 从提取的信息中获取软件包名称、版本和维护者
PACKAGE_NAME=$(echo "$PACKAGE_INFO" | awk -F ': ' '/Package:/ {print $2}')
PACKAGE_ARCH=$(echo "$PACKAGE_INFO" | awk -F ': ' '/Architecture:/ {print $2}')
PACKAGE_VERSION=$(echo "$PACKAGE_INFO" | awk -F ': ' '/Version:/ {print $2}')
MAINTAINER=$(echo "$PACKAGE_INFO" | awk -F ': ' '/Maintainer:/ {print $2}')
# 输出提取的信息
echo "Package Name: $PACKAGE_NAME"
echo "Architecture: $PACKAGE_ARCH"
echo "Version: $PACKAGE_VERSION"
echo "Maintainer: $MAINTAINER"
TARGET_FILENAME="${FILE_FOLDER}/${PACKAGE_NAME}_${PACKAGE_VERSION}_${PACKAGE_ARCH}.deb"
echo "Target Path: ${TARGET_FILENAME}"
if [[ "$FULL_FILENAME" = "$TARGET_FILENAME" ]]; then
printf "\nthe same file\n"
exit 1
fi
mv "$FULL_FILENAME" "$TARGET_FILENAME"