-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppg-clone
executable file
·52 lines (41 loc) · 1.27 KB
/
ppg-clone
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
#!/bin/bash
PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
if [[ -n "${PPG_DEBUG}" ]]; then
set -x
fi
if [ -z "$1" ]; then
echo >&2 "Need path to repository"
fi
basepath=$1
# trim trailing slash
if [[ "${basepath:${#basepath}-1:1}" = '/' ]]; then
basepath="${basepath:0:${#basepath}-1}"
fi
# trim trailing puppet.git
if [[ "${basepath:${#basepath}-11:11}" = '/puppet.git' ]]; then
basepath="${basepath:0:${#basepath}-11}"
fi
if [[ -d "/etc/puppet/.git" ]]; then
echo >&2 "ERROR: /etc/puppet is already under git (or ppg)"
echo >&2 " control, refusing to init."
exit 1
fi
echo "Cloning puppet repo from $basepath to a temporary directory"
# the main puppet config repo
git clone $basepath/puppet.git /etc/puppet.ppg.tmp.$$ || exit 1
if [[ -d /etc/puppet ]]; then
ds=$(date -u --rfc-3339=date)
echo "Backing up /etc/puppet as /etc/puppet.backup.$ds"
mv /etc/puppet /etc/puppet.backup.$ds
fi
echo "Now moving puppet dir into /etc/puppet"
mv /etc/puppet.ppg.tmp.$$ /etc/puppet
pushd /etc/puppet >/dev/null || exit 1
if ! git branch -r | grep -q 'origin/production'; then
echo "No production branch yet; staying on master"
else
git branch --track production origin/production
git checkout production
fi
popd >/dev/null