1 | #!/bin/sh |
---|
2 | |
---|
3 | # This script takes a .spec file and performs a full rebuild of RPM packages |
---|
4 | # for all acrhitectures supported by netlabs.org RPM repositories using the |
---|
5 | # environment from the netlabs_rpmbuild_env.sh script (see that file for more |
---|
6 | # information about the environment). It also generates a .zip package from |
---|
7 | # the last listed architecture (usualliy i386). |
---|
8 | |
---|
9 | run() |
---|
10 | { |
---|
11 | "$@" |
---|
12 | local rc=$? |
---|
13 | if test $rc != 0 ; then |
---|
14 | echo "ERROR: The following command failed with error code $rc:" |
---|
15 | echo $@ |
---|
16 | exit $rc |
---|
17 | fi |
---|
18 | } |
---|
19 | |
---|
20 | log_run() |
---|
21 | { |
---|
22 | log="$1" |
---|
23 | shift |
---|
24 | "$@" >"$log" 2>&1 |
---|
25 | local rc=$? |
---|
26 | if test $rc != 0 ; then |
---|
27 | echo "ERROR: The following command failed with error code $rc:" |
---|
28 | echo $@ |
---|
29 | echo "You will find more information in file '$log'" |
---|
30 | exit $rc |
---|
31 | fi |
---|
32 | } |
---|
33 | |
---|
34 | die() |
---|
35 | { |
---|
36 | echo "ERROR: $1" |
---|
37 | exit 1 |
---|
38 | } |
---|
39 | |
---|
40 | spec=`echo $1 | tr '\\\' /` |
---|
41 | test -n "$spec" || { echo "ERROR: You must specify a .spec file."; exit 1; } |
---|
42 | |
---|
43 | spec_name="${spec##*/}" |
---|
44 | logDir='.' |
---|
45 | |
---|
46 | # Set up official netlabs.org rpmbuild environment |
---|
47 | . netlabs-rpmbuild-env.sh |
---|
48 | |
---|
49 | if test -d "$logDir" ; then |
---|
50 | # already around |
---|
51 | else |
---|
52 | run mkdir -p "$logDir" |
---|
53 | fi |
---|
54 | |
---|
55 | test -n "$NETLABS_RPM_ARCH_LIST" || die "NETLABS_RPM_ARCH_LIST is empty." |
---|
56 | |
---|
57 | zip_arch=${NETLABS_RPM_ARCH_LIST##* } |
---|
58 | |
---|
59 | echo "Will rpm-build packages from '$spec' for:" |
---|
60 | echo " $NETLABS_RPM_ARCH_LIST + SRPM + ZIP ($zip_arch)" |
---|
61 | |
---|
62 | # Generate RPMs |
---|
63 | for arch in $NETLABS_RPM_ARCH_LIST ; do |
---|
64 | echo "Creating RPMs for '$arch' target (logging to $logDir/$spec_name.$arch.log)..." |
---|
65 | log_run "$logDir/$spec_name.$arch.log" rpmbuild --target=$arch -bb "$spec" |
---|
66 | done |
---|
67 | |
---|
68 | # Generate SRPM |
---|
69 | echo "Creating SRPM (logging to $logDir/$spec_name.srpm.log)..." |
---|
70 | log_run "$logDir/$spec_name.srpm.log" rpmbuild -bs "$spec" |
---|
71 | |
---|
72 | # Generate ZIP |
---|
73 | echo "Creating ZIP (logging to $logDir/$spec_name.zip.log)..." |
---|
74 | create_zip() |
---|
75 | {( |
---|
76 | zip=`grep "src.rpm" "$logDir/$spec_name.srpm.log" | sed -e "s#^[a-zA-Z ]*: *##g" -e "s#.src.rpm##g" | tr . _`.zip |
---|
77 | zip_dir="${zip%/*}/../zip" |
---|
78 | zip="$zip_dir/${zip##*/}" |
---|
79 | echo "Will create '$zip'" |
---|
80 | run mkdir -p "$zip_dir" |
---|
81 | rm -r "@unixroot" 2> /dev/null |
---|
82 | for rpm in `grep "$zip_arch.rpm\|noarch.rpm" "$logDir/$spec_name.$zip_arch.log" | sed "s#^[a-zA-Z ]*: *##g"` ; do |
---|
83 | echo "Unpacking $rpm..." |
---|
84 | run rpm2cpio "$rpm" | cpio -idm |
---|
85 | done |
---|
86 | rm -f "$zip" 2> /dev/null |
---|
87 | run zip -mry9 "$zip" "@unixroot" |
---|
88 | )} |
---|
89 | log_run "$logDir/$spec_name.zip.log" create_zip |
---|
90 | |
---|
91 | echo "All done." |
---|