This shows you the differences between two versions of the page.
rpm_tools [2015/05/07 18:27] stephdl [contrib_migration] |
rpm_tools [2019/06/05 19:48] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Rpm Tools===== | ||
- | ===Introduction=== | ||
- | |||
- | In this howto we could let script-tools we need to build rpm | ||
- | |||
- | ====mockbuild==== | ||
- | |||
- | mock get a special syntax not always easy to recall, here a script that you need to record at / | ||
- | |||
- | * mockbuild usage | ||
- | mockbuild package.src.rpm | ||
- | |||
- | mock_configuration can be found in /etc/mocks | ||
- | smeserver-9-x86_64-base smeserver-9-i386-base | ||
- | smeserver-8-x86_64-base smeserver-8-i386-base | ||
- | epel-6-x86_64 | ||
- | epel-5-x86_64 | ||
- | |||
- | < | ||
- | # who i'm | ||
- | ME=$(whoami) | ||
- | mkdir -p / | ||
- | | ||
- | #test if the second argument is here | ||
- | if [[ -z $2 ]]; then | ||
- | echo "################################################" | ||
- | echo "you must give as argument the mock configuration" | ||
- | echo " | ||
- | echo " | ||
- | echo " | ||
- | echo " | ||
- | echo " mockbuild package.src.rpm | ||
- | echo "################################################" | ||
- | exit | ||
- | fi | ||
- | |||
- | mock -r $2 --rebuild $1 --resultdir=/ | ||
- | |||
- | # we give the path where are files | ||
- | echo "" | ||
- | echo " | ||
- | echo "RPMS are in / | ||
- | echo "" | ||
- | ls -1 / | ||
- | echo " | ||
- | |||
- | # and we sign rpm if needed, if not simply do ' | ||
- | echo "" | ||
- | echo " | ||
- | rpm --resign / | ||
- | | ||
- | A the end I use rpm to sign my rpm, if you don't need it you can remove it. | ||
- | |||
- | ====git_ignore==== | ||
- | git don't track empty directory that we may need for a rpm, here a script that you need to record at / | ||
- | |||
- | **usage** | ||
- | in the git directory call the script and track all gew files by " git add . && git commit -m ' | ||
- | git_ignore | ||
- | |||
- | #in order to add a .gitignore file to track empty folder | ||
- | find * -type d -empty -exec touch {}/ | ||
- | |||
- | ====git_mockbuild==== | ||
- | |||
- | a git integration for mock, git and rpm https:// | ||
- | |||
- | you can record this script in /usr/bin | ||
- | |||
- | cp git_mockbuild /usr/bin chmod 775 / | ||
- | |||
- | you need to make a folder with the exact name of the rpm (eg smeserver-dhcpmanager). Inside of this folder you create your git repository and work on files and folder of your RPM. Be aware that GIT do not track empty repositories, | ||
- | |||
- | you can use this command line in case of many folders and subfolders | ||
- | |||
- | find * -type d -empty -exec touch {}/ | ||
- | |||
- | Once you want to make the RPM then simply use git_mockbuild without arguments in the root folder of your git repository, the architecture of build come from the spec file. But if needed you can choose another build arch. You have to choose one argument. | ||
- | |||
- | git_mockbuild or git_mockbuild sme8-386 sme8-64 sme9-386 sme9-64 | ||
- | |||
- | by default if the build architecture is not specified in the spec file, it is the case of packages which are not ' | ||
- | |||
- | The CentOS target version comes from the GIT branch you created in your GIT repository. For example if your branch is named sme9 then the build is done for el6, else the target CentOS version is el5. | ||
- | |||
- | For an automatic build for all architectures you should take considerations about Plague which is done for that. | ||
- | |||
- | Each time you execute the script, the GIT branch in use is tagged with the version of the RPM. | ||
- | |||
- | The result of build can be find in the ' | ||
- | |||
- | * usage | ||
- | |||
- | in the git directory of your rpm (you need to install git & mock installed) | ||
- | git_mockbuild | ||
- | |||
- | #!/bin/bash | ||
- | ############################################################################################## | ||
- | ## a big thank to daniel berteaud from firewall-service who started in first to write this script | ||
- | ## the purpose of this script is to create a targ.gz from the GIT folder in order to build a rpm | ||
- | ## then after mock is used to make the rpm in a chroot | ||
- | ############################################################################################## | ||
- | # git_mockbuild | ||
- | # parameters are optional | ||
- | ME=$(whoami) | ||
- | |||
- | # What is the package name | ||
- | # The package name is given by the name of the main folder | ||
- | PACKAGE=$(basename $(pwd)) | ||
- | | ||
- | # Informations needed from the spec file | ||
- | VERSION=$(rpm -q --qf " | ||
- | ARCH=$(rpm -q --qf " | ||
- | RELEASE=$(rpm -q --qf " | ||
- | | ||
- | # Which git branch we are talking | ||
- | BRANCH=$(git branch | grep ' | ||
- | | ||
- | # Find the centos version | ||
- | DIST=$2 | ||
- | if [[ -z $DIST && " | ||
- | DIST=" | ||
- | elif [ -z $DIST ]; then | ||
- | DIST=" | ||
- | fi | ||
- | | ||
- | # Create a tmp folder in /tmp | ||
- | TMPDIR=$(mktemp -d) | ||
- | mkdir -p $TMPDIR/ | ||
- | | ||
- | # Tag GIT using the version in the spec file | ||
- | ##we do a hack to retrieve the release without %{?dist} | ||
- | RELEASETAG=${RELEASE/ | ||
- | | ||
- | TAG=$VERSION" | ||
- | git tag -f $TAG 2>&1 > /dev/null | ||
- | | ||
- | # Create needed dirs on the build box | ||
- | mkdir -p ~/ | ||
- | mkdir -p ~/exchange | ||
- | | ||
- | | ||
- | # Generate a tgz archive from the repo | ||
- | git archive --format=tar --prefix=$PACKAGE-$VERSION/ | ||
- | | ||
- | # Generate ChangeLog | ||
- | git log --format=%H | git log --pretty --stdin --no-walk > $TMPDIR/ | ||
- | | ||
- | # Create the tar.gz archive | ||
- | tar czf $TMPDIR/ | ||
- | | ||
- | # cp the spec file and tar.gz | ||
- | cp $TMPDIR/ | ||
- | cp $PACKAGE.spec ~/ | ||
- | | ||
- | # And build | ||
- | echo"" | ||
- | echo " | ||
- | echo "# git_mockbuild | ||
- | echo 'you can choose another build architecture : git_mockbuild sme8-386 sme8-64 sme9-386 sme9-64 epel-6-x86_64 epel-6-i386 epel-5-x86_64 epel-5-i386' | ||
- | echo 'you can choose which SME_Server target version you want : sme8 sme9' | ||
- | echo "" | ||
- | echo " | ||
- | echo "" | ||
- | cd ~/ | ||
- | tar -xvf ~/ | ||
- | rpmbuild -bs --nodeps ~/ | ||
- | echo "" | ||
- | echo " | ||
- | echo "" | ||
- | echo " | ||
- | echo "The build RPM architecture is $ARCH" | ||
- | echo "The target CentOS version is $DIST" | ||
- | | ||
- | if [ " | ||
- | if [ " | ||
- | MOCKCONF=" | ||
- | elif [ " | ||
- | MOCKCONF=" | ||
- | elif [ " | ||
- | MOCKCONF=" | ||
- | fi; | ||
- | elif [ " | ||
- | if [ " | ||
- | MOCKCONF=" | ||
- | elif [ " | ||
- | MOCKCONF=" | ||
- | elif [ " | ||
- | MOCKCONF=" | ||
- | fi; | ||
- | fi | ||
- | | ||
- | | ||
- | if ! [ -z " | ||
- | if [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | elif [ $1 = " | ||
- | MOCKCONF=" | ||
- | fi; | ||
- | fi | ||
- | | ||
- | echo "The mock chroot configuration used is $MOCKCONF" | ||
- | echo " | ||
- | echo "" | ||
- | mock -r $MOCKCONF --rebuild ~/ | ||
- | | ||
- | # a bit of clean | ||
- | | ||
- | rm -f ~/ | ||
- | rm -rf $TMPDIR | ||
- | | ||
- | # we give the path where are files | ||
- | echo "" | ||
- | echo " | ||
- | echo "RPMS are in / | ||
- | echo "" | ||
- | ls -1 ~/ | ||
- | echo " | ||
- | | ||
- | # and we sign rpm if needed, if not simply do ' | ||
- | echo "" | ||
- | echo " | ||
- | rpm --resign ~/ | ||
- | |||
- | ====contrib_migration==== | ||
- | a script to migrate contrib from sme8 CVS to your local git and to your remote Github account for sme9 https:// | ||
- | |||
- | simply call the script with the name of the cvs directory. Of course you have to install cvs and retrieve the source code in an anonymous or with a developer access | ||
- | |||
- | contrib_migration smeserver-wordpress | ||
- | |||
- | If the directory is not existed in your git directory (~/ | ||
- | After that the script does several things | ||
- | |||
- | *create the local git repository | ||
- | *create the remote github account | ||
- | * build all patches and remove them | ||
- | * move all perl files to the correct new path | ||
- | * test if the new apache authentication is needed and where. | ||
- | * add a .git_ignore in empty folders (needed by git) | ||
- | * track all that stuff :) | ||
- | |||
- | * usage | ||
- | you need to be outside of the cvs folder (eg in the ' | ||
- | | ||
- | |||
- | < | ||
- | if [[ -z $1 ]]; then | ||
- | echo "#################################################################################" | ||
- | echo "you must give as argument the folder name in cvs : contrib_migration folder_name" | ||
- | echo "#################################################################################" | ||
- | exit | ||
- | fi | ||
- | | ||
- | | ||
- | | ||
- | if [[ ! -d ~/ | ||
- | | ||
- | rm -rf $1/ | ||
- | cvs co $1/ | ||
- | cd $1/ | ||
- | make prep | ||
- | NameGitHub=$1 | ||
- | curl -u ' | ||
- | mkdir -p ~/ | ||
- | | ||
- | cp -R smeserver-*/ | ||
- | cp $1*.spec ~/ | ||
- | cd ~/ | ||
- | | ||
- | if [ -e root/ | ||
- | mkdir -p root/ | ||
- | mv root/ | ||
- | rm -rf root/ | ||
- | fi | ||
- | ##we remove all patch from the spec file | ||
- | sed '/ | ||
- | sed '/ | ||
- | mv -f $1.ter.spec $1.spec | ||
- | rm -f $1.bis.spec | ||
- | | ||
- | | ||
- | ###git work | ||
- | | ||
- | if [ ! -e README.md ]; then | ||
- | touch README.md | ||
- | echo "$1 is a contrib for SME Server, a Linux distro oriented server. see http:// | ||
- | fi | ||
- | | ||
- | ## | ||
- | find * -type d -empty -exec touch {}/ | ||
- | | ||
- | git init | ||
- | git add . | ||
- | git commit -m "first commit to SME Server 9" | ||
- | git co -b sme9 | ||
- | git remote add origin git@github.com: | ||
- | git push -u -f origin sme9 | ||
- | | ||
- | ##find the apache authentication | ||
- | echo "" | ||
- | echo "" | ||
- | echo "we are looking if we need to modify the apache authentication" | ||
- | testapache=$(grep -srni ' | ||
- | if [[ $testapache =~ " | ||
- | echo " | ||
- | echo 'You must add before | ||
- | | ||
- | else | ||
- | echo "no apache authentication" | ||
- | fi | ||
- | | ||
- | ## help to write the changelog | ||
- | myDate=$(LC_ALL=C date +"%a %b %d %Y") | ||
- | echo "" | ||
- | echo "* $myDate stephane de Labrusse < | ||
- | echo "- Initial release to sme9" | ||
- | | ||
- | else | ||
- | echo"" | ||
- | echo "###################################" | ||
- | echo "the git directory ~/ | ||
- | echo " | ||
- | echo "think also if you have a github project called stephdl/ | ||
- | echo "###################################" | ||
- | fi</ | ||
- | |||
- | ====build_srpm==== | ||
- | a script to build srpm, create the git repository, and export all files to github https:// | ||
- | |||
- | it creates automatically the new repository in github with your credentials (adjust ' | ||
- | |||
- | * usage | ||
- | you must give arguments on the git branch (master, sme9 or anything else) and the package name : build_srpm package_name master | ||
- | give the real name without number of version | ||
- | build_srpm freedup sme9 | ||
- | |||
- | ---- | ||
- | < | ||
- | if [[ -z $1 || -z $2 ]]; then | ||
- | echo "################################################################################################################################" | ||
- | echo "you must give arguments on the git branch (master, sme9 or anything else) and the package name : build_srpm package_name master" | ||
- | echo "################################################################################################################################" | ||
- | exit | ||
- | fi | ||
- | |||
- | if [[ -d ~/ | ||
- | echo"" | ||
- | echo "###################################" | ||
- | echo "the git directories ~/ | ||
- | echo " | ||
- | echo "think also if you have a github project called stephdl/$1 and stephdl/ | ||
- | echo "###################################" | ||
- | exit | ||
- | fi | ||
- | # Create needed dirs on the build box | ||
- | |||
- | mkdir -p ~/ | ||
- | mkdir -p ~/exchange | ||
- | |||
- | rpm -ivh $1*.src.rpm | ||
- | cd ~/ | ||
- | rpmbuild -bp --nodeps $1*.spec | ||
- | |||
- | ##we remove all patch from the spec file | ||
- | sed '/ | ||
- | sed '/ | ||
- | mv -f $1.ter.spec $1.spec | ||
- | rm -f $1.bis.spec | ||
- | |||
- | |||
- | ###test to see if the directory already exists in ~/git_work, if yes we use ~/ | ||
- | if [[ ! -d ~/ | ||
- | |||
- | gitexist=0 | ||
- | mkdir -p ~/ | ||
- | NameGitHub=$1 | ||
- | curl -u ' | ||
- | |||
- | cp -R ~/ | ||
- | cp ~/ | ||
- | cd ~/ | ||
- | |||
- | |||
- | elif [[ -d ~/ | ||
- | |||
- | gitexist=1 | ||
- | mkdir -p ~/ | ||
- | NameGitHub=$1-sdl | ||
- | curl -u ' | ||
- | |||
- | cp -R ~/ | ||
- | cp ~/ | ||
- | cd ~/ | ||
- | |||
- | fi | ||
- | | ||
- | | ||
- | ###git work | ||
- | |||
- | if [ ! -e README.md ]; then | ||
- | touch README.md | ||
- | echo "$1 is a RPM for SME Server, a Linux distro oriented server. see http:// | ||
- | fi | ||
- | |||
- | ## | ||
- | find * -type d -empty -exec touch {}/ | ||
- | |||
- | git init | ||
- | git add . | ||
- | git commit -m "first commit to SME Server" | ||
- | |||
- | if [[ $2 != ' | ||
- | git co -b $2 | ||
- | fi | ||
- | | ||
- | if [[ $gitexist = " | ||
- | git remote add origin git@github.com: | ||
- | git push -u -f origin $2 | ||
- | |||
- | elif [[ $gitexist = " | ||
- | git remote add origin git@github.com: | ||
- | git push -u -f origin $2 | ||
- | |||
- | fi | ||
- | |||
- | |||
- | ##find the apache authentication | ||
- | echo "" | ||
- | echo "" | ||
- | echo "we are looking if we need to modify the apache authentication" | ||
- | testapache=$(grep -srni ' | ||
- | if [[ $testapache =~ " | ||
- | echo " | ||
- | echo 'Only for SME9, you must add before $OUT .= " AuthBasicProvider external\n";' | ||
- | | ||
- | else | ||
- | echo "no apache authentication" | ||
- | fi | ||
- | |||
- | ## help to write the changelog | ||
- | myDate=$(LC_ALL=C date +"%a %b %d %Y") | ||
- | echo "" | ||
- | echo "* $myDate stephane de Labrusse < | ||
- | echo "- Initial release to SME Server" | ||
- | | ||
- | # a bit of clean | ||
- | |||
- | rm -rf ~/ | ||
- | | ||
- | ## say where we record the source code | ||
- | if [[ $gitexist = " | ||
- | echo "" | ||
- | echo " packages are in ~/ | ||
- | elif [[ $gitexist = " | ||
- | echo "" | ||
- | echo " packages are in ~/ | ||
- | fi | ||
- | </ | ||
- | |||
- | ====cvs_update==== | ||
- | a script to update all CVS entries of smeserver | ||
- | |||
- | Launch the script, all smeserver & smecontribs will be updated, adapt the path to your directory and to you cvs access. That script can be run the night to avoid lose time when you must work | ||
- | |||
- | usage | ||
- | cvs_update | ||
- | |||
- | #!/bin/bash | ||
- | | ||
- | location=$(pwd) | ||
- | | ||
- | echo "############################" | ||
- | echo " | ||
- | echo "############################" | ||
- | | ||
- | #first we update the smecontribs tree | ||
- | cd ~/ | ||
- | cvs -z3 -d: | ||
- | echo "############################" | ||
- | echo " | ||
- | echo "############################" | ||
- | echo "############################" | ||
- | echo " | ||
- | echo "############################" | ||
- | | ||
- | | ||
- | | ||
- | cd ~/ | ||
- | cvs -z3 -d: | ||
- | | ||
- | echo "############################" | ||
- | echo " | ||
- | echo "############################" | ||
- | | ||
- | | ||
- | cd $location | ||
- | |||
- | ====git_srpm==== | ||
- | This script is done to import a srpm and to push it after a ' | ||
- | |||
- | After that you can commit it if needed | ||
- | |||
- | < | ||
- | ### bit of tests to see if we will not do a mess | ||
- | if [[ -z $1 || -z $2 ]]; then | ||
- | echo "################################################################################################################################" | ||
- | echo "you must give arguments on the git branch (master, sme9, ns6 or anything else) and the package name : git_srpm package_name master" | ||
- | echo "################################################################################################################################" | ||
- | exit | ||
- | fi | ||
- | |||
- | | ||
- | | ||
- | | ||
- | echo "###################################" | ||
- | echo "the git directories ~/ | ||
- | echo " | ||
- | echo "think also if you have a github project called stephdl/ | ||
- | echo "###################################" | ||
- | exit | ||
- | fi | ||
- | | ||
- | # Create needed dirs on the build box | ||
- | | ||
- | mkdir -p ~/ | ||
- | mkdir -p ~/exchange | ||
- | mkdir -p ~/ | ||
- | | ||
- | rpm -ivh $1*.src.rpm | ||
- | cd ~/ | ||
- | | ||
- | | ||
- | ##we remove all patch from the spec file | ||
- | # sed '/ | ||
- | # sed '/ | ||
- | # mv -f $1.ter.spec $1.spec | ||
- | # rm -f $1.bis.spec | ||
- | | ||
- | | ||
- | cp -R ~/ | ||
- | cp ~/ | ||
- | cd ~/ | ||
- | | ||
- | ##fill empty directories | ||
- | find * -type d -empty -exec touch {}/ | ||
- | | ||
- | echo "Now you have to create the correct github remote repository and add the origin" | ||
- | echo " | ||
- | echo "" | ||
- | echo " | ||
- | echo " | ||
- | echo " | ||
- | echo " | ||
- | | ||
- | rm -f ~/ | ||
- | </ | ||
- | |||
- | ====Cron night Job==== | ||
- | |||
- | I don't like to wait so each night I do an init of mock on all configurations I need | ||
- | |||
- | * 2 * * * mock -r epel-5-x86_64 --init; mock -r epel-5-i386 --init | ||
- | * 3 * * * mock -r epel-6-x86_64 --init; mock -r epel-6-i386 --init | ||
- | * 4 * * * mock -r smeserver-9-x86_64-base --init; mock -r smeserver-9-i386-base --init | ||
- | * 5 * * * mock -r smeserver-8-x86_64-base --init; mock -r smeserver-8-i386-base --init | ||
- | * 6 * * * / | ||
- | |||
- | {{tag> rpm }} |