-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetToolVersion.sh
executable file
·176 lines (164 loc) · 5.39 KB
/
getToolVersion.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
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
#
# Organization: MDIBL
# Author: Lucie Hutchins
# Date: February 2018
# What it does:
# 1)
# a. For non git repos releases - downloads the current release Readme file (*.txt, *.html, ...)
# from the downloads site - parses it to extract the latest release number
#
# b. For git repos releases - clones the repos - extract the latest release number
# 2) sets the current release number flag
#
#
cd `dirname $0`
SCRIPT_NAME=`basename $0`
WORKING_DIR=`pwd`
GLOBAL_CONFIG=Configuration
date | tee -a ${LOG_FILE}
function displayTools() {
echo ""
echo " List of available tools"
echo "---------------------------"
tools="`ls`"
for tool in ${tools}
do
[ -d ${tool} ] && echo " ${tool}"
done
echo ""
}
echo "
***************************************
BIOCORE PACKAGE INSTALL AUTOMATION
***************************************
"
## Validate usage
if [ $# -lt 1 ]
then
echo "Usage: ./${SCRIPT_NAME} tool_name"
echo "example: ./${SCRIPT_NAME} blat"
displayTools
exit 1
fi
TOOL_NAME=$1
if [ ! -d ${TOOL_NAME} ]
then
echo "ERROR: No automation found for ${TOOL_NAME}"
echo "Check the spelling or the case sensitive"
displayTools
exit 1
fi
if [ ! -f ${GLOBAL_CONFIG} ]
then
echo "ERROR: ${GLOBAL_CONFIG} file missing under:${WORKING_DIR}"
echo "Make sure you run the ./setup.sh script first under:${WORKING_DIR}"
exit 1
fi
source ./${GLOBAL_CONFIG}
#
## Path relative to this script base
PACKAGE_CONFIG_FILE=${TOOL_NAME}/${TOOL_NAME}${PACKAGE_CONFIGFILE_SUFFIX}
if [ ! -f ${PACKAGE_CONFIG_FILE} ]
then
echo "ERROR: ${PACKAGE_CONFIG_FILE} missing under: ${WORKING_DIR}"
exit 1
fi
source ./${PACKAGE_CONFIG_FILE}
#
## Path relative to this package install base
PACKAGE_DOWNLOADS_BASE=${EXTERNAL_SOFTWARE_BASE}/${TOOL_NAME}
RELEASE_FILE=${PACKAGE_DOWNLOADS_BASE}/${CURRENT_FLAG_FILE}
[ ! -d ${PACKAGE_DOWNLOADS_BASE} ] && mkdir -p ${PACKAGE_DOWNLOADS_BASE}
## Check if wget is installed
if [ ! -f ${WGET} ]
then
echo "Can't use 'wget' command to download some of our packages "
echo "Wget not installed on `uname -n`"
exit 1
fi
## Check if git is installed
if [ ! -f ${GIT} ]
then
echo "Can't use 'git' command to download some of our packages"
echo "Git not installed on `uname -n`"
exit 1
fi
[ ! -d ${DOWNLOADS_LOG_DIR} ] && mkdir -p ${DOWNLOADS_LOG_DIR}
LOG_FILE="${DOWNLOADS_LOG_DIR}/${SCRIPT_NAME}.${TOOL_NAME}.log"
rm -rf ${LOG_FILE}
touch ${LOG_FILE}
## set release number to current value in ${RELEASE_FILE}
[ -f ${RELEASE_FILE} ] && RELEASE_NUMBER=`cat ${RELEASE_FILE}`
echo "Checking ${TOOL_NAME}'s Current Release"| tee -a ${LOG_FILE}
echo "The current version info is stored in ${RELEASE_FILE}"| tee -a ${LOG_FILE}
if [ "${CLONE_GIT}" = true ]
then
#clone repos to get current release tag
echo "-------------------------------------"
echo "Cloning repos to get current release version"
echo ""
echo ">>>>>>>> Git output starts here "
[ ! -d ${PACKAGE_GIT_CLONE_BASE} ] && mkdir -p ${PACKAGE_GIT_CLONE_BASE}
cd ${PACKAGE_GIT_CLONE_BASE}
[ ! -d ${GIT_REPOS} ] && ${GIT} clone ${REMOTE_VERSION_FILE}
if [ ! -d ${GIT_REPOS} ]
then
echo "${GIT} clone for ${REMOTE_VERSION_FILE} FAILED"| tee -a ${LOG_FILE}
exit 1
fi
cd ${GIT_REPOS}
${GIT} pull 2>&1 | tee -a ${LOG_FILE}
RELEASE_TOKEN=`${GIT} rev-list --tags --max-count=1`
RELEASE_NUMBER=`${GIT} describe --tags ${RELEASE_TOKEN}`
RELEASE_NUMBER=`echo $RELEASE_NUMBER | sed -e 's/[[:space:]]*$//' | sed -e 's/^[[:space:]]*//'`
RELEASE_NUMBER=`echo $RELEASE_NUMBER | sed -e 's/^releases\///'`
echo "<<<<<<<< Git output ends here "
echo ""
else
FILE_TOKEN=`basename ${REMOTE_VERSION_FILE}`
LOCAL_VERSION_FILE=${PACKAGE_DOWNLOADS_BASE}/${FILE_TOKEN}
echo "-------------------------------------"
echo "Using Wget to Download the release version file"| tee -a ${LOG_FILE}
echo "File to download:${REMOTE_VERSION_FILE}"| tee -a ${LOG_FILE}
echo ""
echo ">>>>>>>> Wget output starts here "
${WGET} -O ${LOCAL_VERSION_FILE} ${REMOTE_VERSION_FILE} 2>&1 | tee -a ${LOG_FILE}
echo "<<<<<<<< Wget output ends here "
echo ""
if [ ! -f ${LOCAL_VERSION_FILE} ]
then
echo "Download failed: ${LOCAL_VERSION_FILE} is missing"
exit 1
fi
EXPRESSION="$EXP_PREFIX ${LOCAL_VERSION_FILE}"
RELEASE_NUMBER=`${EXPRESSION} | grep "${VERSION_PREFIX}" |sed "s/${VERSION_PREFIX}//" `
[ "${VERSION_SUFFIX}" != "" ] && RELEASE_NUMBER=`echo ${RELEASE_NUMBER} | sed "s/${VERSION_SUFFIX}//"`
fi
echo "------------------------------"
RELEASE_NUMBER=`echo $RELEASE_NUMBER | sed -e 's/[[:space:]]*$//' | sed -e 's/^[[:space:]]*//'`
## Create the current release Number file
echo "${TOOL_NAME} release: ${RELEASE_NUMBER} detected"
if [[ ${RELEASE_NUMBER} =~ ${REPOS_TAG_PATTERN} ]]
then
rm -f ${RELEASE_FILE}
touch ${RELEASE_FILE}
echo "${RELEASE_NUMBER}" > ${RELEASE_FILE}
fi
if [ -f ${RELEASE_FILE} ]
then
RELEASE_NUMBER=`cat ${RELEASE_FILE}`
fi
cd ${WORKING_DIR}
source ./${PACKAGE_CONFIG_FILE}
echo ""
if [ -d ${PACKAGE_DOWNLOADS_BASE}/${RELEASE_DIR} ]
then
echo "WARNING"
echo " ${TOOL_NAME} version $RELEASE_NUMBER is already installed."
echo " See: ${PACKAGE_DOWNLOADS_BASE}/${RELEASE_DIR} "
echo " Remove this directory first if you want to re-install this version"
fi
echo ""| tee -a ${LOG_FILE}
echo "Program complete"| tee -a ${LOG_FILE}
exit 0