Commit ef7d2db2 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

Merge branch 'improve_bash_help' into 'master'

The help function of the bash scripts was somewhat clunky, and has now been...

See merge request !3
parents 60cd867c f324bb88
......@@ -14,39 +14,47 @@
#!/bin/bash
set -e
cat > heredocfile.txt <<_EOF_
where <rootdir> is a base folder for the project
where <projectsource> is a source folder for the project, to clone
and <projectclone> is a name to use for the cloned project.
!! A folder rootdir/projectclone will be created !!
_EOF_
while getopts "h" opt; do
case $opt in
h) cat heredocfile.txt
exit 1
;;
\?) echo "Invalid option: -$OPTARG" >&2
exit 1
;;
*) cat heredocfile.txt
exit 1
;;
usage="$basename "$0" [arg1] [arg2] [arg3] [-h]
-- script to clone an existing CTDAS run and take aover all its settings. This allows a run to be forked, or continued separate from its origin
where:
arg1: base directory with original project (i.e., /scratch/"$USER"/)
arg2: original project name (i.e, test_ctdas)
arg3: cloned project name (i.e, real_ctdas_run)
-h shows this help text
! A new folder will then be created and populated:
/scratch/"$USER"/real_ctdas_run/
"
while getopts ':hs:' option; do
case "$option" in
h) echo "$usage"
exit
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&3
echo "$usage" >&3
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&3
echo "$usage" >&3
exit 1
;;
esac
done
EXPECTED_ARGS=3
E_BADARGS=666
if [ $# -ne $EXPECTED_ARGS ]
then
echo ""
echo "Usage: `basename $0` rootdir projectsource projectclone"
cat heredocfile.txt
exit $E_BADARGS
if [[ $# -ne $EXPECTED_ARGS ]]; then
printf "Missing arguments to function, need $EXPECTED_ARGS \n\n"
echo "$usage"
exit 2
fi
echo "New project to be started in folder $1"
echo " ...........with name $3"
echo " ...........cloned from $1/$2"
......@@ -83,3 +91,4 @@ echo ""
cd ${rundir}
pwd
# CarbonTracker Data Assimilation Shell (CTDAS) Copyright (C) 2017 Wouter Peters.
# CarbonTracker Data Assimilation Shell (CTDAS) Copyright (C) 2017,2018,2019 Wouter Peters.
# Users are recommended to contact the developers (wouter.peters@wur.nl) to receive
# updates of the code. See also: http://www.carbontracker.eu.
#
......@@ -11,43 +11,49 @@
# You should have received a copy of the GNU General Public License along with this
# program. If not, see <http://www.gnu.org/licenses/>.
# CTDAS code can be downloaded from https://git.wur.nl/woude033/test_CTDAS.git
#!/bin/bash
set -e
echo "Welcome $USER"
cat > heredocfile.txt <<_EOF_
where <projectdir> is a base folder for the project
and <projectname> is a name to use for the project.
!! A folder projectdir/projectname will be created !!
_EOF_
while getopts "h" opt; do
case $opt in
h) cat heredocfile.txt
exit 1
;;
\?) echo "Invalid option: -$OPTARG" >&2
exit 1
;;
*) cat heredocfile.txt
exit 1
;;
usage="$basename "$0" [arg1] [arg2] [-h] -- script to start a new CTDAS run
where:
arg1: directory to run from (i.e., /scratch/"$USER"/)
arg2: project name (i.e, test_ctdas)
-h shows this help text
! A new folder will then be created and populated:
/scratch/"$USER"/test_ctdas/
"
while getopts ':hs:' option; do
case "$option" in
h) echo "$usage"
exit
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
EXPECTED_ARGS=2
E_BADARGS=666
if [ $# -ne $EXPECTED_ARGS ]
then
echo ""
echo "Usage: `basename $0` projectdir projectname"
cat heredocfile.txt
exit $E_BADARGS
if [[ $# -ne $EXPECTED_ARGS ]]; then
printf "Missing arguments to function, need $EXPECTED_ARGS \n\n"
echo "$usage"
exit 2
fi
echo "New project to be started in folder $1"
echo " ...........with name $2"
......@@ -65,12 +71,9 @@ rsync -au --cvs-exclude * ${rundir}/
cd ${rundir}
echo "Creating jb file, py file, and rc-file"
sed -e "s/template/$2/g" template.jb > $2.jb
sed -e "s/template/$2/g" template.py > $2.py
sed -e "s,template,${rootdir},g" template.rc > $2.rc
rm -f template.py
rm -f template.jb
rm -f template.rc
sed -e "s/template/$2/g" templates/template.jb > $2.jb
sed -e "s/template/$2/g" templates/template.py > $2.py
sed -e "s,template,${rootdir},g" templates/template.rc > $2.rc
rm -f start_ctdas.sh
chmod u+x $2.jb
......@@ -83,3 +86,4 @@ echo ""
cd ${rundir}
pwd
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment