forked from nickjer/singularity-r
-
Notifications
You must be signed in to change notification settings - Fork 1
/
createproject-rstudio
executable file
·79 lines (65 loc) · 1.87 KB
/
createproject-rstudio
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
#!/usr/bin/env bash
set -ue
projectdir="$PWD"
containerdir="$(dirname "${BASH_SOURCE[0]}")"
startfilename="rstudio" # can be set arbitrarily
msg(){ echo "$@" >&2; }
help(){
cat <<EOF
Set up the working directory as project root"
Usage: createproject [options]"
Options:
--ask Show a message with the current working directory
and ask for confirmation before continuing. This is
the default.
--yes Omit the user confirmation
--help Show this message
EOF
}
# Default is to ask user
if [ "$#" = 0 ]; then set -- --ask; fi
declare ask
while [ ! "$#" = 0 ]; do
case "$1" in
--ask) ask=yes; shift; ;;
--yes) ask=no; shift; ;;
--help) help; exit 0; ;;
*)
msg "Unknown argument: '$1'. Use --help for help."
exit 1
;;
esac
done
if [ "$ask" = yes ]; then
echo "This will set up the current directory as project root:"
echo
echo " $PWD"
echo
echo "This will copy a script called '$startfilename' to this directory that"
echo "can be used to execute programs in the container."
echo -n "> Do you want to continue? [y/N]"
read answer
if [[ ! "$answer" =~ [yY] ]]; then
echo "Cancelled."
exit 1
fi
fi
if [ -e "$startfilename" ]; then
msg "File \"$startfilename\" already exists in this directory."
msg " * If you want to change the container, delete the old file."
msg " * If you want to use more than one container, edit the file manually"
msg " to link to more than one container."
exit 1
fi
while read -r line; do
if [[ "$line" =~ .*###REPLACE_HERE###.* ]]; then
echo "CONTAINER_DIR='$containerdir'"
else
echo "$line"
fi
done < "$containerdir/user-launcher-rstudio" > "$PWD/$startfilename"
chmod u+x "$startfilename"
echo "Done."
echo "Call \"./$startfilename start\" to start an RStudio instance."
echo "Call \"./$startfilename --help\" for info on more options."
echo