Skip to content

Instantly share code, notes, and snippets.

@maddyblue
Last active August 29, 2015 14:10
Show Gist options
  • Save maddyblue/8c93d7d43cecfe5d9d4e to your computer and use it in GitHub Desktop.
Save maddyblue/8c93d7d43cecfe5d9d4e to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
base=bosun.org
gopath=$GOPATH/src
bdir=$gopath/$base
rm -rf $bdir
git init $bdir
git remote add origin git@github.com:mjibson/bosun.org.git
cd $bdir
# $1 = prefix
prefix ()
{
echo ADDING PREFIX $*
git filter-branch --index-filter '
git ls-files -s |
sed "s,\t,&'"$1"'/," |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
' --msg-filter "sed '1s/^/$1: /'" HEAD
}
# $1 = prefix
# $2 = from repo
# $3 = to repo
merge ()
{
echo MERGE $*
tmp=$HOME/tmp/$2
rm -rf $tmp
mkdir -p $tmp
echo CLONE $2
git clone -q https://$2.git $tmp
cd $tmp
prefix $1
cd $gopath/$3
echo PULL $2
git pull --no-edit -q $tmp
echo MERGEDONE
}
for i in metadata util
do
merge $i github.com/bosun-monitor/$i $base
done
for i in collect opentsdb
do
merge $i github.com/bosun-monitor/$i $base
done
for i in vsphere slog
do
merge $i github.com/StackExchange/$i $base
done
for i in scollector bosun
do
merge cmd\\/$i github.com/bosun-monitor/$i $base
done
cd $bdir
git reset -q --hard HEAD
git clean -xdfq
git rm -rf cmd/bosun/_third_party/github.com/bosun-monitor
git rm -rf cmd/scollector/_third_party/github.com/bosun-monitor
git rm -rf cmd/scollector/_third_party/github.com/StackExchange/vsphere
git rm -rf cmd/scollector/_third_party/github.com/StackExchange/slog
git rm -rf cmd/bosun/_third_party/github.com/StackExchange/slog
gos=`find $bdir -name "*.go"`
for i in vsphere slog
do
echo $i
sed -i.bak "s/\"github.com\/StackExchange/\"$base/g" $gos
sed -i.bak "s/\"github.com\/bosun-monitor\/[a-z]*\/_third_party\/github.com\/StackExchange\/$i/\"$base\/$i/g" $gos
done
for i in opentsdb collect util metadata
do
echo $i
sed -i.bak "s/\"github.com\/bosun-monitor\/bosun\/_third_party\/github.com\/bosun-monitor/\"$base/g" $gos
sed -i.bak "s/\"github.com\/bosun-monitor\/scollector\/_third_party\/github.com\/bosun-monitor/\"$base/g" $gos
done
sed -i.bak "s/\"github.com\/bosun-monitor\/[a-z]*\/_third_party/\"$base\/_third_party/g" $gos
tp=$bdir/_third_party
rm -rf $tp
mkdir $tp
for i in bosun scollector
do
sed -i.bak "s/\"github.com\/bosun-monitor\/$i/\"$base\/cmd\/$i/g" $gos
sed -i.bak "s/\"bosun.org\/cmd\/$i\/_third_party/\"bosun.org\/_third_party/g" $gos
done
for i in opentsdb collect metadata util
do
sed -i.bak "s/\"github.com\/bosun-monitor\/$i/\"$base\/$i/g" $gos
done
for i in bosun scollector
do
cp -R $bdir/cmd/$i/_third_party/* $tp/.
git rm -rf cmd/$i/_third_party
done
find $bdir -name "*.bak" | xargs rm
git add _third_party
gofmt -w -s cmd collect metadata util vsphere slog opentsdb
git add .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment