#!/bin/bash

# 参数1: 文件路径
file_path="$1"

# 获取文件所属的包名
package_name=$(dpkg -S "$file_path" | cut -d: -f1 | sort | uniq)


# 检查包是否存在
if [ -z "$package_name" ]; then
    echo "Error: File $file_path does not belong to any package."
    exit 1
fi

# 检查包是否合法
if dpkg -l | grep -q "$package_name"; then
    echo "Error: Package $package_name is installed and the file belongs to it."
    exit 1
else
    echo "Package $package_name is not installed, but the file belongs to it."
    
fi
