Force a non-lazy run if global.ini has changed
[puppet-git.git] / ppg-clone
blob8814a2a7c4621aadccd6ee304848c82d0bb5ea11
1 #!/bin/bash
3 PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
4 export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
6 if [[ -n "${PPG_DEBUG}" ]]; then
7 set -x
8 fi
10 if [ -z "$1" ]; then
11 echo >&2 "Need path to repository"
14 basepath=$1
16 # trim trailing slash
17 if [[ "${basepath:${#basepath}-1:1}" = '/' ]]; then
18 basepath="${basepath:0:${#basepath}-1}"
21 # trim trailing puppet.git
22 if [[ "${basepath:${#basepath}-11:11}" = '/puppet.git' ]]; then
23 basepath="${basepath:0:${#basepath}-11}"
26 if [[ -d "/etc/puppet/.git" ]]; then
27 echo >&2 "ERROR: /etc/puppet is already under git (or ppg)"
28 echo >&2 " control, refusing to init."
29 exit 1
32 echo "Cloning puppet repo from $basepath to a temporary directory"
34 # the main puppet config repo
35 git clone $basepath/puppet.git /etc/puppet.ppg.tmp.$$ || exit 1
37 if [[ -d /etc/puppet ]]; then
38 ds=$(date -u --rfc-3339=date)
39 echo "Backing up /etc/puppet as /etc/puppet.backup.$ds"
40 mv /etc/puppet /etc/puppet.backup.$ds
42 echo "Now moving puppet dir into /etc/puppet"
43 mv /etc/puppet.ppg.tmp.$$ /etc/puppet
45 pushd /etc/puppet >/dev/null || exit 1
46 if ! git branch -r | grep -q 'origin/production'; then
47 echo "No production branch yet; staying on master"
48 else
49 git branch --track production origin/production
50 git checkout production
52 popd >/dev/null