Merge branch '19164-add-flags'
[arvados.git] / tools / copy-tutorial / copy-tutorial.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 set -e -o pipefail
7
8 if test -z "$1" ; then
9   echo "$0: Copies Arvados tutorial resources from public data cluster (jutro)"
10   echo "Usage: copy-tutorial.sh <tutorial>"
11   echo "<tutorial> is which tutorial to copy, one of:"
12   echo " bwa-mem        Tutorial from https://doc.arvados.org/user/tutorials/tutorial-workflow-workbench.html"
13   echo " whole-genome   Whole genome variant calling tutorial workflow (large)"
14   exit
15 fi
16
17 if test -z "ARVADOS_API_HOST" ; then
18     echo "Please set ARVADOS_API_HOST to the destination cluster"
19     exit
20 fi
21
22 src=jutro
23 tutorial=$1
24
25 if ! test -f $HOME/.config/arvados/jutro.conf ; then
26     # Set it up with the anonymous user token.
27     echo "ARVADOS_API_HOST=jutro.arvadosapi.com" > $HOME/.config/arvados/jutro.conf
28     echo "ARVADOS_API_TOKEN=v2/jutro-gj3su-e2o9x84aeg7q005/22idg1m3zna4qe4id3n0b9aw86t72jdw8qu1zj45aboh1mm4ej" >> $HOME/.config/arvados/jutro.conf
29     exit 1
30 fi
31
32 echo
33 echo "Copying from public data cluster (jutro) to $ARVADOS_API_HOST"
34 echo
35
36 make_project() {
37     name="$1"
38     owner="$2"
39     if test -z "$owner" ; then
40         owner=$(arv --format=uuid user current)
41     fi
42     project_uuid=$(arv --format=uuid group list --filters '[["name", "=", "'"$name"'"], ["owner_uuid", "=", "'$owner'"]]')
43     if test -z "$project_uuid" ; then
44         project_uuid=$(arv --format=uuid group create --group '{"name":"'"$name"'", "group_class": "project", "owner_uuid": "'$owner'"}')
45
46     fi
47     echo $project_uuid
48 }
49
50 copy_jobs_image() {
51     if ! arv-keepdocker | grep "arvados/jobs *latest" ; then
52         arv-copy --project-uuid=$parent_project jutro-4zz18-sxmit0qs6i9n2s4
53     fi
54 }
55
56 parent_project=$(make_project "Tutorial projects")
57 copy_jobs_image
58
59 if test "$tutorial" = "bwa-mem" ; then
60     echo
61     echo "Copying bwa mem tutorial"
62     echo
63
64     arv-copy --project-uuid=$parent_project jutro-j7d0g-rehmt1w5v2p2drp
65
66     echo
67     echo "Finished, data copied to \"User guide resources\" at $parent_project"
68     echo "You can now go to Workbench and choose 'Run a process' and then select 'bwa-mem.cwl'"
69     echo
70 fi
71
72 if test "$tutorial" = "whole-genome" ; then
73     echo
74     echo "Copying whole genome variant calling tutorial"
75     echo
76
77     arv-copy --project-uuid=$parent_project jutro-j7d0g-n2g87m02rsl4cx2
78
79     echo
80     echo "Finished, data copied to \"WGS Processing Tutorial\" at $parent_project"
81     echo "You can now go to Workbench and choose 'Run a process' and then select 'WGS Processing Tutorial'"
82     echo
83 fi