Skip to content

Instantly share code, notes, and snippets.

@cbeer
Created August 14, 2014 20:53
Show Gist options
  • Save cbeer/f3437753e37c879aaaf9 to your computer and use it in GitHub Desktop.
Save cbeer/f3437753e37c879aaaf9 to your computer and use it in GitHub Desktop.
Apply license file to all repositories
#/bin/bash
# Dependencies:
# jq: https://github.com/stedolan/jq
# hub: https://github.com/defunkt/hub
cat > /tmp/LICENSE <<EOF
©yyyy The Board of Trustees of the Leland Stanford Junior University.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
EOF
mkdir github-mirror
cd github-mirror
mkdir repos
cd repos
# Clone every repository
for i in 1 2 3 4; do
curl "https://api.github.com/orgs/sul-dlss/repos?page=$i" | jq ".[].clone_url" | sed "s/https:\/\//git@" | sed "s/github.com\//github.com:/"
done | xargs -n 1 git clone
# partition into licensed and unlicensed
mkdir ../licensed
mkdir ../unlicensed
find . -maxdepth 2 | grep -i "LICENSE" | sed "s/.\///" | sed "s/\/.*//" | xargs -I {} mv {} ../licensed
mv * ../unlicensed
cd ../unlicensed
for i in $( ls ); do
(
cd $i
git checkout -b license
cp /tmp/LICENSE .
perl -pi -e "s/yyyy/`git log --format="format:%ci" --reverse | head -n 1 | sed "s/-.*//"`/" LICENSE
git add LICENSE
git commit -m "Add LICENSE file"
git push origin license
hub pull-request -m "Add LICENSE file"
)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment