1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#! /bin/bash
#
# Running examples:
#
# $ ./for-group group_name configure [OPTIONS]
# $ ./for-group group_name make [OPTIONS]
#
# This is a wrapper for the configure and Make steps designed for a group
# of users (sharing the same group name) using this pipeline on the same
# build directory.
#
# When the configuration (normally done with `./configure') and build
# (normally done with `.local/bin/make') steps are done with this script,
# all the files that are created within the pipeline have these properties:
#
# 1) Group owner will be the group specified in the command-line.
# 2) The permission flags give write access to the group members.
#
# Copyright (C) 2019, Mohammad Akhlaghi <mohammad@akhlaghi.org>
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available at
# <http://www.gnu.org/licenses/>.
# Script settings
# ---------------
# Stop the script if there are any errors.
set -e
# See if any argument are given at all.
if [ "x$1" = x ]; then
echo "$0: At least two arguments are necessary:"
echo
echo " To configure: $ ./for-group group_name configure"
echo " To build: $ ./for-group group_name make"
exit 1
fi
# Prepare any other argument to pass onto the `./configure' or `make'
# commands. `$@' is the list of command-line tokens given to the this
# (`./for-group') script. Therefore, the first token in it is the group
# name and the second is the script name. As a result, we want anything
# after the third token.
options=$(echo "$@" | awk '{for(i=3;i<=NF;++i) printf("%s ", $i)}')
# Make sure the given group is usable.
if sg "$1" "echo test &> /dev/null" &> /dev/null; then
if [ "x$2" = xconfigure ]; then script="./configure"
elif [ "x$2" = xmake ]; then script=".local/bin/make"
else
echo "$0: a third argument is necessary."
echo "It specifies the action: either 'configure' or 'make'"
exit 1
fi
else
echo "$0: '$1' is not a usable group name on this system.";
echo "TIP: you can use the 'groups' command to see your groups."
exit 1
fi
# Define the group, and set the permission so the user and group both have
# read and write permissions. Then run the respective script.
#
# We are also exporting a special variable so `./configure' and Make can
# prepare for sanity checks and avoid re-doing the whole analysis with a
# typo (not using this script properly after configuration).
export reproducible_paper_group_name="$1"
sg "$1" "umask u+r,u+w,g+r,g+w,o-r,o-w,o-x && $script $options"
# Group writing permissions for dependencies directory
#
# The common build process sets the writing permissions of the installed
# programs/libraries to `755'. So group members can't write over a
# file. This creates problems when another group member wants to update the
# software for example. We thus need to manually add the group writing flag
# to all installed software files.
if [ "x$2" = xconfigure ]; then
echo "Enabling group writing permission on all installed software..."
chmod -R g+w .local/;
fi
|