Last active
January 2, 2016 13:39
-
-
Save zyluo/8311673 to your computer and use it in GitHub Desktop.
OpenStack git repository update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright (c) 2014 Intel Corporation. | |
# All Rights Reserved. | |
# | |
# 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. | |
print_hint() { | |
echo "Try \`${0##*/} --help' for more information." >&2 | |
} | |
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hp: --long help,project: -- "$@") | |
if [ $? != 0 ] ; then print_hint ; exit 1 ; fi | |
eval set -- "$PARSED_OPTIONS" | |
while true; do | |
case "$1" in | |
-h|--help) | |
echo "${0##*/} [options]" | |
echo "" | |
echo "options:" | |
echo "-h, --help show brief help" | |
echo "-p, --project=NAME project package name" | |
exit 0 | |
;; | |
-p|--project) | |
shift | |
TARGET_PROJECT=`echo $1` | |
shift | |
;; | |
--) | |
break | |
;; | |
esac | |
done | |
if [ -n "$TARGET_PROJECT" ] | |
then | |
PROJECTS="|"$(curl -s https://git.openstack.org/cgit/ | \ | |
grep reposection | \ | |
awk -F 'reposection' '{print $2}' | \ | |
awk -F 'td' '{print $1}' | \ | |
cut -d ">" -f2 | \ | |
cut -d "<" -f1 | \ | |
tr "\\n" "|") | |
if [[ ! $PROJECTS =~ "|"$TARGET_PROJECT"|" ]] | |
then | |
echo "${0##*/}: invalid project name" >&2 ; print_hint ; exit 1 | |
fi | |
fi | |
PROGRAMS=$(curl -s https://git.openstack.org/cgit/ | \ | |
grep sublevel-repo | awk -F 'title=' '{print $2}' | \ | |
awk -F ' href=' '{print $1}' | cut -d "'" -f2) | |
BASEDIR=`pwd` | |
for REPO in $PROGRAMS | |
do | |
[ `pwd` != $BASEDIR ] && cd $BASEDIR | |
PROJECT=$(echo $REPO | cut -d / -f1) | |
PROGRAM=$(echo $REPO | cut -d / -f2) | |
[ -n "$TARGET_PROJECT" ] && [ $TARGET_PROJECT != $PROJECT ] && continue | |
if [ -d $PROJECT ] | |
then | |
cd $PROJECT | |
if [ -d $PROGRAM ] | |
then | |
echo $PROGRAM | |
cd $PROGRAM | |
[[ $(git branch | grep ^*) != "* master" ]] && git checkout master | |
git fetch origin | |
git pull origin master | |
else | |
git clone git://git.openstack.org/$REPO.git | |
fi | |
else | |
mkdir $PROJECT | |
cd $PROJECT | |
git clone git://git.openstack.org/$REPO.git | |
fi | |
done | |
cd $BASEDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment