From ec9781a5b65ce88173baca3be13972efc2494c34 Mon Sep 17 00:00:00 2001 From: ngn Date: Sun, 25 Aug 2024 14:56:58 +0300 Subject: [PATCH] update: better version and empty root directory checking for mp-build and mp-check --- Makefile | 2 +- mp-build/scripts/mp-build.sh | 9 +++++-- mp-check/main.sh | 50 ++++++++++++++++++++++++++++++++++++ mtsc-common/common.sh | 11 ++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ed45e48..02649a7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ SUBDIRS := $(wildcard */.) -VERSION = 24.07 +VERSION = 24.08 install: @for dir in $(SUBDIRS) ; do \ diff --git a/mp-build/scripts/mp-build.sh b/mp-build/scripts/mp-build.sh index a73a598..ff4c0d1 100755 --- a/mp-build/scripts/mp-build.sh +++ b/mp-build/scripts/mp-build.sh @@ -110,7 +110,7 @@ clean_dist() { rm -f "${distpath}/files.tar.gz" } -# install a list of packages with matt +# install a list of packages with matt matt_install(){ if [ "$EUID" -ne 0 ]; then if type doas > /dev/null; then @@ -122,7 +122,7 @@ matt_install(){ return 1 fi fi - + $DOAS matt install --yes --skip --ignore-none $@ return $? } @@ -421,6 +421,11 @@ mkdir -p "${distpath}" clean_dist # build the files archive +if [ -z "$(ls -A)" ]; then + error "Root directory is empty, did something went wrong during build?" + exit 1 +fi + find . -printf "%P\n" | fakeroot tar -czf "${distpath}/files.tar.gz" --no-recursion -T - check_ret "(1/6) Failed to create the files archive (files.tar.gz)" success "(1/6) Created the files archive (files.tar.gz)" diff --git a/mp-check/main.sh b/mp-check/main.sh index 50d7a7f..9d038b3 100755 --- a/mp-check/main.sh +++ b/mp-check/main.sh @@ -174,6 +174,26 @@ check_archive(){ fail_check fi fi + + if [ "${k}" == "size" ]; then + if [ ! -z "${line_1}" ]; then + size="$(echo "${line_1}" | sed 's/size= //g')" + size="$(echo "${size}" | sed 's/size=//g')" + else + size="$(echo "${line_2}" | sed 's/size = //g')" + size="$(echo "${size}" | sed 's/size =//g')" + fi + + if [ -z "${size}" ]; then + error "Failed to obtain package size information" + fail_check + fi + + if [ "${size}" == "0" ]; then + error "Package size information is set as 0, is the package empty?" + fail_check + fi + fi done name="$(head -n1 "${tmpdir}/DATA" | sed 's/\[//g')" @@ -184,6 +204,24 @@ check_archive(){ fail_check fi + case "${name}" in + *_*) + error "Package name contains an invalid character: \"_\"" + fail_check ;; + *" "*) + error "Package name contains an invalid character: \" \"" + fail_check ;; + esac + + case "${version}" in + *_*) + error "Package version contains an invalid character: \"_\"" + fail_check ;; + *" "*) + error "Package version contains an invalid character: \" \"" + fail_check ;; + esac + filename="${name}_${version}.mpf" info "Checking HASHES file" @@ -208,8 +246,15 @@ check_archive(){ done < "${tmpdir}/HASHES" info "Checking files.tar.gz archive" + filec=0 while read p; do + if [ -z "${p}" ]; then + continue + fi + + filec=$((filec + 1)) + if [ "${p:0:1}" == "." ] || [ "${p:0:1}" == "/" ]; then error "Root file location is invalid (${p:0:1})" fail_check @@ -231,6 +276,11 @@ check_archive(){ fi done < <(tar tf "${tmpdir}/files.tar.gz") + if [ "${filec}" == "0" ]; then + error "Package file archive is empty (no files)" + fail_check + fi + info "Checking INSTALL file" if [ -f "${tmpdir}/INSTALL" ] && ! grep -q . "${tmpdir}/INSTALL"; then diff --git a/mtsc-common/common.sh b/mtsc-common/common.sh index 5e2e548..6db460c 100755 --- a/mtsc-common/common.sh +++ b/mtsc-common/common.sh @@ -228,6 +228,17 @@ check_pkg_vars() { return 1 ;; esac + case "${VERSION}" in + *_*) + error "Package version contains an invalid character: \"_\"" + unset_indent + return 1 ;; + *" "*) + error "Package version contains an invalid character: \" \"" + unset_indent + return 1 ;; + esac + return 0 }