-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCRIPT-1f-pull-repos
executable file
·83 lines (69 loc) · 2.6 KB
/
SCRIPT-1f-pull-repos
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
#!/bin/bash
# ----------------------------------------------------------------------
# This script is intended to be "sourced" by other scripts.
#
# The script doing the "source" must have set the variable:
# username_files
# to an array of files from which to obtain usernames
#
# This script:
# Pulls (or clones, if not yet cloned) the repositories
# for the usernames specified in the username_files.
#
# Author: David Mutchler.
# ----------------------------------------------------------------------
if [ "${username_files}" == "" ]; then
echo ""
echo "The script that SOURCED this script"
echo "failed to set the array variable"
echo " username_files"
echo "to a non-empty value."
echo "EXITING NOW, NOTHING DONE."
echo ""
exit 1
fi
# ----------------------------------------------------------------------
# Check that repositories for ALL of the usernames in the specified
# file(s) exist. Exit with a warning if not.
#
# At the same time, get the values of the variables:
# repos_folder e.g. REPOS/REPOS-csse120-202030
# repos_subfolders e.g. ( REPOS REPOS-csse120-202030 )
# repo_prefix e.g. csse120-202030-
# gitter_ssh e.g.
# gitter_repos_folder e.g. /srv/repos
# usernames e.g. (mutchler alangavr)
#
# from the relevant files.
# ----------------------------------------------------------------------
if [ "${CHECK_REPOS_MADE_HAS_RUN}" != "1" ]; then
source SCRIPT-1d-check-repos-made
fi
# ----------------------------------------------------------------------
# For each repo corresponding to a username in the usernames
# for this run, pull it (or clone it if it does not yet exist).
# ----------------------------------------------------------------------
echo ""
echo "Pulling (or cloning) the repos."
cd "${repos_folder}"
clone_command="ssh://${gitter_ssh}:${gitter_repos_folder}"
for username in ${usernames[@]}; do
repo_name="${repo_prefix}${username}"
if [ -d ${repo_name} ]; then
echo " PULLING ${username} (that is, ${repo_name})"
cd ${repo_name}
git pull
cd ..
else
echo " CLONING ${username} (that is, ${repo_name})"
git clone "${clone_command}/${repo_name}"
fi
done
# ---------------------------------------------------------------------
# Undo the CD done previously in this script.
# ---------------------------------------------------------------------
for folder in ${repos_subfolders[@]}; do
cd ..
done
PULL_REPOS_HAS_RUN=1 # For use in scripts "sourcing" this script.