LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-08-2011, 03:18 PM   #1
wills
LQ Newbie
 
Registered: Jun 2008
Posts: 28

Rep: Reputation: 0
Creating an RPM


I want to be able to create an RPM that will install python 2.7.1 along with sqlite 3.7.3, MySQL-Python-1.2.3 on a CentOS 5.5 x86_64 host(s) in a directory (e.g. /opt/python2.7). Once that's done, I want to be able to alias the new python binary in .bash_profile so that my developers can begin using it.

I understand 2.7.1 can't be installed on a CentOS host but I've done the above using a shell script successfully. If you search hard enough, I posted my script on line

However, I need to create the RPM for political reasons. Besides placing the source file(s) in the SOURCES directory, what do I need to do in the spec to be able to successfully create an RPM installer?

Please be gentle with me. I've been drinking the Windows cool-aid for most of my IT career so, this is one of my first attempts of becoming a better DevOps Admin.

Any guidance would be much appreciated.

Thanks.
 
Old 03-08-2011, 04:54 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by wills View Post
I want to (..) create an RPM that will install python 2.7.1 along with sqlite 3.7.3, MySQL-Python-1.2.3 on a CentOS 5.5 x86_64 host(s) in a directory (e.g. /opt/python2.7).
If you intend to create a package containing all three pieces of SW then you are likely to break Centos' package management. That may not sound like a problem right now but down the line it will be (I have just enough RPM packageing-fu knowledge to be dangerous). So as long as you intend to create separate packages for python-2.7.1, sqlite-3.7.3 and MySQL-Python-1.2.3 it should work (shoehorning or not) and you would still maintain a certain degree of compatibility.


Quote:
Originally Posted by wills View Post
I want to be able to alias the new python binary in .bash_profile so that my developers can begin using it.
Patching all current unprivileged users shell profiles and /etc/skel/.* (or modifying /etc/bash.*) may provide "interesting" results so I really would suggest this to be done outside of the RPM.


Quote:
Originally Posted by wills View Post
I posted my script on line
CYP post the URI here?


Quote:
Originally Posted by wills View Post
Besides placing the source file(s) in the SOURCES directory, what do I need to do in the spec to be able to successfully create an RPM installer?
Package creation should be done as unprivileged user to maintain integrity of your workstation (you don't build on production hosts, right?). RPM Package creation ('man rpmbuild') is driven by a .spec file which handles the package meta data, installation and any pre and post-installation scripting. Really not that hard. If you post your script to install python-2.7.1 (preferably in BB code tags) and the name of the tarball to use I'll transmogrify it into a .spec file and explain all of the regular chicken-passing, drawing veves with Penn oil, calling of Loa and such :-]
 
1 members found this post helpful.
Old 03-08-2011, 04:59 PM   #3
wills
LQ Newbie
 
Registered: Jun 2008
Posts: 28

Original Poster
Rep: Reputation: 0
I meant to post the URI. Oh well, here is the bash script:

Code:
# chmod +x install-python.sh
# ./install-python.sh

#!/bin/bash
# Install necessary packages
yum -y install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-develsqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make

cd /var/tmp
wget http://sqlite.org/sqlite-amalgamation-3.7.3.tar.gz
tar xfz sqlite-amalgamation-3.7.3.tar.gz
cd sqlite-3.7.3/
./configure
make
make install

cd /var/tmp
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar xvfz Python-2.7.1.tgz
cd Python-2.7.1
./configure --prefix=/opt/python2.7.1 --with-threads --enable-shared
make
make install

touch /etc/ld.so.conf.d/opt-python2.7.1.conf
echo "/opt/python2.7.1/lib/" >> /etc/ld.so.conf.d/opt-python2.7.1.conf
ldconfig

ln -sf /opt/python2.7.1/bin/python /usr/bin/python2.7

cd /var/tmp
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg --prefix=/opt/python2.7.1

/opt/python2.7.1/bin/easy_install pip
ln -sf /opt/python2.7.1/bin/pip /usr/bin/pip

pip install virtualenv
ln -sf /opt/python2.7.1/bin/virtualenv /usr/bin/virtualenv

echo "alias python=/opt/python2.7.1/bin/python" >> ~/.bash_profile
echo "alias python2.7=/opt/python2.7.1/bin/python" >> ~/.bash_profile
echo "PATH=$PATH:/opt/python2.7/bin" >> ~/.bash_profile
source ~/.bash_profile

# Done
 
Old 03-08-2011, 06:18 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
0. Read http://www.ibm.com/developerworks/library/l-rpm1/, http://www-106.ibm.com/developerworks/library/l-rpm2/, http://www.rpm.org/RPM-HOWTO/ and https://fedoraproject.org/wiki/Packaging/Guidelines
1. Run 'mkdir -p /home/wills/redhat/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}'
2. Save http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz as /home/wills/redhat/SOURCES/Python-2.7.1.tgz
3. Create the below as "/home/wills/redhat/SPECS/python-2.7.1.spec":
Code:
# Don't build debuginfo packages:
%define debug_packages	%{nil}
%define debug_package %{nil}
# Package name:
%define name python
# Version:
%define ver 2.7.1
# Release:
%define rel 1
# RPM meta data:
Name: %{name}
Summary: %{name}
Version: %{ver}
Release: %{rel}
License: GPL
Group: Development/Languages
Source0: http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
BuildRequires: gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-develsqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make
Provides: %{name}
URL: http://www.python.org
BuildRoot: %{_tmppath}/%{name}-%{version}
#
%description 
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).

Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface. This package contains most of the standard
Python modules, as well as modules for interfacing to the Tix widget
set for Tk and RPM.

Note that documentation for Python is provided in the python-docs
package.

# Here we start building the package:
# This preps dir $RPM_BUILD_DIR/%{name}-%{version}.%{release}/.
%prep
# or %setup if a tarball
%setup

%build
%configure --prefix=/opt/python2.7.1 --with-threads --enable-shared
make

%install
make DESTDIR=$RPM_BUILD_ROOT install
# Pre-%files stage inventory
find $RPM_BUILD_ROOT -not -type d -printf "%%%attr(%%m,root,root) %%p\n" | sed -e "s|$RPM_BUILD_ROOT||g" > %{_tmppath}/%{name}_contents.txt

%clean
[ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}" ] && rm -rf $RPM_BUILD_ROOT

# Any pre or post installation scripts run from here:
%post
echo "/opt/python2.7.1/lib/" >> /etc/ld.so.conf.d/opt-python2.7.1.conf
ldconfig
ln -sf /opt/python2.7.1/bin/python /usr/bin/python2.7
# Create a separate script that can be sourced on user login and can be removed:
umask 0022
echo "[ `id -u` -ge 500 ] && { \" >> /etc/profile.d/python.sh
echo "alias python='/opt/python2.7.1/bin/python' \" >> /etc/profile.d/python.sh
echo "alias python2.7='/opt/python2.7.1/bin/python' \" >> /etc/profile.d/python.sh
echo "PATH=$PATH:/opt/python2.7/bin; }" >> /etc/profile.d/python.sh

%preun
# Remove regardless of update or uninstall:
[ -e /etc/ld.so.conf.d/opt-python2.7.1.conf ] && rm -f /etc/ld.so.conf.d/opt-python2.7.1.conf
[ -e /etc/profile.d/python.sh ] && rm -f /etc/profile.d/python.sh

%postun
ldconfig

# Auto-fill in the files section. (http://docs.fedoraproject.org/drafts/rpm-guide-en/ch09s05.html)
# This and the changelog entries mark the end of package creation.
# 
%files -f %{_tmppath}/%{name}_contents.txt

%changelog
* Tue Mar 08 2011 %{packager}
- Testing, testing, one, two...
4. Run 'rpmbuild -bb /home/wills/redhat/SPECS/python-2.7.1.spec 2>&1 | tee /home/wills/redhat/BUILD/python-2.7.1.tee'.
5. Read back /home/wills/redhat/BUILD/python-2.7.1.tee if there's any errors and post relevant lines here.
 
1 members found this post helpful.
Old 03-08-2011, 07:22 PM   #5
wills
LQ Newbie
 
Registered: Jun 2008
Posts: 28

Original Poster
Rep: Reputation: 0
Nice! I will usually make every effort to read the docs before posting questions. I know time is precious so, my intention is to not waste yours. That being said, I need to thank you for the help I had create a spec file but my first mistake was to wrap sqlite and MySQL-Python in there, which goes back to your original reply.

I ran rpmbuild, here is what it's complaining about:
bzip2-develsqlite-devel - assuming (not a good word) that this is referring to bzip2-devel but I noticed that in my script as well so, that's a problem that I caused. Removing that particular package allowed me to go further, but not before running into a new error:

Code:
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd python-2.7.1
/var/tmp/rpm-tmp.51404: line 37: cd: python-2.7.1: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.51404 (%prep)
Here is what I have for the directory structure:

[wills@host27 ~]$ tree redhat/

redhat/
|-- BUILD
| `-- python-2.7.1.tee
|-- RPMS
|-- SOURCES
| `-- Python-2.7.1.tgz
|-- SPECS
| `-- python-2.7.1.spec
|-- SRPMS
`-- tmp

So I switched from /home/wills/redhat to /usr/src/redhat but it continues to do the same. I've got some more reading to do now.
 
Old 03-09-2011, 12:46 AM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
? have you killed CentOS 5.5 yet with a second and different version of python ?

i would NOT make that into a rpm
but build and install into /opt from source and install it to /opt/Python-2.7 and leave that folder OUT of the system $PATH

then point any program that needs it to that folder when you build that from source

cent uses python for yum and MOST of Gnome
and changing the version WILL kill yum if you are not VERY VERY careful .
 
Old 03-10-2011, 03:42 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by wills View Post
I ran rpmbuild, here is what it's complaining about: bzip2-develsqlite-devel - assuming (not a good word) that this is referring to bzip2-devel but I noticed that in my script as well so, that's a problem that I caused.
My bad: just split "bzip2-develsqlite-devel" into "bzip2-devel sqlite-devel".



Quote:
Originally Posted by wills View Post
Code:
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd python-2.7.1
/var/tmp/rpm-tmp.51404: line 37: cd: python-2.7.1: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.51404 (%prep)
(..) So I switched from /home/wills/redhat to /usr/src/redhat but it continues to do the same. I've got some more reading to do now.
No, apparently the tarball expands to "Python-2.7.1" instead of "python-2.7.1". That's just plain *dumb* as developers should know *N{I,U}X are case sensitive. For now I would suggest 'cd ~/redhat/SOURCES && wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz && tar -xzf Python-2.7.1.tgz && mv Python-2.7.1 python-2.7.1 && tar -czf python-2.7.1.tar.gz python-2.7.1' and change the "Source0: http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz" line to read "Source0: python-2.7.1.tgz".




Quote:
Originally Posted by John VV View Post
cent uses python for yum and MOST of Gnome and changing the version WILL kill yum if you are not VERY VERY careful .
Good call, yes, but do note he uses "%configure --prefix=/opt/python2.7.1" already.

[EDIT]Should be %configure --prefix=/opt/python-2.7.1[/EDIT]
 
Old 11-01-2012, 04:26 PM   #8
kdoswald
LQ Newbie
 
Registered: Jan 2001
Location: california
Posts: 5

Rep: Reputation: 0
I know this was posted quite a while ago.

I am trying to get python 2.7.1 to compile. But I get error

rocessing files: python-2.7.1-1.x86_64
error: File not found: /root/rpmbuild/BUILDROOT/python-2.7.1-1.x86_64/usr/share/man/man1/python2.7.1


RPM build errors:
File not found: /root/rpmbuild/BUILDROOT/python-2.7.1-1.x86_64/usr/share/man/man1/python2.7.1


This is on a Centos 6.3 box.

Anyone have any ideas?
 
Old 11-01-2012, 05:33 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by kdoswald View Post
I know this was posted quite a while ago.
It took you more than a decennium to post again so let's not be picky ;-p


Quote:
Originally Posted by kdoswald View Post
Anyone have any ideas?
In no particular order:
- ensure you've got valid and compelling reasons to muck with Python: it's a core system dependency and fscking up means you're SOL.
- please don't compile and package as root: it's an unnecessary risk.
- "/usr/share/man/man1/python2.7.1" may actually be "/usr/share/man/man1/python2.7.1.gz". Check and modify the .spec file.
 
Old 11-01-2012, 06:16 PM   #10
kdoswald
LQ Newbie
 
Registered: Jan 2001
Location: california
Posts: 5

Rep: Reputation: 0
You are correct the file is .gz , it is not referenced in the spec file though.

I figured someone would mention the /root

It is necessary or I would not.
 
Old 11-01-2012, 07:56 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by kdoswald View Post
You are correct the file is .gz , it is not referenced in the spec file though.
To forestall more "interestingness" maybe it would be easier to add this line at the end of your %install section:
Code:
find $RPM_BUILD_ROOT -not -type d -printf "%%%attr(%%m,root,root) %%p\n" | grep -v etc/ | sed -e "s|$RPM_BUILD_ROOT||g" -e "s|.*/man/.*$|\0.gz|g" >> %{_tmppath}/%{name}_contents.txt
and then replace the %files section to read:
Code:
%files -f %{_tmppath}/%{name}_contents.txt
and be done with it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pb creating a RPM freaks_s Red Hat 3 10-12-2010 10:43 AM
Help creating a php5 rpm actifed Red Hat 8 02-18-2010 06:13 PM
Creating an RPM that installs in a directory made by another RPM erinfin Linux - Software 4 11-15-2007 05:10 PM
Creating RPM Debugger Programming 2 11-14-2006 02:53 AM
Creating RPM. jayakrishnan Linux - General 1 04-10-2002 12:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration