aboutsummaryrefslogtreecommitdiffstats
path: root/mkhint
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-18 10:21:56 +0200
committerDanilo M. <danix@danix.xyz>2026-05-18 10:21:56 +0200
commite647c20e9f387b250469cda2b515cf767d2955a8 (patch)
tree4a4a53d03ca9e8d7e10ad604d9b3633b07c2020a /mkhint
parenta0c34e1b949a3b167685080a6776d9e404fd7923 (diff)
downloadmkhintfile-e647c20e9f387b250469cda2b515cf767d2955a8.tar.gz
mkhintfile-e647c20e9f387b250469cda2b515cf767d2955a8.zip
refactor: extract update_checksums, apply version/md5 on --new
--new with -v now sets version and recalculates md5sums via shared update_checksums function. Previously -n ignored VERSION entirely.
Diffstat (limited to 'mkhint')
-rwxr-xr-xmkhint53
1 files changed, 35 insertions, 18 deletions
diff --git a/mkhint b/mkhint
index aefc3a0..9d307f5 100755
--- a/mkhint
+++ b/mkhint
@@ -156,7 +156,7 @@ create_new_hint_file() {
# Check if file exists
if [[ ! -f "$normalized_file" ]]; then
- # the hint file we want to create doesn't exists, so we can check
+ # the hint file we want to create doesn't exists, so we can check
# the sbo repository for a .info file and use that as hint
if [[ -n $info ]]; then
cp $info $normalized_file
@@ -174,6 +174,13 @@ create_new_hint_file() {
echo 'ARCH="x86_64"' >> $normalized_file
fi
+ if [[ -n "$VERSION" ]]; then
+ local old_version
+ old_version=$(grep '^VERSION=' "$normalized_file" | sed 's/VERSION="//;s/"$//')
+ sed -i "s/${old_version}/${VERSION}/g" "$normalized_file"
+ update_checksums "$normalized_file"
+ fi
+
if [[ $NO_DL -eq 1 ]]; then
add_nodownload "$normalized_file"
fi
@@ -187,7 +194,7 @@ create_new_hint_file() {
echo "Backed up to: ${normalized_file}.bak" >&2
# Create new hint file with empty variables
cat > "$normalized_file" <<EOF
-VERSION=""
+VERSION="${VERSION}"
ARCH="x86_64"
DOWNLOAD=""
MD5SUM=""
@@ -195,7 +202,7 @@ DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
EOF
if [[ $NO_DL -eq 1 ]]; then
- sed -i '/^MD5SUM_x86_64=/a NODOWNLOAD=yes' "$normalized_file"
+ add_nodownload "$normalized_file"
fi
echo "Created new hint file [EMPTY]: $normalized_file"
@@ -211,6 +218,27 @@ add_nodownload() {
fi
}
+# Download files and update MD5SUM/MD5SUM_x86_64 in hint file
+update_checksums() {
+ local file="$1"
+
+ local download
+ download=$(grep '^DOWNLOAD=' "$file" | sed 's/DOWNLOAD="//;s/"$//')
+ if [[ -n "$download" && $download != "UNSUPPORTED" && $download != "UNTESTED" ]]; then
+ local sum
+ sum=$(download_file "$download")
+ sed -i "/^MD5SUM=/s/MD5SUM=\"[^\"]*\"/MD5SUM=\"$sum\"/" "$file"
+ fi
+
+ local download_x64
+ download_x64=$(grep '^DOWNLOAD_x86_64=' "$file" | sed 's/DOWNLOAD_x86_64="//;s/"$//')
+ if [[ -n "$download_x64" && $download_x64 != "UNSUPPORTED" && $download_x64 != "UNTESTED" ]]; then
+ local sum64
+ sum64=$(download_file "$download_x64")
+ sed -i "/^MD5SUM_x86_64=/s/MD5SUM_x86_64=\"[^\"]*\"/MD5SUM_x86_64=\"$sum64\"/" "$file"
+ fi
+}
+
# Update existing hint file
update_hint_file() {
cd "$HINT_DIR"
@@ -241,21 +269,7 @@ update_hint_file() {
# Use sed for global replacement of OLD_VERSION in all variables
sed -i "s/${old_version}/${new_version}/g" "$normalized_file"
- download=$(grep '^DOWNLOAD=' "$normalized_file" | sed 's/DOWNLOAD="//;s/"$//')
- if [[ -n "$download" ]]; then
- if [[ $download != "UNSUPPORTED" && $download != "UNTESTED" ]]; then
- sum=$(download_file ${download})
- sed -i "/^MD5SUM=/s/MD5SUM=\"[^\"]*\"/MD5SUM=\"$sum\"/" "$normalized_file"
- fi
- fi
-
- download_x64=$(grep '^DOWNLOAD_x86_64=' "$normalized_file" | sed 's/DOWNLOAD_x86_64="//;s/"$//')
- if [[ -n "$download_x64" ]]; then
- if [[ $download_x64 != "UNSUPPORTED" && $download_x64 != "UNTESTED" ]]; then
- sum64=$(download_file ${download_x64})
- sed -i "/^MD5SUM_x86_64=/s/MD5SUM_x86_64=\"[^\"]*\"/MD5SUM_x86_64=\"$sum64\"/" "$normalized_file"
- fi
- fi
+ update_checksums "$normalized_file"
if [[ $NO_DL -eq 1 ]]; then
add_nodownload "$normalized_file"
@@ -403,6 +417,9 @@ main() {
update_hint_file "$HINT_FILE" "$VERSION"
;;
new)
+ if [[ -n "$VERSION" ]]; then
+ check_wget
+ fi
create_new_hint_file "$NEW_HINT_FILE"
;;
delete)