#!/bin/sh # # High-level script to manage the project. # Run `./project --help' for a description of how to use it. # # Copyright (C) 2019-2020 Mohammad Akhlaghi # # This program 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 program 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Basic settings # -------------- # Stop the script if there are any errors. set -e # Default option values jobs=0 # 0 is for the default for the `configure.sh' script. group= debug= host_cc=0 operation= build_dir= input_dir= check_config= make_targets= software_dir= clean_texdir=0 prepare_redo=0 existing_conf=0 scriptname="./project" minmapsize=10000000000 # Parse the options # ----------------- # # Separate command-line arguments from options. Then put the option value # into the respective variable. # # Each option has two lines because we want to process both these formats: # `--name=value' and `--name value'. The former (with `=') is a single # command-line argument, so we just need to shift the counter by one. The # latter (without `=') is two arguments, so we'll need two shifts. # # Note on the case strings: for every option, we need three lines: one when # the option name and value are separate. Another when there is an equal # between them, and finally one where the value is immediately after the # short-format. This exact order is important. Otherwise, there will be a # conflict between them. print_help() { # Print the output. cat < /dev/null > /dev/null; then coloropt="--color=auto" elif ls -G 2> /dev/null > /dev/null; then coloropt="-G" else coloropt="" fi # Print a notice to let the user know what is happening. cat < /dev/null" &> /dev/null; then echo "$scriptname: '$group' is not a usable group name on this system."; echo "(TIP: you can use the 'groups' command to see your groups)" exit 1 fi # Set the group option for running Make. gopt="reproducible_paper_group_name=$group" fi # Run operations in controlled environment # ---------------------------------------- controlled_env() { # Get the full address of the build directory: bdir=`.local/bin/realpath .build` # Remove all existing environment variables (with `env -i') and only # use some pre-defined environment variables, then build the project. envmake=".local/bin/env -i HOME=$bdir sys_rm=$(which rm) $gopt" envmake="$envmake .local/bin/make --no-builtin-rules" envmake="$envmake --no-builtin-variables -f $1" if ! [ x"$debug" = x ]; then envmake="$envmake --debug=$debug"; fi # Set the number of jobs. Note that for the `configure.sh' script the # default value has to be 0, so the default is the maximum number of # threads. But here, the default value is 1. if ! [ x"$jobs" = x0 ]; then envmake="$envmake -j$jobs"; fi # Run the project if [ x"$group" = x ]; then $envmake $make_targets else # Set the group and permission flags. sg "$group" "umask $perms && $envmake $make_targets" fi } # Do requested operation # ---------------------- perms="u+r,u+w,g+r,g+w,o-r,o-w,o-x" configscript=./reproduce/software/shell/configure.sh case $operation in # Build the project's software. configure) # Set executable flags # -------------------- # # In some scenarios (for example when using a tarball from arXiv), # it may happen that the host server has removed the executable # flags of all the files. In `README.md' we instruct the readers on # setting the executable flag of this script. But we don't want the # user to have to worry about any other file that needs an # executable flag. # # Basically, all the files (shell scripts) in the two # `reproduce/*/bash' should need executable flags, so we are giving # them executable flags by default. If any other file in your project # needs such flags, add them here. chmod +x reproduce/software/shell/* reproduce/analysis/bash/* # If the user requested, clean the TeX directory from the extra # (to-be-built) directories that may already be there (and will not # allow the configuration to complete). if [ x"$clean_texdir" = x1 ]; then rm -rf tex/build tex/tikz fi # Variables to pass to the configuration script. export jobs=$jobs export host_cc=$host_cc export build_dir=$build_dir export input_dir=$input_dir export scriptname=$scriptname export minmapsize=$minmapsize export software_dir=$software_dir export existing_conf=$existing_conf export reproducible_paper_group_name=$group # Run the configuration script if [ x"$group" = x ]; then $configscript else # Set the group and permission flags. sg "$group" "umask $perms && $configscript" # Set the group writing permission for everything in the # installed software 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. echo "Enabling group writing permission on all installed software..." .local/bin/chmod -R g+w .local/; fi ;; # Run the project. make) # Make sure the configure script has been completed properly # (`configuration-done.txt' exists). if ! [ -f .build/software/configuration-done.txt ]; then cat <