Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 233 lines (198 sloc) 7.203 kb
e59261f @rtomayko split package registration and installation into separate programs
authored
1 #!/bin/sh
2 # The `rpg-package-install` program perform the actual installation of files
3 # into the system installation locations. The `<package>` and `<version>`
4 # supplied must already be registered in the package database as by invoking
5 # the `rpg-package-register` program.
6 #
7 # If the package is already installed and at the version specified,
8 # `rpg-package-install` exits immediately with a success exit status. The
9 # `-f` argument can be used to force the install operations to be performed
10 # on an already installed program.
11 set -e
12 . rpg-sh-setup
13
14 [ "$*" ] || set -- '--help'; ARGV="$@"
15 USAGE '${PROGNAME} [-f] <package> <version> ...
16 Install a registered package from the database.
17
18 This is a low level command. For an install front-end, see rpg-install(1).'
19
20 force=false
21 test "$1" = '-f' && {
22 force=true
23 shift
24 }
25
26 [ "$1$2" ] || {
27 warn "invalid arguments: '$*'";
28 exit 2
29 }
30
31 # Utility Functions
32 # -----------------
33
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
34 # Usage: `installfile <source> <dest>`
35 #
36 # Attempt to hard link `<dest>` to `<source>` but fall back to `cp(1)` if
37 # you're crossing file systems or `ln` fails otherwise.
38 installfile () {
56f3312 @rtomayko create extension lib directories before copying
authored
39 if ln -f "$1" "$2" 2>/dev/null
e59261f @rtomayko split package registration and installation into separate programs
authored
40 then notice "$2 [ln]"
41 else notice "$2 [cp]"
42 cp "$1" "$2"
43 fi
44 }
45
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
46 # Usage: `installdir <source> <dest>`
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
47 #
e59261f @rtomayko split package registration and installation into separate programs
authored
48 # Recursive file hierarchy copy routine. Attempts to hardlink files
49 # and falls back to normal copies.
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
50 installdir () {
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
51 mkdir -p "$2"
e59261f @rtomayko split package registration and installation into separate programs
authored
52 for file in "$1"/*
53 do
8f1f43d @richmeyers Fix rpg-package-install when gem contains empty dirs in lib.
richmeyers authored
54 if ! test -e "$file"
55 then
56 # no files in directory - * was not expanded
57 :
58
59 elif test -f "$file"
e59261f @rtomayko split package registration and installation into separate programs
authored
60 then # link dest to source
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
61 installfile "$file" "$2/$(basename $file)"
62 echo "$2/$(basename $file)"
e59261f @rtomayko split package registration and installation into separate programs
authored
63
64 elif test -d "$file"
65 then # recurse into directories
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
66 installdir "$file" "$2/$(basename $file)"
e59261f @rtomayko split package registration and installation into separate programs
authored
67
68 else warn "unknown file type: $file"
69 return 1
70 fi
71 done
72 return 0
73 }
74
75 # Package Database Prep
76 # ---------------------
77
78 # Establish our directories in the package database. These should
79 # have already been created by `rpg-package-register`. If not, bail
80 # out now since something isn't right.
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
81 package="$1" version="$2"; shift 2
82 test "$version" = '=' && { version="$1"; shift; }
e59261f @rtomayko split package registration and installation into separate programs
authored
83 packagedir="$RPGDB/$package"
84
85 test -d "$packagedir/$version" || {
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
86 warn "package not registered: $package $version"
e59261f @rtomayko split package registration and installation into separate programs
authored
87 exit 1
88 }
89
0ce8a80 @rtomayko rpg-install uses delta file unless forced with -f
authored
90 heed "$package $version"
e59261f @rtomayko split package registration and installation into separate programs
authored
91
92 # Fetch the gem into the cache and unpack into the packs area if
93 # its not already there.
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
94 if ! $force && test -d "$RPGPACKS/$package-$version"
f5f7140 @rtomayko rpg-install -s actually resumes the session
authored
95 then notice "$package $version sources exist. bypassing fetch / unpack."
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
96 else rm -rf "$RPGPACKS/$package-$version"
97 gemfile=$(rpg-fetch "$package" "$version")
e59261f @rtomayko split package registration and installation into separate programs
authored
98 notice "unpacking $gemfile into $RPGPACKS"
99 mkdir -p "$RPGPACKS"
64c9edb @rtomayko rpg-unpack writes name of unpack directory to stdout
authored
100 rpg-unpack -p "$RPGPACKS" "$gemfile" >/dev/null
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
101 rpg-shit-list "$package" "$version" "$RPGPACKS/$package-$version"
e59261f @rtomayko split package registration and installation into separate programs
authored
102 fi
103
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
104 # If the package already has an active/installed version, check if it's
e59261f @rtomayko split package registration and installation into separate programs
authored
105 # the same as the one we're installing and bail if so. Otherwise unlink
106 # the active version and install over it for now.
107 test -e "$packagedir/active" && {
108 activevers=$(readlink $packagedir/active)
109 if test "$activevers" = "$version"
110 then
111 if $force
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
112 then notice "$package $version is current; reinstalling due to -f"
e59261f @rtomayko split package registration and installation into separate programs
authored
113 unlink "$packagedir/active"
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
114 else notice "$package $version is current; skipping package install"
e59261f @rtomayko split package registration and installation into separate programs
authored
115 exit 0
116 fi
117 else notice "$package $activevers is installed but $version requested"
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
118 rpg-uninstall "$package"
e59261f @rtomayko split package registration and installation into separate programs
authored
119 fi
120 }
121
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
122 # Path to the unpacked package directory.
123 pack="$RPGPACKS/$package-$version"
124
e59261f @rtomayko split package registration and installation into separate programs
authored
125 # Symlink the `installing` file to the version directory. This will let us
126 # detect in progress or failed installations.
127 ln -sf "$version" "$packagedir/installing"
128
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
129 # Anything written to standard output within the main install block is
130 # written to the install manifest. The manifest should include full paths to
131 # all files installed
132 manifest="$packagedir/$version/manifest"
133 {
8b06f12 @rtomayko write package name and date to manifest file so we see it on rpg-manifes...
authored
134 echo "# $package $version ($(date))"
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
135
136 # Extension Libraries
137 # -------------------
138
139 # Build extension libraries if they exist. Bail out if the build fails.
140 exts="$(rpg-build "$pack")" || {
141 warn "extension failed to build"
142 exit 1
143 }
144
145 # Install any extensions to `RPGLIB`. This is kind of tricky. We should
146 # be running `make` in the extension directory but I haven't had time to
147 # make it work right so just pull the prefix out of the `Makefile` and
148 # install the shared libs manually.
149 test -n "$exts" && {
150 mkdir -p "$RPGLIB"
151 echo "$exts" |
152 while read dl
153 do
154 prefix=$(sed -n 's/^target_prefix *= *//p' "$(dirname $dl)/Makefile")
b28e4bc @rtomayko fix packages like url_escape that say their target_prefix is /ext
authored
155 test "$prefix" = "/ext" && prefix=""
77d2211 @rtomayko extension prefix needs to come after RUBYARCH
authored
156 dest="${RPGLIB}/${RUBYARCH}${prefix}/$(basename $dl)"
157 mkdir -p "${RPGLIB}/${RUBYARCH}${prefix}"
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
158 installfile "$dl" "$dest"
159 echo "$dest"
160 done
161 }
162
163 # Ruby Library Files
164 # ------------------
165
166 # Recursively install all library files into `RPGLIB`.
5b244c3 @rtomayko install all libdirs specified by gemspec require_paths
authored
167 #
168 # A big majority of packages have a single lib directory but some use an
169 # alternative libdir (ruby-debug) and it's also possible to have multiple
170 # lib directories. Use the `require_paths` gemspec value to determine lib
171 # sub-directories, ignoring certain incorrect values (`test`, `ext`, `spec`,
172 # etc.).
173
174 libdirs=$(cat "$packagedir/$version/require_paths" 2>&1)
175 : ${libdirs:=lib}
176
177 for libdir in $libdirs
178 do
179 test "$libdir" = "ext" && continue
180 test "$libdir" = "test" && continue
181 test "$libdir" = "spec" && continue
182
183 if test -d "$pack/$libdir"
184 then mkdir -p "$RPGLIB"
185 installdir "$pack/$libdir" "$RPGLIB"
186 else notice "warning: $package libdir '$libdir' does not exist"
187 fi
188 done
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
189
190 # Ruby Executables
191 # ----------------
192
babdb18 @richmeyers Correctly handle gems whose bindir is not "bin" (e.g. rspec-core)
richmeyers authored
193 bindir=$(cat "$packagedir/$version/bindir" 2>&1)
194 : ${bindir:=bin}
195
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
196 # Write executable scripts into `RPGBIN` and rewrite shebang lines.
babdb18 @richmeyers Correctly handle gems whose bindir is not "bin" (e.g. rspec-core)
richmeyers authored
197 test -d "$pack/$bindir" && {
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
198 mkdir -p "$RPGBIN"
babdb18 @richmeyers Correctly handle gems whose bindir is not "bin" (e.g. rspec-core)
richmeyers authored
199 for file in "$pack/$bindir"/*
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
200 do dest="$RPGBIN/$(basename $file)"
201 notice "$dest [!]"
202 sed "s@^#!.*ruby.*@#!$(ruby_command)@" <"$file" >"$dest"
203 chmod 0755 "$dest"
204 echo "$dest"
205 done
206 }
207
208 # Manpages
209 # --------
210
211 # Install any manpages included with the package into `RPGMAN`. Make
212 # sure files are being installed under the prescribed hierarchy.
213 test -d "$pack/man" && {
214 for file in "$pack/man"/*
215 do
216 if test -f "$file" &&
217 expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
218 then
219 section=${file##*\.}
220 dest="$RPGMAN/man$section/$(basename $file)"
221 mkdir -p "$RPGMAN/man$section"
222 installfile "$file" "$dest"
223 echo "$dest"
224 fi
225 done
226 }
227
228 } > "$manifest"
e59261f @rtomayko split package registration and installation into separate programs
authored
229
230 # Mark this package as active
231 unlink "$packagedir/installing"
232 ln -sf "$version" "$packagedir/active"
Something went wrong with that request. Please try again.