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 ctdas/CTDAS!3
parents 60cd867c f324bb88
...@@ -14,39 +14,47 @@ ...@@ -14,39 +14,47 @@
#!/bin/bash #!/bin/bash
set -e set -e
cat > heredocfile.txt <<_EOF_ usage="$basename "$0" [arg1] [arg2] [arg3] [-h]
where <rootdir> is a base folder for the project
where <projectsource> is a source folder for the project, to clone -- 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
and <projectclone> is a name to use for the cloned project.
where:
!! A folder rootdir/projectclone will be created !! arg1: base directory with original project (i.e., /scratch/"$USER"/)
_EOF_ arg2: original project name (i.e, test_ctdas)
arg3: cloned project name (i.e, real_ctdas_run)
while getopts "h" opt; do -h shows this help text
case $opt in
h) cat heredocfile.txt ! A new folder will then be created and populated:
exit 1
;; /scratch/"$USER"/real_ctdas_run/
\?) echo "Invalid option: -$OPTARG" >&2
exit 1 "
;;
*) cat heredocfile.txt while getopts ':hs:' option; do
exit 1 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 esac
done done
EXPECTED_ARGS=3 EXPECTED_ARGS=3
E_BADARGS=666
if [[ $# -ne $EXPECTED_ARGS ]]; then
if [ $# -ne $EXPECTED_ARGS ] printf "Missing arguments to function, need $EXPECTED_ARGS \n\n"
then echo "$usage"
echo "" exit 2
echo "Usage: `basename $0` rootdir projectsource projectclone"
cat heredocfile.txt
exit $E_BADARGS
fi fi
echo "New project to be started in folder $1" echo "New project to be started in folder $1"
echo " ...........with name $3" echo " ...........with name $3"
echo " ...........cloned from $1/$2" echo " ...........cloned from $1/$2"
...@@ -83,3 +91,4 @@ echo "" ...@@ -83,3 +91,4 @@ echo ""
cd ${rundir} cd ${rundir}
pwd 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 # Users are recommended to contact the developers (wouter.peters@wur.nl) to receive
# updates of the code. See also: http://www.carbontracker.eu. # updates of the code. See also: http://www.carbontracker.eu.
# #
...@@ -11,43 +11,49 @@ ...@@ -11,43 +11,49 @@
# You should have received a copy of the GNU General Public License along with this # You should have received a copy of the GNU General Public License along with this
# program. If not, see <http://www.gnu.org/licenses/>. # 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 #!/bin/bash
set -e set -e
echo "Welcome $USER" usage="$basename "$0" [arg1] [arg2] [-h] -- script to start a new CTDAS run
cat > heredocfile.txt <<_EOF_ where:
where <projectdir> is a base folder for the project arg1: directory to run from (i.e., /scratch/"$USER"/)
and <projectname> is a name to use for the project. arg2: project name (i.e, test_ctdas)
-h shows this help text
!! A folder projectdir/projectname will be created !!
_EOF_ ! A new folder will then be created and populated:
while getopts "h" opt; do /scratch/"$USER"/test_ctdas/
case $opt in
h) cat heredocfile.txt "
exit 1
;; while getopts ':hs:' option; do
\?) echo "Invalid option: -$OPTARG" >&2 case "$option" in
exit 1 h) echo "$usage"
;; exit
*) cat heredocfile.txt ;;
exit 1 :) 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 esac
done done
EXPECTED_ARGS=2 EXPECTED_ARGS=2
E_BADARGS=666
if [[ $# -ne $EXPECTED_ARGS ]]; then
if [ $# -ne $EXPECTED_ARGS ] printf "Missing arguments to function, need $EXPECTED_ARGS \n\n"
then echo "$usage"
echo "" exit 2
echo "Usage: `basename $0` projectdir projectname"
cat heredocfile.txt
exit $E_BADARGS
fi fi
echo "New project to be started in folder $1" echo "New project to be started in folder $1"
echo " ...........with name $2" echo " ...........with name $2"
...@@ -65,12 +71,9 @@ rsync -au --cvs-exclude * ${rundir}/ ...@@ -65,12 +71,9 @@ rsync -au --cvs-exclude * ${rundir}/
cd ${rundir} cd ${rundir}
echo "Creating jb file, py file, and rc-file" 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" templates/template.jb > $2.jb
sed -e "s/template/$2/g" template.py > $2.py sed -e "s/template/$2/g" templates/template.py > $2.py
sed -e "s,template,${rootdir},g" template.rc > $2.rc sed -e "s,template,${rootdir},g" templates/template.rc > $2.rc
rm -f template.py
rm -f template.jb
rm -f template.rc
rm -f start_ctdas.sh rm -f start_ctdas.sh
chmod u+x $2.jb chmod u+x $2.jb
...@@ -83,3 +86,4 @@ echo "" ...@@ -83,3 +86,4 @@ echo ""
cd ${rundir} cd ${rundir}
pwd pwd
Markdown is supported
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