changeset 2:a75581c89dde

validation and help message.
author Robert McIntyre <rlm@mit.edu>
date Tue, 08 Jan 2013 12:48:59 +0000
parents d6bef198ae71
children 9ff0fcf34920
files defaults/hg-wrapper.pl org/pkg.org src/pkg-history.pl src/pkg-report.pl src/pkg.pl
diffstat 2 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/pkg.org	Tue Jan 08 11:45:01 2013 +0000
     1.2 +++ b/org/pkg.org	Tue Jan 08 12:48:59 2013 +0000
     1.3 @@ -36,7 +36,7 @@
     1.4  (this commits as the emacs user)
     1.5  
     1.6  3. can examine provenance of information
     1.7 -$ pkg-examine emacs
     1.8 +$ pkg-report emacs
     1.9     > package emacs owns the following files:
    1.10     >  emacs
    1.11     >  man/emacs 
     2.1 --- a/src/pkg.pl	Tue Jan 08 11:45:01 2013 +0000
     2.2 +++ b/src/pkg.pl	Tue Jan 08 12:48:59 2013 +0000
     2.3 @@ -0,0 +1,52 @@
     2.4 +#!/usr/bin/env perl
     2.5 +
     2.6 +if ($ARGV[0] eq "--help"){
     2.7 +  print <<"HERE";
     2.8 +
     2.9 +pkg -- create a package user.
    2.10 +
    2.11 +syntax:
    2.12 +  pkg package-name description
    2.13 +  pkg --help 
    2.14 +
    2.15 +Create a package user for the purpose of compiling
    2.16 +a particular package.
    2.17 +
    2.18 +The user will be created with user and group both
    2.19 +equal to the name you specify.
    2.20 +
    2.21 +You will then be put into the user's home
    2.22 +directory where you may proceed with
    2.23 +compiling/installation of the package.
    2.24 +
    2.25 +If the user already exists, this is equivalent to 
    2.26 +  su package-name; cd ~; 
    2.27 +
    2.28 +Written by Robert McIntyre. This software is free
    2.29 +software and is released to the public domain.
    2.30 +  
    2.31 +HERE
    2.32 +exit 0;
    2.33 +}
    2.34 +
    2.35 +
    2.36 +$pkg_name = $ARGV[0];
    2.37 +
    2.38 +$pkg_desc = $ARGV[1];
    2.39 +
    2.40 +# Validate pkg_user as a user name.
    2.41 +if (!($pkg_name =~ m/^[A-Za-z][A-Za-z0-9_-]*$/)){
    2.42 +  print "$pkg_name is not a valid user name!\n";
    2.43 +  exit 0;
    2.44 +}
    2.45 +
    2.46 +# Validate description.
    2.47 +if ($pkg_desc =~ m/:/){
    2.48 +  print "Package Description cannot contain \":\"\n";
    2.49 +  exit 0
    2.50 +}
    2.51 +
    2.52 +
    2.53 +print "name: $pkg_name\ndesc: $pkg_desc\n";
    2.54 +
    2.55 +