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