source: projects/self-build-setup/trunk/self-build-rpm.sh @ 419

Revision 419, 3.6 KB checked in by munepi, 14 years ago (diff)

added self-build-setup

  • Property svn:executable set to *
Line 
1#!/bin/bash
2#
3# Helper script for self-build rpm package.
4# arguments 1:package name, 2:spec file, 3 and on: source url
5#
6# NOTE: To avoid scriptlet failure during rpm transaction,
7#       This script should always return 0 even if there is an error.
8
9TEXTDOMAIN=self-build-setup
10TEXTDOMAINDIR=/usr/share/locale
11
12_NAME=$1
13_SPEC=$2
14_ARCH=$(rpm --eval %_arch)
15_QUEDIR=/var/cache/self-build
16
17. /etc/self-build.conf
18
19echo -n "     "
20echo -n $"Start creating rpm packages."
21echo "($_NAME)"
22
23# create temporary rpm directory
24if ! _TOPDIR=`mktemp -d $TEMP_DIR/$_NAME.XXXXXX`; then
25    echo -n "     "
26    echo $"*ERROR: can't crete temporary directory."
27    exit 0
28fi
29mkdir $_TOPDIR/rpm
30mkdir $_TOPDIR/rpm/BUILD
31mkdir $_TOPDIR/rpm/RPMS
32mkdir $_TOPDIR/rpm/RPMS/$_ARCH
33mkdir $_TOPDIR/rpm/RPMS/noarch
34mkdir $_TOPDIR/rpm/SOURCES
35
36# copy patches and other files.
37cp -a /usr/share/$_NAME/* $_TOPDIR/rpm/SOURCES
38
39# get source
40
41echo -n "     "
42echo $"Downloading source files..."
43shift 2
44for u in $@; do
45    _SRC=$_TOPDIR/rpm/SOURCES/$(basename $u)
46    [ -s $_SRC ] && continue
47
48    if [ ! $DL_SHOW_PROGRESS = "yes" ]; then
49        # run quiet, no GUI
50        wget -q -P $_TOPDIR/rpm/SOURCES $u
51        RESULT=$?
52    elif [ -z `pgrep -n synaptic` ]; then
53        # run verbose, without GUI (because no synaptic running)
54        wget -P $_TOPDIR/rpm/SOURCES $u
55        RESULT=$?
56    else
57        # run verbose with GUI (zenity)
58        wget -P $_TOPDIR/rpm/SOURCES $u 2>&1 | \
59             sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \
60             zenity --auto-close --progress \
61                     --title $"Download files" \
62                     --text $"Downloading $(basename $u)..." &
63
64        # workaround for killing remaining wget process when cancel button pressed.
65        WGETPID=`pgrep -f "wget -P $_TOPDIR/rpm/SOURCES $u"`
66        ZENITYPID=$!                        # last child pid = zenity pid
67        RESULT=0                            # hold exit status of zenity
68
69        RUNNING=0
70        while [ $RUNNING -eq 0 ]
71        do
72            sleep 1
73            if [ -z `ps -p $ZENITYPID -o pid=` ]; then
74                if [ `ps -p $WGETPID -o pid=` ]; then
75                    # if zenity exited but wget still running,
76                    # then we suppose that zenity is cancelled by user.
77                    sleep 3
78                    kill -KILL $WGETPID
79                    RESULT=1
80                fi
81            RUNNING=1
82            fi
83        done
84    fi
85    [ $RESULT -ne 0 -a -e $_SRC ] && rm -f $_SRC   
86done
87for f in $(echo $@|xargs -r -n1 basename|sort -u); do
88    if [ ! -s $_TOPDIR/rpm/SOURCES/$f ]; then
89        echo -n "     "
90        echo $"*ERROR: can't download source file."": $f"
91        rm -rf $_TOPDIR
92        exit 0
93    fi
94done
95echo -n "     "
96echo $"Source files download successfully."
97
98# build rpm package
99echo -n "     "
100echo $"Building rpm packages..."
101echo -n "      "
102echo $"(see $TEMP_DIR/$_NAME.log for detail.)"
103# now rpmbuild done by non-root user $BUILD_USER
104rm -f $TEMP_DIR/$_NAME.log
105chown -R $BUILD_USER:$BUILD_USER $_TOPDIR
106if su $BUILD_USER -c "rpmbuild -bb --define=\"_topdir $_TOPDIR/rpm\" /usr/share/$_NAME/$_SPEC > $TEMP_DIR/$_NAME.log 2>&1" > /dev/null 2>&1; then
107    echo -n "     "
108    echo $"rpm packages are successfully built."
109    if ls $_TOPDIR/rpm/RPMS/$_ARCH | grep -e "\.rpm$" > /dev/null ; then
110        mv -f $_TOPDIR/rpm/RPMS/$_ARCH/*.rpm $_QUEDIR
111    fi
112    if ls $_TOPDIR/rpm/RPMS/noarch | grep -e "\.rpm$" > /dev/null ; then
113        mv -f $_TOPDIR/rpm/RPMS/noarch/*.rpm $_QUEDIR
114    fi
115    rm -rf $_TOPDIR
116else
117    echo -n "     "
118    echo $"*ERROR: can't build rpm packages."
119    rm -rf $_TOPDIR
120    exit 0
121fi
122exit 0
Note: See TracBrowser for help on using the repository browser.