Mercurial > pkg
view src/pkg.pl @ 12:e056798af879
fixing problem with shell interpretation.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 09 Jan 2013 07:09:37 +0000 |
parents | a0c0ccd22ca5 |
children | ac1ca422bd54 |
line wrap: on
line source
1 #!/usr/bin/env perl4 #this is the root of the package users' homes5 $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 description15 pkg --help17 Create a package user for the purpose of compiling18 a particular package.20 The user will be created with user and group both21 equal to the name you specify.23 You will then be put into the user's home24 directory where you may proceed with25 compiling/installing the package.27 If the user already exists, this is equivalent to28 su --login package-name30 Written by Robert McIntyre. This software is free31 software and is released to the public domain.33 HERE34 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 }55 $pkg_home = "$pkg_home_root/$pkg_name";57 #set default for $pkg_desc.58 if (!($pkg_desc)){$pkg_desc = $pkg_name;}60 @pkg_switch_cmd = ("su", "--login", $pkg_name);62 @pkg_create_cmd =63 ("useradd", "-c", $pkg_desc, "-d", $pkg_home,64 "-g", $pkg_name, "-s", "/bin/bash",65 $pkg_name);67 @pkg_create_group_cmd =68 ("groupadd", "--force", $pkg_name);70 @pkg_create_home_cmd =71 ("install", "-d", "-g", $pkg_name, "-o", $pkg_name,72 "-m", "755", $pkg_home);74 @pkg_add_install_cmd =75 ("gpasswd", "--add", $pkg_name, "install");77 @pkg_link_bashrc_cmd =78 ("install", "-g", $pkg_name, "-o", $pkg_name,79 "/pkg/defaults/.profile", "$pkg_home/.profile");81 @pkg_copy_hg_wrapper_cmd =82 (install, "-g", "hg-wheel", "-o", "hg-committer",83 "-m", "6111", "/pkg/defaults/.hg-wrapper", $pkg_home);85 $pkg_hgrc = "[ui]\n\86 username = $pkg_name\n\87 [extensions]\n\88 hgext.purge =\n";90 $pkg_hgrc_filename = "$pkg_home/.hgrc";92 @pkg_set_hgrc_user_cmd =93 ("chown", "$pkg_name:$pkg_name", $pkg_hgrc_filename);96 sub execute{print "\t@_\n"; system(@_) and die $!;}99 #determine if the user already exists:100 `id $pkg_name 2>/dev/null`;101 if (!$?){102 print "Change user.\n";103 execute(@pkg_switch_cmd); exit 0;}105 print "Creating package group.\n";106 execute(@pkg_create_group_cmd);108 print "Creating package user.\n";109 execute(@pkg_create_cmd);111 print "Create home directory for $pkg_name.\n";112 execute(@pkg_create_home_cmd);114 print "Add $pkg_name to install group.\n";115 execute(@pkg_add_install_cmd);117 print "Copy Default Files.\n";118 execute(@pkg_link_bashrc_cmd);119 execute(@pkg_copy_hg_wrapper_cmd);121 # print "Create ~/.hgrc\n";122 # open(HGRC, ">$pkg_hgrc_filename") or die $!;123 # select HGRC;124 # print $pkg_hgrc;125 # close(HGRC);127 # select(STDOUT);128 # print "Set permissions on ~/.hgrc.\n";129 # execute(@pkg_set_hgrc_user_cmd);131 print "Change user.\n";132 execute(@pkg_switch_cmd);