-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexamples_script.sh
More file actions
executable file
·126 lines (107 loc) · 3.17 KB
/
examples_script.sh
File metadata and controls
executable file
·126 lines (107 loc) · 3.17 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env sh
# set -xv
# show usage and quit
function usage()
{
printf "usage: %s <command>\n" $(basename $0) >&2
printf "\n" >&2
printf " commands are:\n"
printf " download [<version>] - downloads and mounts all example data\n" >&2
printf " gets latest version, unless <version> supplied\n" >&2
printf " initialize - download current example data if not already available\n" >&2
printf " remove - removes all example data\n" >&2
printf " version - shows current the version\n" >&2
printf " versions - list available versions\n" >&2
exit 2
}
# complain and quit
function fail_out()
{
printf "Failed! %s\n" "$@" >&2
exit 2
}
# check that we have the expected enlistment directory; download it if not
function ensure_enlistment()
{
if [ ! -d $target_path/.git ]; then
printf "no examples collection at %s; downloading ..." $target_path >&2
do_download
fi
}
# clone the git repo, don't report progress but DO report errors
function do_download()
{
if [ -d $target_path/.git ]; then
printf "examples collection already exists at %s\n" $target_path >&2
cd $target_path
git checkout main || fail_out "Couldn't reset to main"
git pull || fail_out "Couldn't update existing collection"
else
git clone --quiet $git_root_url $target_path || fail_out "Couldn't clone examples repository"
printf "examples downloaded to $target_path\n"
fi
if [ ! -z "$1" ]; then
do_checkout_version "$1"
else
cd $target_path
do_checkout_version `git describe --tags $(git rev-list --tags --max-count=1)`
fi
}
# remove the enlistment directory
function do_remove()
{
[ -d $target_path ] || fail_out "Couldn't find $target_path$root_path"
rm -rf $target_path
printf "$target_path removed\n"
}
# list all the tags we know
function do_list_versions()
{
cd $target_path
printf "local versions follow:\n"
git tag -n
printf "remote versions follow:\n"
git ls-remote --tags $git_root_url | grep -v "{}" | awk '{print $2}' | sed 's/refs\/tags\///'
printf "Version listed\n"
}
# switch version to something different
function do_checkout_version()
{
cd $target_path
printf "checkout out version %s ...\n" "$1"
git -c advice.detachedHead=false checkout "$1" || fail_out "Couldn't change versions"
printf "set to version %s\n" "$1"
}
#####
# set up the source and target info
# The :@ indicates an empty username and password
# Sometimes git prompts for username/password even though this is a public repo
# Sometimes it does not prompt. I have no idea why this started prompting sometimes.
# There doesn't seem to be another way to disable the prompt. Setting GIT_TERMINAL_PROMPT=false just makes the clone fail.
git_root_url="https://:@github.com/deephaven/examples.git"
target_path="/data/examples"
# figure out command and dispatch ...
case "$1" in
download)
do_download "$2"
;;
initialize)
ensure_enlistment
;;
version)
ensure_enlistment
cd $target_path
git describe
;;
versions)
ensure_enlistment
do_list_versions
;;
remove)
do_remove
;;
*)
printf "Unknown command '%s'\n" $1 >&2
usage
;;
esac