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