#!/bin/sh # xlint TEMPLATE - scan XBPS template for common mistakes export LC_ALL=C scan() { local rx="$1" msg="$2" grep -P -Hn -e "$rx" "$template" | sed "s/^\([^:]*:[^:]*:\)\(.*\)/\1 $msg/" } once() { head -n 1 } variables=$(echo -n "#.* _.* .*_descr .*_groups .*_homedir .*_pgroup .*_shell desc_option_.* AR AS CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS GCC LD LDFLAGS LD_LIBRARY_PATH NM OBJCOPY OBJDUMP RANLIB READELF STRIP allow_unknown_shlibs bootstrap broken build_options build_options_default build_pie build_style build_wrksrc checksum conf_files configure_args configure_script conflicts create_wrksrc depends depends disable_parallel_build distfiles dkms_modules font_dirs force_debug_pkgs go_import_path homepage hostmakedepends keep_libtool_archives kernel_hooks_version lib32depends lib32disabled lib32files lib32mode lib32symlinks license maintainer make_build_args make_build_target make_cmd make_dirs make_install_args make_install_target makedepends mutable_files noarch nocross nodebug noshlibprovides nostrip nostrip_files noverifyrdeps only_for_archs patch_args pkgname preserve provides pycompile_dirs pycompile_module pycompile_version python_versions register_shell replaces repository reverts revision run_depends sgml_catalogs sgml_entries shlib_provides shlib_requires short_desc skip_extraction subpackages system_accounts system_groups systemd_services tags triggers version wrksrc xml_catalogs xml_entries" | tr '\n' '|') ret=0 for template; do if [ -f "$template" ]; then scan 'short_desc=.*\."' "unwanted trailing dot in short_desc" scan 'short_desc=["'\''][a-z]' "short_desc should start uppercase" scan 'short_desc=["'\''].{72}' "short_desc should be less than 72 chars" scan 'license=.*[^L]GPL[^-]' "license GPL without version" scan 'license=.*LGPL[^-]' "license LGPL without version" if ! grep -q vlicense "$template"; then scan 'license=.*custom' "license 'custom', but no use of vlicense" fi scan 'vinstall.* usr/bin' "use vbin" scan 'vinstall.* usr/share/man' "use vman" scan 'vinstall.* usr/share/licenses' "use vlicense" scan '^ ' "indent with tabs" | once scan '[\t ]$' "trailing whitespace" scan '`' "use \$() instead of backticks" scan 'revision=0' "revision must not be zero" scan 'replaces=(?=.*\w)[^<>]*$' "replaces needs depname with version" scan 'conflicts=(?=.*\w)[^<>]*$' "conflicts needs depname with version" scan 'maintainer=(?!.*<.*@.*>).*' "maintainer needs email address" scan 'nonfree=' "use repository=nonfree" scan '^(?!\s*('"$variables"'))[^\s=-]+=' \ "custom variables should use _ prefix: \2" scan '^[^ =]*=(""|''|)$' "variable set to empty string: \2" scan 'distfiles=.*sourceforge\.net' 'use $SOURCEFORGE_SITE' scan 'distfiles=.*savannah.nongnu\.org' 'use $NONGNU_SITE' scan 'distfiles=.*archive\.ubuntu\.com' 'use $UBUNTU_SITE' scan 'distfiles=.*xorg\.freedesktop\.org' 'use $XORG_SITE' scan 'distfiles=.*(?&2 fi | sort -t: -n -k2 | grep . && ret=1 done exit $ret