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