-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgear-hsh-build
executable file
·215 lines (193 loc) · 5.63 KB
/
gear-hsh-build
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh -efu
#
# Copyright (C) 2006-2007 Alexey I. Froloff <[email protected]>
# Copyright (C) 2006-2008 Dmitry V. Levin <[email protected]>
# Copyright (C) 2006 Alexey Gladkov <[email protected]>
#
# gear-hsh-build - build packages from gear repositories with hasher
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
. gear-utils-sh-functions
print_version()
{
cat <<EOF
$PROG version $PROG_VERSION
Written by Alexey I. Froloff <[email protected]>
Copyright (C) 2006-2007 Alexey I. Froloff <[email protected]>
Copyright (C) 2006-2008 Dmitry V. Levin <[email protected]>
Copyright (C) 2006 Alexey Gladkov <[email protected]>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit
}
show_help()
{
cat <<EOF
Usage: $PROG [OPTIONS...] -- REPOSITORY... [-- HASHER_OPTIONS...]
This program will build package(s) from your gear repository(es) with
hasher. REPOSITORY is a path to git directory (/path/to/repo.git or
/path/to/repo/.git) with optional tree-ish separated by \`\`#''
(/path/to/repo#tree-ish). You can specify additional hasher options
after repository list.
Options:
--cleanup-repo cleanup hasher repo after build;
--export-dir=DIR write built packages to specified directory;
--hasher=FILE path to hasher binary;
--prefix=DIR path to hasher workdir;
--repo=DIR repository directory;
--sisyphus export packages to sisyphus-like START_DIR;
--target=ARCH target architecture;
-q, --quiet try to be more quiet;
-v, --verbose print a message for each action;
-V, --version print program version and exit;
-h, --help show this text and exit.
Report bugs to https://bugzilla.altlinux.org/
EOF
exit
}
target=
prefix=
# source user config if any
hasher_config="$HOME/.hasher/config"
if [ -s "$hasher_config" ]; then
. "$hasher_config"
fi
[ -n "$target" ] || target="$(uname -m)"
cleanup_repo=
hasher="hsh"
outdir=
repo="$(mktemp -u "build-XXXXXXXXXX")"
sisyphus=
repos=
indir=
cleanup_handler()
{
if [ "$*" = 0 ]; then
if [ -n "$cleanup_repo" ]; then
rm -rf $verbose -- "$indir"
else
message "You may add \`\`rpm file:$indir $target hasher'' to your sources.list"
fi
else
[ -z "$indir" ] ||
message "Build failed. You may wish to check \`\`$indir'' for leftovers."
fi
}
TEMP=$(getopt -n $PROG -o +h,q,V,v -l cleanup-repo,export-dir:,hasher:,prefix:,repo:,sisyphus,target:,help,quiet,verbose,version -- "$@")
eval set -- "$TEMP"
while :; do
case "$1" in
--) shift; break
;;
--cleanup-repo) cleanup_repo=1
;;
--export-dir) outdir="$(opt_check_dir "$1" "$2")"; shift
;;
--hasher) hasher="$2"; shift
;;
--prefix) prefix="$(opt_check_dir "$1" "$2")"; shift
;;
--repo) repo="$2"; shift
;;
--sisyphus) sisyphus=1
;;
--target) target="$2"; shift
;;
-h|--help) show_help
;;
-q|--quiet) quiet=-q; verbose=
;;
-v|--verbose) verbose=-v; quiet=
;;
-V|--version) print_version
;;
*) fatal "Unrecognized option: $1"
;;
esac
shift
done
[ -n "$prefix" ] ||
fatal "Can't operate with empty prefix"
if [ -z "$outdir" ]; then
[ -z "$cleanup_repo" ] ||
fatal "--cleanup-repo without --export-dir doesn't makes sense"
[ -z "$sisyphus" ] ||
fatal "--sisyphus without --export-dir doesn't makes sense"
fi
indir="$prefix/$repo"
if [ -z "${repo##/*}" ]; then
if [ -n "$cleanup_repo" ]; then
message "--repo is absolute, refusing to --cleanup-repo"
cleanup_repo=
fi
indir="$repo"
fi
while [ $# -gt 0 ]; do
case "$1" in
--) shift; break
;;
*) repos="${repos:+$repos
}$1"
;;
esac
shift
done
[ -n "$repos" ] || {
repos="$(git rev-parse --git-dir)"
verbose "No repositories given, assuming $repos..."
}
install_cleanup_handler cleanup_handler
save_IFS="$IFS"
IFS="
"
for git_repo in $repos; do
IFS="$save_IFS"
if [ -z "${git_repo##*\#*}" ]; then
git_dir="${git_repo%%\#*}"
git_tree="${git_repo#*\#}"
else
git_dir="$git_repo"
git_tree=
fi
[ -d "$git_dir" ] || continue
git_dir="$(readlink -ev -- "$git_dir")"
message "Building $git_dir${git_tree:+ with tag $git_tree}..."
export GIT_DIR="$git_dir"
run_command gear $quiet $verbose ${git_tree:+--tree="$git_tree"} --hasher -- "$hasher" $quiet $verbose "$@" --target="$target" --repo="$repo" -- "$prefix"
save_IFS="$IFS"
IFS="
"
done
IFS="$save_IFS"
if [ -n "$outdir" ]; then
verbose "Exporting packages to $outdir..."
rpms="$indir/$target/RPMS.hasher"
srpms="$indir/SRPMS.hasher"
if [ -n "$sisyphus" ]; then
mkdir -p "$outdir/RPMS"
mkdir -p "$outdir/SRPMS"
rpms_out="$outdir/RPMS"
srpms_out="$outdir/SRPMS"
else
rpms_out="$outdir"
srpms_out="$outdir"
fi
find "$rpms" -mindepth 1 -maxdepth 1 -type f -name '*.rpm' -print0 |
xargs -r0 cp -f $verbose --target-directory="$rpms_out" --
find "$srpms" -mindepth 1 -maxdepth 1 -type f -name '*.rpm' -print0 |
xargs -r0 cp -f $verbose --target-directory="$srpms_out" --
fi