-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrpmbuild_spec
executable file
·58 lines (49 loc) · 1.55 KB
/
rpmbuild_spec
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
#!/bin/bash
#
# Authors: Guo Yunhe <[email protected]>
# Created: 2018-10-06
# Updated: 2018-10-11
#
# Build RPM packages from a SPEC file. Automatically download sources from
# GitHub/GitLab/BitBucket.
#
# Usage: ./build_package <package_name>
#
# Requires: rpm rpm-build nodejs npm
if [ -z "$1" ]; then
echo "No pcakge name given!"
echo "Usage: rpmbuild_spec <package_name>"
exit
fi
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
REPO_DIR=$ROOT_DIR/repo
SPEC_DIR=$ROOT_DIR/spec
RPMBUILD_DIR=~/rpmbuild
RPMBUILD_SOURCES_DIR=$RPMBUILD_DIR/SOURCES
RPMBUILD_RPMS_DIR=$RPMBUILD_DIR/RPMS
SPEC_FILE=$SPEC_DIR/$1/$1.spec
SOURCE_URL=$(rpmspec -P $SPEC_FILE | grep -oP "Source0\:\s+\K\S+")
SOURCE_FILENAME=$(echo $SOURCE_URL | grep -oP "\#\/\K\S+")
SOURCE_FILE=$RPMBUILD_SOURCES_DIR/$SOURCE_FILENAME
PACKAGE_NAME=$1
PACKAGE_VERSION=$(rpmspec -P $SPEC_FILE | grep -oP "Version\:\s+\K\S+")
PACKAGE_RELEASE=$(rpmspec -P $SPEC_FILE | grep -oP "Release\:\s+\K\S+")
PACKAGE_FILENAME=$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.x86_64.rpm
PACKAGE_FILE=$REPO_DIR/$PACKAGE_FILENAME
if [ -f "$PACKAGE_FILE" ]; then
echo "$PACKAGE_FILENAME exists. Skip."
exit
fi
mkdir -p $RPMBUILD_SOURCES_DIR
# Downlaod main source if not existing
if [ ! -f "$SOURCE_FILE" ]; then
echo "Downloading $SOURCE_FILENAME"
wget -O $SOURCE_FILE $SOURCE_URL
echo "Done"
fi
# Copy other source files
cp $SPEC_DIR/$PACKAGE_NAME/* $RPMBUILD_SOURCES_DIR
# Build package
echo "Building $1"
rpmbuild -ba $SPEC_FILE && mv $RPMBUILD_RPMS_DIR/x86_64/* $REPO_DIR/
echo "Done"