-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·81 lines (66 loc) · 2 KB
/
run.sh
File metadata and controls
executable file
·81 lines (66 loc) · 2 KB
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
#!/bin/bash
#set -ev
# Get some functions
. ./tools/parse_yaml.sh
# read parameters
eval $(parse_yaml config.yml)
projectID="${openicpsr}"
projectID="${projectID:-$dataverse}"
projectID="${projectID:-$zenodo}"
projectID="${projectID:-$osf}"
# Check if MainFile is provided from Bitbucket pipeline variable
# If provided, update config.yml and use it
if [ ! -z "$MainFile" ]; then
echo "MainFile variable detected from pipeline: $MainFile"
# Update config.yml with the new MainFile
sed -i "s|^main:.*|main: $MainFile|" config.yml
main="$MainFile"
echo "Updated config.yml with main: $main"
else
# Fall back to reading from config.yml
main="${main:-main.do}"
fi
statabin="${statabin:-stata-mp}"
rbin="${rbin:-R}"
maindir="$(dirname "$main")"
if [[ "$maindir" == "." ]]
then
# we don't have a path
fullmain="$(find $projectID -name $main)"
maindir="$(dirname "$fullmain")"
fi
ext=$(echo $main | awk -F. ' { print $2 } ')
echo "======================================================================"
echo "Active project: $projectID"
echo "Configured main file: $main"
echo "Configured subdir: $maindir"
echo "Identified extension: $ext"
echo "======================================================================"
# go into the project directory
set -ev
# show all the files
find $projectID -type f
# now go to where the main file is
echo "======================================================================"
echo "Changing directory to: $maindir"
cd "$maindir"
case $ext in
do)
if [[ -z $(which $statabin 2>/dev/null || echo "" ) ]]
then
echo "Stata not found - skipping"
exit 0
fi
$statabin -b do "$main"
[[ -f ${main%.do}.log ]] && tail -n 20 ${main%.do}.log || echo "No log file found."
;;
R|r)
if [[ -z $(which $rbin 2>/dev/null || echo "" ) ]]
then
echo "R not found - skipping"
exit 0
fi
$rbin CMD BATCH "$main"
[[ -f ${main%.R}.Rout ]] && tail -n 20 ${main%.R}.Rout || echo "No Rout file found."
;;
esac