c06834a7d2c8702c57b980f219d8cfcda9e20d05
[rvm-ruby.git] / rpm / rvm-ruby.spec
1 %global rvm_dir /usr/lib/rvm
2 %global rvm_group rvm
3
4 # RVM can not be sourced with default /bin/sh
5 %define _buildshell /bin/bash
6
7 # PL conventions
8 %define name rvm-ruby
9 # pick a RVM version from https://github.com/wayneeseguin/rvm/tags
10 %define version 1.22.9
11 %define taglevel 8
12 %define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}}
13
14 Summary: Ruby Version Manager (including Rubies and Gems)
15 Name: %{name}
16 Version: %{version}
17 Release: %{release}
18 License: ASL 2.0
19 URL: http://rvm.io/
20 Group: Applications/System
21 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
22
23 BuildRequires: bash curl git
24 BuildRequires: gcc-c++ patch chrpath readline readline-devel zlib-devel libyaml-devel libffi-devel openssl-devel autoconf automake libtool bison
25 BuildRequires: sed grep tar gzip bzip2 make file
26 # for OMF:
27 BuildRequires: tar libxml2 libxml2-devel libxslt libxslt-devel
28
29 Requires(pre): shadow-utils
30 # For rvm
31 Requires: bash curl git
32 # Basics for building ruby 1.8/1.9
33 # We expect all the building to take place .. at build-time, so let's take this out
34 #Requires: gcc-c++ patch readline readline-devel zlib-devel libyaml-devel libffi-devel openssl-devel autoconf automake libtool bison
35 # Used by the scripts
36 Requires: sed grep tar gzip bzip2 make file
37 # for OMF:
38 Requires: libxml2 libxslt
39
40 %description
41 RVM is the Ruby Version Manager. It manages Ruby interpreter environments
42 and switching between them.
43
44 This package is meant for use by multiple users maintaining a shared copy of
45 RVM. Users added to the '%{rvm_group}' group will be able to modify all aspects
46 of RVM. These users will also have their default umask modified ("g+w") to allow
47 group write permission (usually resulting in a umask of "0002") in order to
48 ensure correct permissions for the shared RVM content.
49
50 RVM is activated for all logins by default. To disable remove
51 %{_sysconfdir}/profile.d/rvm.sh and source rvm from each users shell.
52
53 %install
54 rm -rf %{buildroot}
55
56 # Clean the env
57 for i in $(env | grep ^rvm_ | cut -d"=" -f1); do
58   unset $i;
59 done
60
61 # Install everything into one directory
62 (
63 export rvm_ignore_rvmrc=1 \
64   rvm_user_install_flag=0 \
65   rvm_path="%{buildroot}%{rvm_dir}" \
66   rvm_man_path="%{buildroot}%{_mandir}" \
67   HOME=%{buildroot}
68 \curl -L https://get.rvm.io | bash -s stable --version %{version}
69 )
70
71 # So members of the rvm group can write to it
72 find %{buildroot}%{rvm_dir} -exec chmod ug+w {} \;
73 find %{buildroot}%{rvm_dir} -type d -exec chmod g+s {} \;
74
75 mkdir -p %{buildroot}%{_sysconfdir}
76
77 # We use selfcontained so binaries end up in rvm/bin
78 cat > %{buildroot}%{_sysconfdir}/rvmrc <<END_OF_RVMRC
79 # Setup default configuration for rvm.
80 # If an rvm install exists in the home directory, don't load this.'
81 if [[ ! -s "\${HOME}/.rvm/scripts/rvm" ]]; then
82
83   # Only users in the rvm group need the umask modification
84   for i in \$(id -G -n); do
85     if [ \$i = "rvm" ]; then
86       umask g+w
87       break
88     fi
89   done
90
91   export rvm_user_install_flag=1
92   export rvm_path="%{rvm_dir}"
93 fi
94 END_OF_RVMRC
95
96 mkdir -p %{buildroot}%{_sysconfdir}/profile.d
97
98 cat > %{buildroot}%{_sysconfdir}/profile.d/rvm.sh <<END_OF_RVMSH
99 # rvm loading hook
100 #
101 if [ -s "\${HOME}/.rvm/scripts/rvm" ]; then
102   source "\${HOME}/.rvm/scripts/rvm"
103 elif [ -s "%{rvm_dir}/scripts/rvm" ]; then
104   source "%{rvm_dir}/scripts/rvm"
105 fi
106 END_OF_RVMSH
107
108 chmod 755 %{buildroot}%{_sysconfdir}/profile.d/rvm.sh
109
110 # At this point, install of RVM is finished
111 # Now install some rubies
112
113 # Run this in a subshell so the rvm loading does not infect our current shell.
114 (
115 export rvm_ignore_rvmrc=1
116 export rvm_user_install_flag=0
117 export rvm_path="%{buildroot}%{rvm_dir}"
118 export rvm_man_path="%{buildroot}%{_mandir}"
119 source ${rvm_path}/scripts/rvm
120 gemi='gem install --no-ri --no-rdoc'
121
122 ruby_tag=ruby-1.9.3-p286
123 rvm install $ruby_tag --verify-downloads 1
124 rvm use $ruby_tag
125 rvm gemset create omf
126 rvm use $ruby_tag@omf --default
127 $gemi omf_rc
128 #$gemi whatever_gem_you_need
129
130 #ruby_tag=ruby-1.8.7-p352
131 #rvm install $ruby_tag
132 #rvm use $ruby_tag
133 rvm cleanup all
134 )
135
136 export br=%{buildroot}
137
138 # Strip binaries
139 #find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep 'not stripped' |cut -f1 -d: |xargs -r strip
140
141 # Strip and Fix bad paths in generated files
142 # That is not optimized, but that is not supposed to be done often
143 for f in $(find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': ELF' |cut -f1 -d:); do
144   strip $f
145   grep "$br" $f || continue
146   line=$(chrpath -l $f) || continue
147   echo $line |grep "$br" || continue
148   chrpath -r $(echo $line |cut -f2 -d= |sed "s,$br,,") $f
149 done
150
151 # Replace bad paths in text files
152 find $br -type f \( -name \*.log -o -name \*.la \) -print0 |xargs -0 -r sed -i "s,$br,,g"
153 find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': .* text' |cut -f1 -d: |xargs -r sed -i "s,$br,,g"
154
155 # Replace bad paths in all remaining files
156 # Padding with zeroes broke the LOAD_PATH in libruby, therefore prepend path with harmless forward slashes
157 printf -vch "%${#br}s" ""
158 slashes=$(printf "%s" "${ch// //}")
159 find $br -type f -print0 | xargs -0 sed -i "s,$br,$slashes,g"
160
161 # Fix symlinks with bad path
162 # the canonical path of the build root
163 brc=$(readlink -f $br)
164 for f in $(find $br -type l); do
165     # some symlinks are relative, in which case we want to preserve them
166     # do *not* mention -f here as it would always return an absolute path
167     dest=$(readlink $f)
168     # relative symlinks have $dest not starting with a /
169     first_step=$(echo $dest | cut -d / -f1)
170     # absolute paths have a void first_step 
171     if [ -z "$first_step" ] ; then
172         # destination is an absolute path, let's fix it
173         # call readlink with -f so all symlinmks are solved
174         # and so we can reliably substitute $brc that is also canonicalized
175         destc=$(readlink -f $f | sed -e "s,^$brc,,")
176         ln -sfn $destc $f
177     fi
178 done
179
180 find $br -maxdepth 1 -name '.*' -exec rm -rf {} \;
181 rm $br/usr/share/man/man1/rvm.1.gz
182
183 %clean
184 rm -rf %{buildroot}
185 # it appears that, because we build as root, rvm installs stuff in /etc on the build box
186 # which is not desirable, so let us get rid of that - don't worry if that fails
187 find /etc -name 'rvm*' | xargs rm || :
188
189 %pre
190 getent group %{rvm_group} >/dev/null || groupadd -r %{rvm_group}
191 exit 0
192
193 %files
194 %defattr(-,root,root)
195 %config(noreplace) /etc/rvmrc
196 %config(noreplace) /etc/profile.d/rvm.sh
197 %attr(-,root,%{rvm_group}) %{rvm_dir}
198 %{_mandir}/man1/*
199
200 %changelog
201 * Sun Jul 14 2013 Thierry Parmentelat - rvm-ruby-1.20.10-8
202 - create an omf gemset (in rvm-ruby-1.20.10-7)
203 - make omf the default gemset
204 - add libxml2 and lixslt dependencies for omf
205
206 * Tue Jun 25 2013 Thierry Parmentelat - rvm-ruby-1.20.10-6
207 - add omf-rc in the mix
208
209 * Fri May 18 2013 Christoph Dwertmann - 4.xxx
210 - downloads RVM instead of relying on local sources
211 - works with latest RVM and Fedora
212 - removed ruby build dependency
213 - no more clashing with distribution ruby
214
215 * Fri Mar 30 2012 Alexandre Fouche - 3.xxx
216 Add some rubies and gems to compile:
217 - 1.9.2-p290 + bundler, bluepill, whenever
218 - 1.9.3-p0 + bundler, bluepill, whenever
219
220 * Thu Mar 29 2012 Alexandre Fouche - 2.xxx
221 - Adapt <https://github.com/mdkent/rvm-rpm/blob/master/SPECS/rvm-ruby.spec> to make it work from RVM git source directly
222 - Strip binaries, libraries, ...
223
224 * Thu Mar 29 2012 Alexandre Fouche - 1.xxx
225 - Adapt <https://github.com/mdkent/rvm-rpm/blob/master/SPECS/rvm-ruby.spec> to make it work from RVM git source directly
226
227 * Tue Dec 13 2011 Matthew Kent <mkent@magoazul.com> - 1.10.0-2
228 - New upstream release
229 - Drop rvm_prefix
230 - Rename rvm_user_install to rvm_user_install_flag
231 - Rename rake wrapper to rvm-rake
232 - Add file dependency
233
234 * Thu Aug 4 2011 Matthew Kent <mkent@magoazul.com> - 1.6.32-1
235 - New upstream release
236
237 * Tue Apr 19 2011 Matthew Kent <mkent@magoazul.com> - 1.6.3-1
238 - Initial package based off Gentoo work