-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-sync.sh
More file actions
executable file
·73 lines (62 loc) · 1.56 KB
/
git-sync.sh
File metadata and controls
executable file
·73 lines (62 loc) · 1.56 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
#!/usr/bin/env bash
main() {
case ${1} in
export)
shift
export ${@}
;;
import)
shift
import ${@}
;;
*)
echo $"usage: ${0} (export|export) profile"
exit 1
esac
}
export() {
local profile="${1}"
local repositoryCatalog="${profile}.txt"
local exportDirectory="${profile}.export"
if [[ -z ${profile} || ! -e "${repositoryCatalog}" ]]; then
echo "[ERROR] File for repository-catalog does not exist: ${repositoryCatalog}"
exit 1
fi
[[ ! -d "${exportDirectory}" ]] && mkdir "${exportDirectory}"
pushd ${exportDirectory} > /dev/null
for repository in $(cat "../${repositoryCatalog}");
do
directory=$(basename ${repository})
if [ ! -d "${directory}" ];
then
echo -e "\nClone Repository ${directory%.*}"
git clone --mirror "${repository}"
else
echo -e "\nUpdate Repository ${directory%.*}"
pushd ${directory} > /dev/null
git fetch --all
popd > /dev/null
fi
done
local exportFile="${profile}.$(date +%Y%m%d%H%M).tgz"
echo -e "\nExport Repositories to ${exportFile}"
tar czf "../${exportFile}" *.git
popd > /dev/null
}
import() {
local profile="${1}"
if [[ -z ${profile} ]]; then
echo $"[ERROR] Missing profile"
exit 1
fi
local importFile="$(ls ${profile}.*.tgz | sort | tail -n1)"
if [[ ! -f "${importFile}" ]]; then
echo $"[ERROR] No import file for profile ${profile} found"
exit 1
fi
local importDirectory="${profile}.import"
[[ ! -d "${importDirectory}" ]] && mkdir "${importDirectory}"
echo -e "\nImport Repositories from ${importFile}"
tar xzf "${importFile}" -C "${importDirectory}"
}
main ${@}