🧹 chore: minor improvements in the script

This commit is contained in:
eshanized
2025-01-06 23:52:40 +05:30
parent 5f2a646de2
commit 9ab885d082
2 changed files with 31 additions and 19 deletions

View File

@@ -6,7 +6,7 @@
# Date: 2024-12-27 # Date: 2024-12-27
# Description: This script fetches the list of package filenames # Description: This script fetches the list of package filenames
# from a specified GitHub repository and processes them into a clean output. # from a specified GitHub repository and processes them into a clean output.
# It also removes duplicate package names. # It also removes duplicate package names and version info.
#----------------------------------------------------------- #-----------------------------------------------------------
# GitHub API URL for the directory # GitHub API URL for the directory
@@ -15,35 +15,46 @@ repo_url="https://api.github.com/repos/Snigdha-OS/snigdhaos-core/contents/x86_64
# Output file # Output file
output_file="packages.txt" output_file="packages.txt"
# Function to install curl if not installed (for Arch Linux) # Function to check if a command is available
install_curl() { command_check() {
echo "curl is not installed. Attempting to install..." command -v "$1" &> /dev/null
}
# Function to install a package if not installed (for Arch Linux)
install_package() {
package="$1"
echo "$package is not installed. Attempting to install..."
# Check if the system is using the pacman package manager (Arch Linux) # Check if the system is using the pacman package manager (Arch Linux)
if command -v pacman &> /dev/null; then if command_check "pacman"; then
sudo pacman -Sy --noconfirm curl sudo pacman -Sy --noconfirm "$package"
else else
echo "Error: Could not detect pacman package manager. Please install curl manually." echo "Error: Could not detect pacman package manager. Please install $package manually."
exit 1 exit 1
fi fi
# Verify if curl was successfully installed # Verify if the package was successfully installed
if command -v curl &> /dev/null; then if command_check "$package"; then
echo "curl has been installed successfully." echo "$package has been installed successfully."
else else
echo "Error: Failed to install curl. Please install it manually." echo "Error: Failed to install $package. Please install it manually."
exit 1 exit 1
fi fi
} }
# Function to fetch and process the package list (only package names, with duplicates removed) # Function to fetch and process the package list (only package names, with duplicates removed and version removed)
fetch_packages() { fetch_packages() {
# Check if curl is installed # Ensure curl and jq are installed
if ! command -v curl &> /dev/null; then if ! command_check "curl"; then
install_curl install_package "curl"
fi fi
# Fetch the directory content from the GitHub API, extract package names, remove duplicates if ! command_check "jq"; then
install_package "jq"
fi
# Fetch the directory content from the GitHub API, extract package names, remove version and duplicates
echo "Fetching package list from GitHub repository..."
curl -s "$repo_url" | \ curl -s "$repo_url" | \
jq -r '.[].name' | \ jq -r '.[].name' | \
grep -oP '^[^/]+(?=-[0-9]+-[a-z0-9]+\.pkg\.tar\.zst)' | \ grep -oP '^[^/]+(?=-[0-9]+-[a-z0-9]+\.pkg\.tar\.zst)' | \
@@ -52,12 +63,12 @@ fetch_packages() {
# Check if the output file is generated successfully # Check if the output file is generated successfully
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Generated $output_file with package names (duplicates removed)." echo "Generated $output_file with package names (duplicates and versions removed)."
else else
echo "Error: Failed to generate the package list." echo "Error: Failed to generate the package list."
exit 1 exit 1
fi fi
} }
# Run the function # Run the function to fetch and process packages
fetch_packages fetch_packages

View File

@@ -1,3 +1,4 @@
snigdhaos-asian-fonts-r331.bdb761c5 snigdhaos-asian-fonts-r331.bdb761c5
snigdhaos-grub-theme-r15.3e36d6c
snigdhaos-keyring-r332.68a02606 snigdhaos-keyring-r332.68a02606
snigdhaos-mirrorlist-r331.bdb761c5 snigdhaos-mirrorlist-r331.bdb761c5