comparison 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
comparison
equal deleted inserted replaced
1:d6bef198ae71 2:a75581c89dde
1 #!/usr/bin/env perl
2
3 if ($ARGV[0] eq "--help"){
4 print <<"HERE";
5
6 pkg -- create a package user.
7
8 syntax:
9 pkg package-name description
10 pkg --help
11
12 Create a package user for the purpose of compiling
13 a particular package.
14
15 The user will be created with user and group both
16 equal to the name you specify.
17
18 You will then be put into the user's home
19 directory where you may proceed with
20 compiling/installation of the package.
21
22 If the user already exists, this is equivalent to
23 su package-name; cd ~;
24
25 Written by Robert McIntyre. This software is free
26 software and is released to the public domain.
27
28 HERE
29 exit 0;
30 }
31
32
33 $pkg_name = $ARGV[0];
34
35 $pkg_desc = $ARGV[1];
36
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 }
42
43 # Validate description.
44 if ($pkg_desc =~ m/:/){
45 print "Package Description cannot contain \":\"\n";
46 exit 0
47 }
48
49
50 print "name: $pkg_name\ndesc: $pkg_desc\n";
51
52