-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkout.sh
executable file
·132 lines (114 loc) · 3.46 KB
/
checkout.sh
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
127
128
129
130
131
132
#!/usr/bin/env bash
#
# Clones the repositories we need to run ONI and checks out a configured
# tag/sha/branch for each repository
set -eu
# Repo checkout SHAs / tags - avoid using branch names except when
# experimenting, otherwise we risk creating an unstable codebase for
# production. Note that an env variable can be used for development work,
# rather than editing this file.
openoni_checkout=${openoni_checkout:-uo-hotfix}
plugin_map_checkout=${plugin_map_checkout:-main}
plugin_staticpages_checkout=${plugin_staticpages_checkout:-v3.0.0}
plugin_calendar_checkout=${plugin_calendar_checkout:-v0.4.0}
plugin_title_locations_checkout=${plugin_title_locations_checkout:-v0.2.0}
oregononi_checkout=${oregononi_checkout:-main}
onisitemapplugin_checkout=${onisitemapplugin_checkout:-main}
force=0
if [[ ${1:-} == "--force" ]]; then
force=1
fi
# Runs a command with an attempt at more graceful error handling than we'd get
# otherwise; git spews all its output to STDERR even when everything is
# successful.
run_git_command() {
local cmd=$@
ok=1
# Make sure captured output retains newlines
IFS=' '
output=$(git $cmd 2>&1) || ok=0
unset IFS
if [[ $ok == 0 ]]; then
echo "[31;1mError[0m"
echo "> $cmd"
echo $output
exit 1
fi
echo "Success"
}
checkout() {
group=$1
project=$2
destination=$3
echo
echo "* Getting $group/$project cloned and checked out"
slug=$(echo $project | tr -cd '[[:alnum:]]_')
checkoutvar="${slug}_checkout"
# Allow undeclared vars here just so we can produce a useful message
set +u
checkout_value="${!checkoutvar}"
set -u
if [[ $checkout_value == "" ]]; then
echo "Unable to check out project $project: there is no \$$checkoutvar setting"
return
fi
if [[ ! -d $destination ]]; then
# Destination doesn't exist; just clone it
echo -n " Cloning $group/$project.git: "
# If servername is oregonnews*, don't try to clone as a privileged user
proto="git@github.com:"
hn=$(hostname)
if [[ ${hn:0:10} == "oregonnews" ]]; then
proto="https://github.com/"
fi
run_git_command clone $proto$group/$project.git $destination
else
echo " '$destination' already exists"
# Destination exists; behavior depends on $force value
if [[ $force == 1 ]]; then
# Force: fetch just in case the sha/tag/branch is new
pushd . >/dev/null
echo -n " Fetching repository for forced sync: "
cd $destination
run_git_command fetch --prune
popd >/dev/null
else
# Don't force: let user know we aren't modifying the contents of $destination
echo " Cowardly refusing to modify existing directory; use --force if you really want this"
return
fi
fi
pushd . >/dev/null
cd $destination
echo -n " Checking out $project @ $checkout_value: "
run_git_command checkout $checkout_value
popd >/dev/null
}
get_oni_plugin() {
plugin=$1
checkout open-oni plugin_$plugin $plugin
}
dest=${1:-open-oni}
if [[ $force == 1 ]]; then
dest=${2:-open-oni}
fi
dest=$(realpath $dest)
echo "ONI code will be deployed to $dest"
checkout open-oni open-oni $dest
pushd . >/dev/null
cd $dest/onisite/plugins
get_oni_plugin map
get_oni_plugin staticpages
get_oni_plugin calendar
get_oni_plugin title_locations
checkout jechols oni-sitemap-plugin sitemap
popd >/dev/null
pushd . >/dev/null
cd $dest/themes
checkout uoregon-libraries oregon-oni oregon
popd >/dev/null
if [[ $force == 1 ]]; then
./configure.sh --force $dest
else
./configure.sh $dest
fi