From 3639873a6e3e6da2f571004bf0a33e0ccfff47a8 Mon Sep 17 00:00:00 2001 From: sepehr Date: Wed, 15 May 2024 15:48:43 +0330 Subject: [PATCH] Get Package Files --- README.md | 2 + Scripts/Package Files/README.md | 10 ++++ Scripts/Package Files/package-files.sh | 67 ++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 Scripts/Package Files/README.md create mode 100755 Scripts/Package Files/package-files.sh diff --git a/README.md b/README.md index 9f7b70e..8164daa 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,11 @@ You can also use each script individually. | [abs.shecan-dns-changer]() | Start and Stop the Shecan DNS like a VPN | | [abs.move-and-link]() | Move files and link to new path (old path also work) | | [abs.share-file]() | Upload Files on the http://0x0.st and get download link | +| [abs.abs-package-files]() | Get the files of a package and their size | | [abs.abs-uninstall]() | Uninstall Me | + diff --git a/Scripts/Package Files/README.md b/Scripts/Package Files/README.md new file mode 100644 index 0000000..f89ec5e --- /dev/null +++ b/Scripts/Package Files/README.md @@ -0,0 +1,10 @@ +# Package Files +## install : +``` +chmod +x package-name.sh +``` +``` +./package-name.sh zip +``` + +Get related files to a package and calculate the used size on disk. \ No newline at end of file diff --git a/Scripts/Package Files/package-files.sh b/Scripts/Package Files/package-files.sh new file mode 100755 index 0000000..8d9ea3b --- /dev/null +++ b/Scripts/Package Files/package-files.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Function to convert bytes to human-readable format +function human_readable_size() { + local size=$1 + local unit="B" + if [ $size -gt 1024 ]; then + size=$(echo "scale=0; $size / 1024" | bc) + unit="KB" + fi + if [ $size -gt 1024 ]; then + size=$(echo "scale=0; $size / 1024" | bc) + unit="MB" + fi + if [ $size -gt 1024 ]; then + size=$(echo "scale=0; $size / 1024" | bc) + unit="GB" + fi + echo "$size $unit" +} + +# Check if at least one argument is provided +if [ $# -eq 0 ]; then + echo "Error: Please provide a package name as an argument." + exit 1 +fi + +# Get the package name +package_name=$1 + +# Construct the file path +file_path="/var/lib/dpkg/info/$package_name.list" + +# Check if the file exists +if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' does not exist." + exit 1 +fi + +# Initialize variables +total_size=0 +total_count=0 + +# Table header +printf "%-50s %15s\n" "File Path" "Size" +printf "%-50s %15s\n" "---------" "----" +# Loop through each file in the list file +while IFS= read -r filename; do + # Check if the file exists and is a regular file + if [ -f "$filename" ]; then + # Get the file size + file_size=$(stat -c "%s" "$filename") + total_size=$((total_size + file_size)) + total_count=$((total_count + 1)) + + # Call human_readable_size function for size calculation + human_size=$(human_readable_size "$file_size") + + # Display file path and size in table format + printf "%-50s %15s\n" "$filename" "$human_size" + fi +done < "$file_path" + +# total count and size +total_size_human=$(human_readable_size "$total_size") +printf "\n" +echo "$total_count files, $total_size_human used."