update-lvm.sh in chef-ruby-lvm-attrib-0.2.6 vs update-lvm.sh in chef-ruby-lvm-attrib-0.2.7
- old
+ new
@@ -10,44 +10,38 @@
# ADDING ATTRIBUTES:
# To add attributes:
# * Download and extract LVM2 source version from: https://sourceware.org/git/?p=lvm2.git;a=tags
# * Fork this repository
-# * `git clone your-forked-repo`
-# * `cd your-forked-repo`
-# * `git checkout -b mybranch`
# * `bin/generate_field_data path/to/lvm2-source`
# * See missing attribute type note below if there's issues, otherwise will just return "Done."
# * `mv LVM_VERSION_FULL lib/lvm/attributes/LVM_VERSION`
# * LVM_VERSION_FULL being something like 2.02.86(2)-cvs or 2.02.98(2)-git
# * LVM_VERSION being something like 2.02.86(2) or 2.02.98(2)
# * `git commit -am "Added LVM_VERSION attributes"`
# * `git push origin mybranch`
-# * Submit PR to this repository. **Please make sure to point your pull at the
-# `next` branch -- NOT MASTER!**
#
-repo_url=git://sourceware.org/git/lvm2.git
refs=refs/heads/master:refs/remotes/origin/master
-pattern=v2_02_*
+pattern=v2_0[23]_*
git_dir=lvm2/.git
set -e
msg() {
echo >&2 "$*"
}
# do initial clone or update LVM2 repository
-clone_lvm2() {
- if [ ! -d $GIT_DIR ]; then
- msg "Checkout $repo_url"
+update_lvm2_repo() {
+ if [ ! -e lvm2/.git ]; then
+ msg "Checkout LVM2 repository"
git submodule update --init --recursive
- else
- msg "Update $repo_url"
- git submodule update --recursive
fi
+
+ msg "Update LVM2 repository"
+ GIT_DIR=$git_dir git fetch origin $refs --tags
}
process_lvm2_version() {
local tag=$1
msg ""
@@ -58,13 +52,11 @@
msg "lib/lvm/attributes/$tag already exists, skip"
return 1
fi
msg "Checkout LVM2 $tag"
- cd lvm2
- git checkout $tag
- cd ..
+ GIT_DIR=lvm2/.git git checkout $tag
version=$(awk '{print $1}' lvm2/VERSION)
msg "LVM2 Full Version: $version"
# skip old "cvs" releases
case "$version" in
@@ -76,59 +68,57 @@
# remove -git suffix
version=${version%-git}
msg "LVM2 Sanitized Version: $version"
- # already present locally
- if [ -d $version ]; then
- msg "dir '$version' exists, skip"
+ attr_dir=lib/lvm/attributes/${version}
+ if [ -d "$attr_dir" ]; then
+ msg "$attr_dir already exists, skip"
return 1
fi
- # dir where attributes get saved
- lvm_dir=$version
-
git_branch=LVM-${version}
# check that local branch isn't already created
if git show-ref --verify --quiet refs/heads/$git_branch; then
msg "Git branch '$git_branch' already exists; skip"
return 1
fi
./bin/generate_field_data lvm2
-
- attr_dir=lib/lvm/attributes/${version}
- if [ -d "$attr_dir" ]; then
- msg "$attr_dir already exists, skip"
+ if [ ! -d "$attr_dir" ]; then
+ msg "Failed to generate $attr_dir"
return 1
fi
- mv $lvm_dir $attr_dir
git add -A $attr_dir
- git checkout -b $git_branch next
- git commit -am "Added $tag attributes"
+ git checkout -b $git_branch master
+ cat > .git/commit-msg <<-EOF
+Added $tag attributes
+$(git diff --stat HEAD $attr_dir)
+EOF
+ git commit -s -F .git/commit-msg $attr_dir
+
return 0
}
+update_lvm2_repo
-GIT_DIR=$git_dir clone_lvm2
-
if [ "$1" = "-a" ]; then
# obtain all versions
- set -- $(GIT_DIR=$git_dir git tag -l $pattern)
+ set -- $(GIT_DIR=lvm2/.git git tag -l $pattern)
fi
-# it shouldn't be exported, but somewhy is. unset
-unset GIT_DIR
-
# process versions specified on commandline,
# otherwise iterate over all LVM2 tags
for tag in "$@"; do
process_lvm2_version $tag || continue
updated=1
done
+
+# keep the pointer to master branch
+GIT_DIR=lvm2/.git git checkout master
if [ -z "$updated" ]; then
echo >&2 "Nothing updated"
exit 1
fi