Builder/package.sh

101 lines
2.3 KiB
Bash
Raw Normal View History

2024-09-04 17:11:37 +00:00
#!/bin/bash
# Output APKINDEX file
OUTPUT_FILE="./APKINDEX"
# Function to calculate a mock checksum
calc_checksum() {
echo -n "$1" | sha1sum | awk '{ print $1 }'
}
# Parse command-line arguments
while getopts "P:V:A:S:I:T:U:L:o:m:D:" opt; do
case ${opt} in
P) name="$OPTARG" ;;
V) version="$OPTARG" ;;
A) arch="$OPTARG" ;;
S) size="$OPTARG" ;;
I) installed_size="$OPTARG" ;;
T) description="$OPTARG" ;;
U) url="$OPTARG" ;;
L) license="$OPTARG" ;;
o) origin="$OPTARG" ;;
m) maintainer="$OPTARG" ;;
D) dependencies="$OPTARG" ;;
\?) echo "Invalid option: $OPTARG" 1>&2; exit 1 ;;
:) echo "Invalid option: $OPTARG requires an argument" 1>&2; exit 1 ;;
esac
done
# If no parameters are provided, prompt for input
if [ -z "$name" ]; then
read -p "Enter package name: " name
fi
if [ -z "$version" ]; then
read -p "Enter package version: " version
fi
if [ -z "$arch" ]; then
arch="x86_64"
fi
if [ -z "$size" ]; then
read -p "Enter package size: " size
fi
if [ -z "$installed_size" ]; then
read -p "Enter installed size: " installed_size
fi
if [ -z "$description" ]; then
read -p "Enter package description: " description
fi
if [ -z "$url" ]; then
read -p "Enter package URL: " url
fi
if [ -z "$license" ]; then
read -p "Enter license: " license
fi
if [ -z "$origin" ]; then
read -p "Enter origin: " origin
fi
if [ -z "$maintainer" ]; then
read -p "Enter maintainer: " maintainer
fi
if [ -z "$dependencies" ]; then
read -p "Enter dependencies: " dependencies
fi
# Mock package file name
pkg_file="$name-$version.apk"
# Calculate checksums based on package details
checksum=$(calc_checksum "$pkg_file")
content_checksum=$(calc_checksum "$pkg_file")
timestamp=$(date +%s)
# Remove existing entry if present
sed -i "/^P:$name$/,/^$/d" "$OUTPUT_FILE" # Ensures the removal from 'P:$name' to the first empty line.
sed -i "/^C:$checksum/d" "$OUTPUT_FILE" # Additionally, ensures all occurrences of 'C:$checksum' are removed.
# Append new entry
cat >> "$OUTPUT_FILE" << EOF
C:$checksum
P:$name
V:$version
A:$arch
S:$size
I:$installed_size
T:$description
U:$url
L:$license
o:$origin
m:$maintainer
t:$timestamp
c:$content_checksum
D:$dependencies
p:$pkg_file
q:
Z:$checksum
EOF
echo "APKINDEX has been created/updated successfully."