update: implement --no-warn and --fail-warn for mp-check
This commit is contained in:
parent
d232d26b32
commit
8f1a7f5e27
@ -65,9 +65,25 @@ bad_vars=(
|
|||||||
####################
|
####################
|
||||||
## util functions ##
|
## util functions ##
|
||||||
####################
|
####################
|
||||||
|
# prints the help info
|
||||||
|
help_cmd() {
|
||||||
|
info "MatterLinux package check script (mtsc ${MTSC_VERSION})" # sourced from mtsc-common
|
||||||
|
info "Usage: ${0} <options> [archive file/source dir]"
|
||||||
|
info "Options:"
|
||||||
|
echo_color " $BOLD--fail-warn$RESET: fail on a warning"
|
||||||
|
echo_color " $BOLD--no-warn$RESET: ignore warnings"
|
||||||
|
echo
|
||||||
|
info "Licensed under GPLv3, see <https://www.gnu.org/licenses/> for more information"
|
||||||
|
}
|
||||||
|
|
||||||
# adds a new warning to the counter
|
# adds a new warning to the counter
|
||||||
add_warning(){
|
add_warning(){
|
||||||
|
[ $OPT_NO_WARN -eq 1 ] && return
|
||||||
|
|
||||||
|
warn "${1}"
|
||||||
warnc=$((warnc+1))
|
warnc=$((warnc+1))
|
||||||
|
|
||||||
|
[ $OPT_FAIL_WARN -eq 1 ] && fail_check
|
||||||
}
|
}
|
||||||
|
|
||||||
# cleans up the temp directoru
|
# cleans up the temp directoru
|
||||||
@ -123,7 +139,6 @@ check_archive(){
|
|||||||
check_ret_fail "Failed to extract the archive"
|
check_ret_fail "Failed to extract the archive"
|
||||||
|
|
||||||
info "Checking archive files"
|
info "Checking archive files"
|
||||||
set_indent
|
|
||||||
|
|
||||||
for f in "${required_files[@]}"; do
|
for f in "${required_files[@]}"; do
|
||||||
if [ ! -f "${tmpdir}/${f}" ]; then
|
if [ ! -f "${tmpdir}/${f}" ]; then
|
||||||
@ -132,9 +147,7 @@ check_archive(){
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
unset_indent
|
|
||||||
info "Checking DATA file"
|
info "Checking DATA file"
|
||||||
set_indent
|
|
||||||
|
|
||||||
for k in "${required_keys[@]}"; do
|
for k in "${required_keys[@]}"; do
|
||||||
local line_1="$(grep "^${k}=" "${tmpdir}/DATA")"
|
local line_1="$(grep "^${k}=" "${tmpdir}/DATA")"
|
||||||
@ -171,11 +184,7 @@ check_archive(){
|
|||||||
|
|
||||||
filename="${name}_${version}.mpf"
|
filename="${name}_${version}.mpf"
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
|
|
||||||
info "Checking HASHES file"
|
info "Checking HASHES file"
|
||||||
set_indent
|
|
||||||
|
|
||||||
while read l; do
|
while read l; do
|
||||||
if [ -z "${l}" ]; then
|
if [ -z "${l}" ]; then
|
||||||
@ -196,11 +205,7 @@ check_archive(){
|
|||||||
fi
|
fi
|
||||||
done < "${tmpdir}/HASHES"
|
done < "${tmpdir}/HASHES"
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
|
|
||||||
info "Checking files.tar.gz archive"
|
info "Checking files.tar.gz archive"
|
||||||
set_indent
|
|
||||||
|
|
||||||
while read p; do
|
while read p; do
|
||||||
if [ "${p:0:1}" == "." ] || [ "${p:0:1}" == "/" ]; then
|
if [ "${p:0:1}" == "." ] || [ "${p:0:1}" == "/" ]; then
|
||||||
@ -224,49 +229,31 @@ check_archive(){
|
|||||||
fi
|
fi
|
||||||
done < <(tar tf "${tmpdir}/files.tar.gz")
|
done < <(tar tf "${tmpdir}/files.tar.gz")
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
|
|
||||||
info "Checking INSTALL file"
|
info "Checking INSTALL file"
|
||||||
set_indent
|
|
||||||
|
|
||||||
if [ -f "${tmpdir}/INSTALL" ] && ! grep -q . "${tmpdir}/INSTALL"; then
|
if [ -f "${tmpdir}/INSTALL" ] && ! grep -q . "${tmpdir}/INSTALL"; then
|
||||||
warn "Package contains an empty install script"
|
add_warning "Package contains an empty install script"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
|
|
||||||
info "Checking CHANGES file"
|
info "Checking CHANGES file"
|
||||||
set_indent
|
|
||||||
|
|
||||||
if ! grep -q . "${tmpdir}/CHANGES"; then
|
if ! grep -q . "${tmpdir}/CHANGES"; then
|
||||||
warn "Changes file is empty"
|
add_warning "Changes file is empty"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
|
|
||||||
info "Checking archive name"
|
info "Checking archive name"
|
||||||
set_indent
|
|
||||||
|
|
||||||
archivefile="$(basename "${archivepath}")"
|
archivefile="$(basename "${archivepath}")"
|
||||||
|
|
||||||
if [ "${archivefile}" != "${filename}" ]; then
|
if [ "${archivefile}" != "${filename}" ]; then
|
||||||
warn "Package archive name is not ideal (${archivefile} -> ${filename})"
|
add_warning "Package archive name is not ideal (${archivefile} -> ${filename})"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
clean_tempdir
|
clean_tempdir
|
||||||
}
|
}
|
||||||
|
|
||||||
check_source(){
|
check_source(){
|
||||||
info "Checking the package script"
|
info "Checking the package script"
|
||||||
set_indent
|
|
||||||
|
|
||||||
if [ ! -f "${sourcepath}/pkg.sh" ]; then
|
if [ ! -f "${sourcepath}/pkg.sh" ]; then
|
||||||
error "Package script does not exist"
|
error "Package script does not exist"
|
||||||
@ -288,8 +275,7 @@ check_source(){
|
|||||||
local line_num=0
|
local line_num=0
|
||||||
|
|
||||||
if [[ "${DESC}" == *"contains"* ]] || [[ "${DESC}" == *"provides"* ]]; then
|
if [[ "${DESC}" == *"contains"* ]] || [[ "${DESC}" == *"provides"* ]]; then
|
||||||
warn "Avoid using words such as \"contains\" or \"provides\" in the package description"
|
add_warning "Avoid using words such as \"contains\" or \"provides\" in the package description"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type INSTALL &>/dev/null; then
|
if type INSTALL &>/dev/null; then
|
||||||
@ -306,22 +292,16 @@ check_source(){
|
|||||||
|
|
||||||
for v in "${bad_vars[@]}"; do
|
for v in "${bad_vars[@]}"; do
|
||||||
if echo "${l}" | grep "${v}" &> /dev/null; then
|
if echo "${l}" | grep "${v}" &> /dev/null; then
|
||||||
warn "${v} used without parenthesis on line ${line_num}"
|
add_warning "${v} used without parenthesis on line ${line_num}"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if echo "${l}" | grep '&&' | grep -v 'cd ..' &> /dev/null; then
|
if echo "${l}" | grep '&&' | grep -v 'cd ..' &> /dev/null; then
|
||||||
warn "Unreliable use of \"&&\" on line ${line_num}"
|
add_warning "Unreliable use of \"&&\" on line ${line_num}"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
done < "${sourcepath}/pkg.sh"
|
done < "${sourcepath}/pkg.sh"
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
|
|
||||||
info "Checking the changes file"
|
info "Checking the changes file"
|
||||||
set_indent
|
|
||||||
|
|
||||||
if [ ! -f "${sourcepath}/changes.md" ]; then
|
if [ ! -f "${sourcepath}/changes.md" ]; then
|
||||||
error "Package does not contain a changes file"
|
error "Package does not contain a changes file"
|
||||||
@ -329,33 +309,73 @@ check_source(){
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! grep -q . "${sourcepath}/changes.md"; then
|
if ! grep -q . "${sourcepath}/changes.md"; then
|
||||||
warn "Changes file is empty"
|
add_warning "Changes file is empty"
|
||||||
add_warning
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success "Check was completed"
|
|
||||||
unset_indent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#################
|
#################
|
||||||
## main script ##
|
## main script ##
|
||||||
#################
|
#################
|
||||||
if [ -z "${1}" ]; then
|
OPT_FAIL_WARN=0
|
||||||
error "Please specify a package archive or source directory"
|
OPT_NO_WARN=0
|
||||||
|
OPT_TARGET=()
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $arg in
|
||||||
|
"--help")
|
||||||
|
help_cmd
|
||||||
|
exit 0 ;;
|
||||||
|
"--fail-warn")
|
||||||
|
OPT_FAIL_WARN=1 ;;
|
||||||
|
"--no-warn")
|
||||||
|
OPT_NO_WARN=1 ;;
|
||||||
|
--*)
|
||||||
|
error "Unknown option: ${arg}"
|
||||||
|
exit 1 ;;
|
||||||
|
*)
|
||||||
|
OPT_TARGET+=("${arg}") ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${OPT_TARGET}" ]; then
|
||||||
|
error "Please specify at least one package archive or a source directory, run --help for more info"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "${1}" ] && [ ! -d "${1}" ]; then
|
if [ $OPT_FAIL_WARN -eq 1 ] && [ $OPT_NO_WARN -eq 1 ]; then
|
||||||
error "Specified path is invalid"
|
error "Cannot use both of the --fail-warn and --no-warn options"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${1}" ]; then
|
info "Running mp-check with the options:"
|
||||||
archivepath="$(realpath "${1}")"
|
print " $BOLD FAIL_WARN = $(itoyn $OPT_FAIL_WARN)"
|
||||||
check_archive
|
print " $BOLD NO_WARN = $(itoyn $OPT_NO_WARN)"
|
||||||
elif [ -d "${1}" ]; then
|
|
||||||
sourcepath="$(realpath "${1}")"
|
for target in "${OPT_TARGET[@]}"; do
|
||||||
check_source
|
if [ ! -f "${target}" ] && [ ! -d "${target}" ]; then
|
||||||
fi
|
error "Specified path is invalid: ${target}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
tc="${#OPT_TARGET[@]}"
|
||||||
|
ti=0
|
||||||
|
|
||||||
|
for target in "${OPT_TARGET[@]}"; do
|
||||||
|
unset_indent
|
||||||
|
ti=$((ti + 1))
|
||||||
|
|
||||||
|
if [ -f "${target}" ]; then
|
||||||
|
info "(${ti}/${tc}) Checking the archive: ${target}"
|
||||||
|
set_indent
|
||||||
|
archivepath="$(realpath "${target}")"
|
||||||
|
check_archive
|
||||||
|
elif [ -d "${target}" ]; then
|
||||||
|
info "(${ti}/${tc}) Checking the source directory: ${target}"
|
||||||
|
set_indent
|
||||||
|
sourcepath="$(realpath "${target}")"
|
||||||
|
check_source
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
success_check
|
success_check
|
||||||
|
Loading…
Reference in New Issue
Block a user