Rpmbuild: Difference between revisions

From Leo's Notes
This page was last edited on 1 September 2019, at 06:20.
m Text replacement - "{{Navbox Linux}}{{Navbox Linux}}" to "{{Navbox Linux}}"
m Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux"
Line 106: Line 106:




[[Category:Linux]]{{Navbox Linux}}
{{Navbox Linux}}[[Category:Linux]]
[[Category:PackageManagement]]
[[Category:PackageManagement]]
[[Category:Todo]]
[[Category:Todo]]

Revision as of 06:20, 1 September 2019

I have this RPM build script that will automatically build the package based on the .spec file in the directory tree...


#!/bin/bash

Usage() {
	echo "Usage: rebuild.sh [sl | f20] package1 [package2 ...]"
	exit
}


if [ $# -eq 0 ] ; then
	Usage
fi

if [[ "$1" == "-h" ]] ; then
	Usage
fi

DistroPath="release" # scientific is under 'release'
if [ $# -ge 2 ] ; then
	if [[ "$1" == "f20" ]] || [[ "$1" == "fc20" ]] ; then
		echo "Building to the Fedora 20 repository"
		DistroPath="fedora20"

		shift
	elif [[ "$1" == "sl" ]] ; then
		echo "Building to the ScientificLinux repository"
		DistroPath="release"

		shift
	else
		echo "No distro specified - using SL"
	fi
fi

# Build each package specified
while [ ! -z $1 ] ; do
	Package=$1

	if [ ! -f  "SPECS/$Package.spec" ] ; then
		echo "Could not find SPEC file for $Package"
		exit
	fi

	Version=`cat SPECS/$Package*.spec | grep Version | head -n 1 | awk '{print \$2}'` 
	Release=`cat SPECS/$Package*.spec | grep Release | head -n 1 | awk '{print \$2}'`

	Arch=`cat SPECS/$Package*.spec | grep BuildArch | head -n 1 | awk '{print \$2}'`
	# Arch by default is x86_64
	if [ -z $Arch ] ; then
		Arch="x86_64";
	fi

	# We are putting everyting in the same x86_64 extras directory.
	PackageOutputDirectory="../../repository/cpsc-extras/$DistroPath/x86_64/extras/"
	# Source pacages are dumped into /tmp - you  might want to save it somewhere better.
	SourceOutputDirectory="/tmp"

	echo Building $Package Version $Version Release $Release...

	cd SOURCES

	if [ ! -d $Package ] ; then
		echo "Make sure you have a directory in SOURCE called $Package"
		exit
	fi

	rm $Package*.tar.gz

	# Tar up the source with the directory as $package-$ver
	mv $Package $Package-$Version
	tar -czf $Package-$Version-$Release.tar.gz $Package-$Version
	mv $Package-$Version $Package
	chmod 644 *.tar.gz

	# Build
	cd ..
	# rpmbuild -ba --define '_topdir /export/package_build/rpmbuild/'  SPECS/$Package.spec || exit 
	rpmbuild -ba --define "_topdir `pwd`"  SPECS/$Package.spec || exit $?

	# Save
	rm $PackageOutputDirectory/$Package*rpm
	cp RPMS/$Arch/$Package*-$Version-$Release.$Arch.rpm $PackageOutputDirectory
	cp SOURCES/$Package*-$Version-$Release.tar.gz $SourceOutputDirectory
	chmod 644 $PackageOutputDirectory/$Package*-$Version-$Release.x86_64.rpm

	echo Copied $Package to $PackageOutputDirectory


	shift
done


# Regenerate the repository
cd $PackageOutputDirectory
chown -R apache:apache *
sudo -u apache createrepo -g comp* . --update
chmod 644 repodata/*
chmod 755 repodata