forked from hfp/xconfigure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-get.sh
executable file
·165 lines (152 loc) · 5.46 KB
/
configure-get.sh
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
#!/usr/bin/env bash
###############################################################################
# Copyright (c) Intel Corporation - All rights reserved. #
# This file is part of the XCONFIGURE project. #
# #
# For information on the license, see the LICENSE file. #
# Further information: https://github.com/hfp/xconfigure/ #
# SPDX-License-Identifier: BSD-3-Clause #
###############################################################################
# Hans Pabst (Intel Corp.)
###############################################################################
# shellcheck disable=SC2012
BASENAME=$(command -v basename)
TIMEOUT=$(command -v timeout)
CHMOD=$(command -v chmod)
WGET=$(command -v wget)
TAIL=$(command -v tail)
SED=$(command -v gsed)
CUT=$(command -v cut)
TR=$(command -v tr)
LS=$(command -v ls)
RM=$(command -v rm)
MV=$(command -v mv)
# GNU sed is desired (macOS)
if [ ! "${SED}" ]; then
SED=$(command -v sed)
fi
TIMEOUT_ARGS="--foreground 10s"
BASEURL=https://github.com/hfp/xconfigure/raw/main/config
ERROR_NOTFOUND=8
APPLICATION=$1
#NBACKUPS=3
ARCHS=$2
KINDS=$3
if [ ! "${BASENAME}" ] || [ ! "${CHMOD}" ] || [ ! "${WGET}" ] || [ ! "${TAIL}" ] || \
[ ! "${CUT}" ] || [ ! "${TR}" ] || [ ! "${LS}" ] || [ ! "${RM}" ] || [ ! "${MV}" ];
then
>&2 echo "ERROR: prerequisites not found!"
exit 1
fi
WGET="${WGET} --no-check-certificate --no-cache"
if [ "${TIMEOUT}" ] && [ "${TIMEOUT_ARGS}" ]; then
WGET="${TIMEOUT} ${TIMEOUT_ARGS} ${WGET}"
fi
if [ ! "${APPLICATION}" ]; then
>&2 echo "Please use: $0 <application-name>"
exit 1
fi
# check if configure-get.sh was duplicated by wget
SELF=$(${LS} -1t "$0".* 2>/dev/null | tail -n1)
if [ "${SELF}" ]; then
>&2 echo "WARNING: $0 was duplicated by wget!"
${MV} "${SELF}" "$0"
chmod +x "$0"
exec "$0" "$*"
exit $?
fi
echo "Be patient, it can take up to 30 seconds before progress is shown..."
echo
if [ "$(${WGET} -q -S --spider "${BASEURL}/${APPLICATION}/README.md" 2>/dev/null | ${SED} -n '/200 OK/p')" ]; then
>&2 echo "ERROR: cannot find a recipe for application \"${APPLICATION}\"!"
exit 1
fi
MSGBUFFER=$(mktemp .configure-XXXXXX.buf)
if [ ! "${ARCHS}" ]; then
ARCHS="gnu snb hsw knl skx"
fi
if [ ! "${KINDS}" ]; then
KINDS="omp gnu gnu-omp"
for KIND in ${KINDS}; do
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/configure-${APPLICATION}-${KIND}.sh" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
done
for ARCH in ${ARCHS}; do
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/configure-${APPLICATION}-${ARCH}.sh" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
for KIND in ${KINDS}; do
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/configure-${APPLICATION}-${ARCH}-${KIND}.sh" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
done
done
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/configure-${APPLICATION}.sh" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
else
for ARCH in ${ARCHS}; do
for KIND in ${KINDS}; do
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/configure-${APPLICATION}-${ARCH}-${KIND}.sh" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
done
done
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/configure-${APPLICATION}.sh" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
fi
# attempt to get a list of non-default file names, and then download each file
if [ "${ERROR_NOTFOUND}" != "$(${WGET} -N "${BASEURL}/${APPLICATION}/.filelist" 2>"${MSGBUFFER}"; echo "$?")" ]; then
${SED} "" "${MSGBUFFER}"
fi
if [ -e .filelist ]; then
if [ "${NBACKUPS}" ] && [ "0" != "${NBACKUPS}" ]; then
BACKUP="--backups=${NBACKUPS}"
fi
ROOTDIR=${PWD}
${TR} -s " " <.filelist | \
while read -r LINE; do
FILE=$(${CUT} -d" " -f1 <<<"${LINE}")
DIR=$(${CUT} -d" " -f2 <<<"${LINE}")
if [ "${LINE}" ]; then # skip empty lines
if [ "${FILE}" != "${DIR}" ] && [ -d "${DIR}" ]; then
cd "${DIR}" || exit 1
elif [[ "${FILE}" = *".sh" ]] && [ ! "${NBACKUPS}" ]; then
FILENAME=$(${BASENAME} "${FILE}")
if [ -e "${FILENAME}" ]; then
>&2 echo "WARNING: ${FILENAME} exists hence not updated!"
continue
fi
fi
if [[ "${FILE}" =~ "://" ]]; then
eval "${WGET} -N ${BACKUP} ${FILE} 2>/dev/null"
else
eval "${WGET} -N ${BACKUP} ${BASEURL}/${APPLICATION}/${FILE} 2>/dev/null"
fi
if [ "${FILE}" != "${DIR}" ]; then
cd "${ROOTDIR}" || exit 1
else
if [[ "${FILE}" = *".git.diff" ]] && [ "$(command -v git)" ]; then
git apply "${FILE}" 2>/dev/null
fi
fi
fi
done
# cleanup list of file names
${RM} .filelist
fi
# make all scripts executable (beyond application)
${CHMOD} +x ./*.sh 2>/dev/null
# cleanup message buffer
${RM} "${MSGBUFFER}"
# cleanup old core dump files
HERE=$(cd "$(dirname "$0")" && pwd -P)
${RM} -f "${HERE}/core.*"
if [ ! "$(${LS} -1 "configure-${APPLICATION}"*.sh 2>/dev/null)" ]; then
# display reminder about build recipe
echo
echo "There is no configuration needed! Please read:"
echo "https://xconfigure.readthedocs.io/${APPLICATION}/"
fi