From 156a9452db05f7dd961e3c6b34b7616407571437 Mon Sep 17 00:00:00 2001 From: John McQuah Date: Wed, 25 May 2022 11:36:23 -0400 Subject: [PATCH] prtcheck: initial commit --- man1/prtcheck.1 | 42 ++++++++++++++++ scripts/prtcheck | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 man1/prtcheck.1 create mode 100755 scripts/prtcheck diff --git a/man1/prtcheck.1 b/man1/prtcheck.1 new file mode 100644 index 0000000..e58046c --- /dev/null +++ b/man1/prtcheck.1 @@ -0,0 +1,42 @@ +.\" +.\" prtcheck manual page. +.\" (C) 2003 by Martin Opel +.\" +.TH prtcheck 1 +.SH NAME +prtcheck \- check the port in the current directory +.SH SYNOPSIS +.PP +.B prtcheck +[ \-\-root ] +.SH DESCRIPTION + +The \fIprtcheck\fP script checks the following things: existence of +Pkgfile, \.footprint, and \.signature. It warns, if any files with non-root +user/group appear in the \.footprint, or if any of the fields Description, URL, +Packager, "Depends on" were omitted from the Pkgfile, or if any source +needed for compiling and verifying the package is unsigned. + +\fIprtcheck\fP returns with an exit status of -1 if it encounters serious +violations of port correctness, >0 if it only finds easily-fixed violations, +and 0 if all checks were passed. + +.SH OPTIONS +The following option is supported: +.TP +.I "\--root" +This option is helpful if you create ports as a normal user. Even after +debugging those Makefiles or source code packages that try to install directly +in /usr/local or ignore DESTDIR variables, the .footprint might contain +uid/gid entries matching the uid/gid of the user who called \fIpkgmk\fP (since +\fIfakeroot\fP is no requirement in a basic CRUX installation). +\fIprtcheck\fP normally just issues a warning if it finds such uid/gid entries, +but passing the --root option lets you create a new footprint, replacing the invalid +uid/gid entries with root/root. Follow up with \fIprtverify(1)\fP to additionally +check that your port's footprint respects CRUX filesystem conventions. + +.PP +.SH AUTHORS + +\fIprtcheck\fP was written by Martin Opel for CRUX Linux, +revised by John McQuah to address FS#1763. diff --git a/scripts/prtcheck b/scripts/prtcheck new file mode 100755 index 0000000..1b8ae33 --- /dev/null +++ b/scripts/prtcheck @@ -0,0 +1,121 @@ +#!/bin/bash +# +# $Id: prtcheck,v 1.1.1.1 2003/08/27 11:43:05 opel Exp $ +# (c) 2003, Martin Opel +# revised 2022 by John McQuah to address FS#1763 +# +# Utility to check a port for existence of .signature, .footprint and +# the mandatory fields in Pkgfile. See "man 1 prtcheck" for details +# +# May be redistributed and modified under the terms of the GPL +# only usable with CRUX Linux, version 1.0 or higher +# +# USE AT YOUR OWN RISK +# + + +msg() { + echo -n -e "====> $1" +} + +warn() { + msg "WARNING: $1\n" + excode=$(( excode+1 )) +} + +error() { + msg "ERROR: $1\n" + exit -1 +} + +ok() { + msg "$(basename "$PWD") ok" +} + +get_filename() { + if [[ "$1" =~ ^(http|https|ftp|file)://.*/(.+) ]]; then + echo "${BASH_REMATCH[2]}" + else + echo "$1" + fi +} + +# +# read options +# +while [ $# -gt 0 ]; do + if [ "$1" = "--root" ]; then + convertfootprint="true" + else + error "unsupported option \"$1\"" + fi + shift +done + +((excode=0)) + +# +# Checking footprint +# +if [ ! -s .footprint ]; then + error "no footprint found or empty footprint!" +fi +if [ "$convertfootprint" = "true" ]; then + uid="$(id -nu)" + gid="$(id -ng)" + file=".footprint" + <$file sed -e "s,$uid/$gid,root/root," > $file.tmp + mv $file.tmp $file +fi +if [ "$( <.footprint cut -f 2 | grep -c -v "root/root" )" -gt 0 ]; then + warn "non-root users found!\nrun \"prtcheck --root\" to convert footprint" +fi + +# +# Checking Pkgfile +# +if [ ! -s Pkgfile ]; then + error "no Pkgfile found or Pkgfile empty!" +fi +desc="$(