-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathupdate-lvm.sh
executable file
·125 lines (102 loc) · 2.8 KB
/
update-lvm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# Script to checkout LVM2 from git and make attributes for all versions that
# don't have yet.
#
# Author: Elan Ruusamäe <[email protected]>
#
# Usage:
# - update all versions: ./update-lvm.sh -a
# - update specific version "2.0.102": ./update-lvm.sh v2_02_102
# ADDING ATTRIBUTES:
# To add attributes:
# * Download and extract LVM2 source version from: https://sourceware.org/git/?p=lvm2.git;a=tags
# * Fork this repository
# * `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`
#
refs=refs/heads/main:refs/remotes/origin/main
pattern=v2_0[23]_*
git_dir=lvm2/.git
set -e
msg() {
echo >&2 "$*"
}
# do initial clone or update LVM2 repository
update_lvm2_repo() {
if [ ! -e lvm2/.git ]; then
msg "Checkout LVM2 repository"
git submodule update --init --recursive
fi
msg "Update LVM2 repository"
GIT_DIR=$git_dir git fetch origin $refs --tags
}
process_lvm2_version() {
local tag=$1
msg ""
msg "Process LVM2 $tag"
# already present in source tree
if [ -d lib/lvm/attributes/$tag ]; then
msg "lib/lvm/attributes/$tag already exists, skip"
return 1
fi
msg "Checkout LVM2 $tag"
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
*-cvs)
msg "$version is CVS tag, skip"
return 1
;;
esac
# remove -git suffix
version=${version%-git}
msg "LVM2 Sanitized Version: $version"
attr_dir=lib/lvm/attributes/${version}
if [ -d "$attr_dir" ]; then
msg "$attr_dir already exists, skip"
return 1
fi
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
if [ ! -d "$attr_dir" ]; then
msg "Failed to generate $attr_dir"
return 1
fi
git add -A $attr_dir
git checkout -b $git_branch main
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
if [ "$1" = "-a" ]; then
# obtain all versions
set -- $(GIT_DIR=lvm2/.git git tag -l $pattern)
fi
# 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 main branch
GIT_DIR=lvm2/.git git checkout main
if [ -z "$updated" ]; then
echo >&2 "Nothing updated"
exit 1
fi