ppg-update-production: delete stale/broken conditional
[puppet-git.git] / ppg-clone
blobf1cdf753365cfc2c21786513cee6a0e076756496
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
7 if [ -z "$1" ]; then
8 echo >&2 "Need path to repository"
9 fi
11 basepath=$1
13 # trim trailing slash
14 if [[ "${basepath:${#basepath}-1:1}" = '/' ]]; then
15 basepath="${basepath:0:${#basepath}-1}"
18 # trim trailing puppet.git
19 if [[ "${basepath:${#basepath}-11:11}" = '/puppet.git' ]]; then
20 basepath="${basepath:0:${#basepath}-11}"
23 if [[ -d "/etc/puppet/.git" ]]; then
24 echo >&2 "ERROR: /etc/puppet is already under git (or ppg)"
25 echo >&2 " control, refusing to init."
26 exit 1
29 echo "Cloning puppet and reports repos from $basepath to a temporary directory"
31 # the main puppet config repo
32 git clone $basepath/puppet.git /etc/puppet.ppg.tmp.$$ || exit 1
34 # and nested inside, reports repo
35 if ! git --git-dir /etc/puppet.ppg.tmp.$$/.ppg init ; then
36 rm -fr /etc/puppet.ppg.tmp.$$
39 ## apply configs to .git
40 echo '.ppg' >> /etc/puppet.ppg.tmp.$$/.git/info/exclude
42 ## apply configs to .ppg
43 export GIT_DIR=/etc/puppet.ppg.tmp.$$/.ppg
44 git remote add origin $basepath/reports.git
45 git config --bool core.bare false || exit 1
46 git config --path user.name "ppg" || exit 1
47 git config --path user.email "root@$(/bin/hostname -f)" || exit 1
48 git config --path core.worktree /etc/puppet/.ppg/scratch-worktree || exit 1
49 unset GIT_DIR
51 if [[ -d /etc/puppet ]]; then
52 ds=$(date -u --rfc-3339=date)
53 echo "Backing up /etc/puppet as /etc/puppet.backup.$ds"
54 mv /etc/puppet /etc/puppet.backup.$ds
56 echo "Now moving puppet and reports dirs into /etc/puppet"
57 mv /etc/puppet.ppg.tmp.$$ /etc/puppet
59 pushd /etc/puppet >/dev/null || exit 1
60 if ! git branch -r | grep -q 'origin/production'; then
61 echo "No production branch yet; staying on master"
62 else
63 git branch --track production origin/production
64 git checkout production
66 popd >/dev/null