aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: e1baae052a1500ae23967ec967c0d7e37cac8d3b (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! /bin/bash
#
# Necessary preparations/configurations for the reproduction pipeline.
#
# Original author:
#     Your name <your@email.address>
# Contributing author(s):
# Copyright (C) YYYY, Your Name.
#
# 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/>.





# Top level locations
cdir=reproduce/config
pdir=$cdir/pipeline
pconf=$pdir/LOCAL.mk
ptconf=$pdir/LOCAL_tmp.mk
poconf=$pdir/LOCAL_old.mk
gconf=$cdir/gnuastro/gnuastro-local.conf





# Functions.
function add_top_notice() {
    if echo "# DO NOT EDIT MANUALLY: this is an automatically generated file." > $1
    then
        echo "#"                                                   >> $1
        echo "# This file is generated from the reproduction"      >> $1
        echo "# pipeline's './configure' script. Please re-run"    >> $1
        echo "# that command."                                     >> $1
    else
        exit 1
    fi
}





# If `LOCAL.mk' already exists, then copy it to an `.old' file.
if [ -f $pconf ]; then
    if mv $pconf $poconf; then
        echo
        echo "-------"
        echo "WARNING"
        echo "-------"
        echo "  Existing configuration moved to '$poconf'."
        echo
        echo
    else
        exit 1
    fi
fi





# Using the base file, prepare the output file.
cp $pconf.in $ptconf





# Tell the user to edit the directories.
echo
echo "-----------------------------------------"
echo "Reproduction pipeline local configuration"
echo "-----------------------------------------"
echo
echo "Local settings include things like top-level directories,"
echo "or processing steps (e.g., if you want a final PDF output)."
echo
echo "Pressing 'y' will open the local settings file in an editor"
echo "so you can modify the default values if you want. Each"
echo "variable is thoroughly described in the comments (lines"
echo "starting with a '#') above it."
echo
while [ "$userread" != "y" -a "$userread" != "n" ]
do
    read -p"Edit the default local configuration (y/n)? " userread
done





# Open an editor if the user wants to edit the file.
if [ $userread = "y" ]; then

    # Open a text editor to set the given directories
    if   emacs $ptconf; then ready=1
    elif gedit $ptconf; then ready=1
    elif vi    $ptconf; then ready=1
    else
        echo
        echo "================="
        echo "IMPORTANT WARNING"
        echo "================="
        echo "No common text editor was found on this system."
        echo "Please set the values in the following files manually:"
        echo "  - $pconf"
        # --------- Delete for no Gnuastro ---------
        echo "  - $gconf"
        # ------------------------------------------
        echo "================="
        echo
        ready=0
    fi
else
    ready=1
fi




# --------- Delete for no Gnuastro ---------
# From the input file, set the Gnuastro configuration file.
mm=$(awk '$1=="MINMAPSIZE"{print $3}' $ptconf)
add_top_notice $gconf
echo "minmapsize $mm" >> $gconf
# ------------------------------------------





# Make the final file that will be used.
add_top_notice $pconf
cat $ptconf >> $pconf
rm $ptconf





# Print a final notice.
echo
if [ $ready = 1 ]; then
    echo "This reproduction pipeline has been configured for this system."
    echo "Please run the following command to start the pipeline:"
else
    echo "AFTER MANUALLY EDITING THE FILE(S) ABOVE, please run the following"
    echo "commands to run the pipeline."
fi
echo "(Replace '8' with the number of CPU threads available)"
echo
echo "    make -j8"
echo
echo "To change the configuration later, please re-run './configure',"
echo "DO NOT manually edit the relevant files."
echo