annotate src/pkg.pl @ 27:738745bfa17b

remove broken files.
author Robert McIntyre <rlm@mit.edu>
date Thu, 10 Jan 2013 15:21:57 +0000
parents 5caff062fd36
children f1d0574937b5
rev   line source
rlm@2 1 #!/usr/bin/env perl
rlm@2 2
rlm@3 3
rlm@3 4 #this is the root of the package users' homes
rlm@3 5 $pkg_home_root = "/pkg";
rlm@3 6
rlm@3 7
rlm@2 8 if ($ARGV[0] eq "--help"){
rlm@2 9 print <<"HERE";
rlm@2 10
rlm@2 11 pkg -- create a package user.
rlm@2 12
rlm@2 13 syntax:
rlm@2 14 pkg package-name description
rlm@2 15 pkg --help
rlm@3 16
rlm@2 17 Create a package user for the purpose of compiling
rlm@2 18 a particular package.
rlm@2 19
rlm@2 20 The user will be created with user and group both
rlm@2 21 equal to the name you specify.
rlm@2 22
rlm@2 23 You will then be put into the user's home
rlm@2 24 directory where you may proceed with
rlm@3 25 compiling/installing the package.
rlm@2 26
rlm@2 27 If the user already exists, this is equivalent to
rlm@3 28 su --login package-name
rlm@2 29
rlm@2 30 Written by Robert McIntyre. This software is free
rlm@2 31 software and is released to the public domain.
rlm@2 32
rlm@2 33 HERE
rlm@2 34 exit 0;
rlm@2 35 }
rlm@3 36 $" = " ";
rlm@2 37
rlm@2 38 $pkg_name = $ARGV[0];
rlm@2 39
rlm@2 40 $pkg_desc = $ARGV[1];
rlm@2 41
rlm@2 42 # Validate pkg_user as a user name.
rlm@3 43 if (!($pkg_name =~ m/^[a-z_][a-z0-9_-]*\$?$/)){
rlm@2 44 print "$pkg_name is not a valid user name!\n";
rlm@3 45 exit 1;
rlm@2 46 }
rlm@2 47
rlm@2 48 # Validate description.
rlm@2 49 if ($pkg_desc =~ m/:/){
rlm@2 50 print "Package Description cannot contain \":\"\n";
rlm@3 51 exit 1;
rlm@2 52 }
rlm@2 53
rlm@3 54 $pkg_home = "$pkg_home_root/$pkg_name";
rlm@2 55
rlm@3 56 #set default for $pkg_desc.
rlm@3 57 if (!($pkg_desc)){$pkg_desc = $pkg_name;}
rlm@2 58
rlm@3 59 @pkg_switch_cmd = ("su", "--login", $pkg_name);
rlm@3 60
rlm@3 61 @pkg_create_cmd =
rlm@3 62 ("useradd", "-c", $pkg_desc, "-d", $pkg_home,
rlm@3 63 "-g", $pkg_name, "-s", "/bin/bash",
rlm@3 64 $pkg_name);
rlm@3 65
rlm@3 66 @pkg_create_group_cmd =
rlm@3 67 ("groupadd", "--force", $pkg_name);
rlm@3 68
rlm@3 69 @pkg_create_home_cmd =
rlm@7 70 ("install", "-d", "-g", $pkg_name, "-o", $pkg_name,
rlm@9 71 "-m", "755", $pkg_home);
rlm@7 72
rlm@7 73 @pkg_add_install_cmd =
rlm@7 74 ("gpasswd", "--add", $pkg_name, "install");
rlm@3 75
rlm@21 76 sub copy_default_file {
rlm@21 77 execute(("install", "-g", $pkg_name, "-o", $pkg_name,
rlm@26 78 "/pkg/skel/$_[0]", "$pkg_home"));
rlm@21 79 }
rlm@21 80
rlm@21 81
rlm@7 82 @pkg_link_bashrc_cmd =
rlm@21 83 ("install", "-g", $pkg_name, "-o", $pkg_name,
rlm@26 84 "/pkg/skel/.profile", "$pkg_home/.profile");
rlm@7 85
rlm@7 86 @pkg_copy_hg_wrapper_cmd =
rlm@25 87 ("install", "-g", "root", "-o", "root",
rlm@26 88 "-m", "6111", "/pkg/skel/hg-wrapper", "$pkg_home/.hg-wrapper");
rlm@12 89
rlm@23 90 @pkg_copy_save_acls_cmd =
rlm@23 91 ("install", "-g", "root", "-o", "root",
rlm@26 92 "-m", "6111", "/pkg/skel/save-acls", "$pkg_home/.save-acls");
rlm@23 93
rlm@12 94 sub execute{print "\t@_\n"; system(@_) and die $!;}
rlm@12 95
rlm@3 96 #determine if the user already exists:
rlm@3 97 `id $pkg_name 2>/dev/null`;
rlm@4 98 if (!$?){
rlm@4 99 print "Change user.\n";
rlm@4 100 execute(@pkg_switch_cmd); exit 0;}
rlm@3 101
rlm@3 102 print "Creating package group.\n";
rlm@3 103 execute(@pkg_create_group_cmd);
rlm@3 104
rlm@3 105 print "Creating package user.\n";
rlm@3 106 execute(@pkg_create_cmd);
rlm@3 107
rlm@3 108 print "Create home directory for $pkg_name.\n";
rlm@3 109 execute(@pkg_create_home_cmd);
rlm@3 110
rlm@7 111 print "Add $pkg_name to install group.\n";
rlm@7 112 execute(@pkg_add_install_cmd);
rlm@7 113
rlm@7 114 print "Copy Default Files.\n";
rlm@21 115
rlm@7 116 execute(@pkg_copy_hg_wrapper_cmd);
rlm@23 117 execute(@pkg_copy_save_acls_cmd);
rlm@21 118 copy_default_file(".profile");
rlm@21 119
rlm@21 120 #execute(@pkg_link_bashrc_cmd);
rlm@21 121 #execute(@pkg_copy_hgrc_cmd);
rlm@7 122
rlm@3 123 print "Change user.\n";
rlm@3 124 execute(@pkg_switch_cmd);