blob: a91b438fba2e2e3999c574b74a51fb394788704f (
plain)
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
|
#!/bin/sh
# Craig Jennings <c@cjennings.net>
# updates or clones repositories for backup
REPOS_HOME="/media/backup/repositories/"
# Create REPOS_HOME dir if not exists
if [ ! -d "$REPOS_HOME" ]; then
mkdir -p "$REPOS_HOME"
fi
# Make sure REPOS_HOME dir is writable
if [ ! -w "$REPOS_HOME" ]; then
echo "Directory $REPOS_HOME is not writable."
exit 1
fi
# Make sure git is available
if ! command -v git >/dev/null 2>&1; then
echo "Git command does not exist. Please install git."
exit 1
fi
cd "$REPOS_HOME"
repos="
git@cjennings.net:archsetup.git
git@cjennings.net:dmenu.git
git@cjennings.net:dotemacs.git
git@cjennings.net:dotfiles.git
git@cjennings.net:dwm.git
git@cjennings.net:pinentry-dmenu.git
git@cjennings.net:rsyncshot.git
git@cjennings.net:st.git
git@github.com:cjennings/emacs-wttrin.git
https://github.com/d12frosted/elpa-mirror.git
https://github.com/mirrors/emacs.git
"
for repo in $repos; do
dir=$(echo "$repo" | awk -F'[/:]' '{gsub(/.git/, "", $NF); print $NF}')
# Note on the above awk command:
# awk -F'[/:]': uses awk with a regex field delimiter that matches both : and /
# which will work with both ssh and http style URLs.
# '{gsub(/.git/, "", $NF); print $NF}: This removes the ".git" postfixes from the last field ($NF)
# which leaves only the repo name.
fullpath="$REPOS_HOME$dir"
if [ -d "$fullpath" ]; then
echo "Repository $dir exists at $fullpath, pulling..."
(cd "$fullpath" && git pull)
else
echo "Repository $dir doesn't exist at $fullpath, cloning..."
cd "$REPOS_HOME" && git clone --depth 1 "$repo" "$fullpath"
fi
done
|