-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_new_dataset.sh
74 lines (64 loc) · 1.78 KB
/
add_new_dataset.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
authorname=$1
biosystem=$2
current_version=$3
RmdReport="./inst/scripts/make-$authorname-$biosystem-data.Rmd"
metadataScript="./inst/scripts/make-$authorname-$biosystem-metadata.R"
downloadScript="./R/${authorname}${biosystem}Data.R"
remove_and_replace() {
rm -f $1
case $1 in
$RmdReport)
create_Rmd
;;
$metadataScript)
create_metadataScript
;;
$downloadScript)
create_downloadScript
;;
*)
echo "-add_new_dataset: $1 not understood as valid target file" 1>&2
exit 64
esac
}
make_dirs() {
mkdir --parents ./inst/scripts
mkdir --parents ./R
}
# To create the RMD report template
create_Rmd() {
local template_str=$(cat ./templates/TemplateMake.txt)
create_file_from_template $RmdReport "$template_str"
}
# To create the metadata script template
create_metadataScript() {
local template_str=$(cat ./templates/TemplateMetadata.txt)
create_file_from_template $metadataScript "$template_str"
}
# To create the R downloader script
create_downloadScript() {
local template_str=$(cat ./templates/TemplateData.txt)
create_file_from_template $downloadScript "$template_str"
}
create_file_from_template() {
local file_location=$1
local template_string=$2
eval "echo \"${template_string}\"" >> $file_location
}
# Ensures that ./inst/scripts and ./R both exist
make_dirs
# If any of the files exist, warn the user and ask if they want to overwrite or ignore
if [[ -e $RmdReport || -e metadataScript || -e downloadScript ]]; then
read -p "The files $RmdReport, $metadataScript, $downloadScript already exist.
Do you want to override them? (y/n)"
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Overwriting all files!"
remove_and_replace $RmdReport
remove_and_replace $metadataScript
remove_and_replace $downloadScript
fi
else
create_Rmd
create_metadataScript
create_downloadScript
fi