view src/pkg.pl @ 21:d46aeb3166d0

going to work on file permissions/ownership since mercurial doesn't track them.
author Robert McIntyre <rlm@mit.edu>
date Thu, 10 Jan 2013 07:02:49 +0000
parents c75924bd38e3
children 43cfd1a2c523
line wrap: on
line source
1 #!/usr/bin/env perl
4 #this is the root of the package users' homes
5 $pkg_home_root = "/pkg";
8 if ($ARGV[0] eq "--help"){
9 print <<"HERE";
11 pkg -- create a package user.
13 syntax:
14 pkg package-name description
15 pkg --help
17 Create a package user for the purpose of compiling
18 a particular package.
20 The user will be created with user and group both
21 equal to the name you specify.
23 You will then be put into the user's home
24 directory where you may proceed with
25 compiling/installing the package.
27 If the user already exists, this is equivalent to
28 su --login package-name
30 Written by Robert McIntyre. This software is free
31 software and is released to the public domain.
33 HERE
34 exit 0;
35 }
36 $" = " ";
38 $pkg_name = $ARGV[0];
40 $pkg_desc = $ARGV[1];
42 # Validate pkg_user as a user name.
43 if (!($pkg_name =~ m/^[a-z_][a-z0-9_-]*\$?$/)){
44 print "$pkg_name is not a valid user name!\n";
45 exit 1;
46 }
48 # Validate description.
49 if ($pkg_desc =~ m/:/){
50 print "Package Description cannot contain \":\"\n";
51 exit 1;
52 }
54 $pkg_home = "$pkg_home_root/$pkg_name";
56 #set default for $pkg_desc.
57 if (!($pkg_desc)){$pkg_desc = $pkg_name;}
59 @pkg_switch_cmd = ("su", "--login", $pkg_name);
61 @pkg_create_cmd =
62 ("useradd", "-c", $pkg_desc, "-d", $pkg_home,
63 "-g", $pkg_name, "-s", "/bin/bash",
64 $pkg_name);
66 @pkg_create_group_cmd =
67 ("groupadd", "--force", $pkg_name);
69 @pkg_create_home_cmd =
70 ("install", "-d", "-g", $pkg_name, "-o", $pkg_name,
71 "-m", "755", $pkg_home);
73 @pkg_add_install_cmd =
74 ("gpasswd", "--add", $pkg_name, "install");
76 sub copy_default_file {
77 execute(("install", "-g", $pkg_name, "-o", $pkg_name,
78 "/pkg/hg-committer/$_[0]", "$pkg_home"));
79 }
82 @pkg_link_bashrc_cmd =
83 ("install", "-g", $pkg_name, "-o", $pkg_name,
84 "/pkg/hg-committer/.profile", "$pkg_home/.profile");
86 @pkg_copy_hg_wrapper_cmd =
87 ("install", "-g", "hg-wheel", "-o", "hg-committer",
88 "-m", "6111", "/pkg/hg-committer/hg-wrapper", "$pkg_home/.hg-wrapper");
90 sub execute{print "\t@_\n"; system(@_) and die $!;}
92 #determine if the user already exists:
93 `id $pkg_name 2>/dev/null`;
94 if (!$?){
95 print "Change user.\n";
96 execute(@pkg_switch_cmd); exit 0;}
98 print "Creating package group.\n";
99 execute(@pkg_create_group_cmd);
101 print "Creating package user.\n";
102 execute(@pkg_create_cmd);
104 print "Create home directory for $pkg_name.\n";
105 execute(@pkg_create_home_cmd);
107 print "Add $pkg_name to install group.\n";
108 execute(@pkg_add_install_cmd);
110 print "Copy Default Files.\n";
112 execute(@pkg_copy_hg_wrapper_cmd);
113 copy_default_file(".hgrc");
114 copy_default_file(".profile");
116 #execute(@pkg_link_bashrc_cmd);
117 #execute(@pkg_copy_hgrc_cmd);
119 print "Change user.\n";
120 execute(@pkg_switch_cmd);