view src/pkg.pl @ 2:a75581c89dde

validation and help message.
author Robert McIntyre <rlm@mit.edu>
date Tue, 08 Jan 2013 12:48:59 +0000
parents 0b7a589f6e9a
children 9ff0fcf34920
line wrap: on
line source
1 #!/usr/bin/env perl
3 if ($ARGV[0] eq "--help"){
4 print <<"HERE";
6 pkg -- create a package user.
8 syntax:
9 pkg package-name description
10 pkg --help
12 Create a package user for the purpose of compiling
13 a particular package.
15 The user will be created with user and group both
16 equal to the name you specify.
18 You will then be put into the user's home
19 directory where you may proceed with
20 compiling/installation of the package.
22 If the user already exists, this is equivalent to
23 su package-name; cd ~;
25 Written by Robert McIntyre. This software is free
26 software and is released to the public domain.
28 HERE
29 exit 0;
30 }
33 $pkg_name = $ARGV[0];
35 $pkg_desc = $ARGV[1];
37 # Validate pkg_user as a user name.
38 if (!($pkg_name =~ m/^[A-Za-z][A-Za-z0-9_-]*$/)){
39 print "$pkg_name is not a valid user name!\n";
40 exit 0;
41 }
43 # Validate description.
44 if ($pkg_desc =~ m/:/){
45 print "Package Description cannot contain \":\"\n";
46 exit 0
47 }
50 print "name: $pkg_name\ndesc: $pkg_desc\n";