Skip to content
Newer
Older
100644 228 lines (194 sloc) 6.93 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
54 if test -f "$file"
55 then # link dest to source
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
56 installfile "$file" "$2/$(basename $file)"
57 echo "$2/$(basename $file)"
e59261f @rtomayko split package registration and installation into separate programs
authored
58
59 elif test -d "$file"
60 then # recurse into directories
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
61 installdir "$file" "$2/$(basename $file)"
e59261f @rtomayko split package registration and installation into separate programs
authored
62
63 else warn "unknown file type: $file"
64 return 1
65 fi
66 done
67 return 0
68 }
69
70 # Package Database Prep
71 # ---------------------
72
73 # Establish our directories in the package database. These should
74 # have already been created by `rpg-package-register`. If not, bail
75 # out now since something isn't right.
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
76 package="$1" version="$2"; shift 2
77 test "$version" = '=' && { version="$1"; shift; }
e59261f @rtomayko split package registration and installation into separate programs
authored
78 packagedir="$RPGDB/$package"
79
80 test -d "$packagedir/$version" || {
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
81 warn "package not registered: $package $version"
e59261f @rtomayko split package registration and installation into separate programs
authored
82 exit 1
83 }
84
0ce8a80 @rtomayko rpg-install uses delta file unless forced with -f
authored
85 heed "$package $version"
e59261f @rtomayko split package registration and installation into separate programs
authored
86
87 # Fetch the gem into the cache and unpack into the packs area if
88 # its not already there.
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
89 if ! $force && test -d "$RPGPACKS/$package-$version"
f5f7140 @rtomayko rpg-install -s actually resumes the session
authored
90 then notice "$package $version sources exist. bypassing fetch / unpack."
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
91 else rm -rf "$RPGPACKS/$package-$version"
92 gemfile=$(rpg-fetch "$package" "$version")
e59261f @rtomayko split package registration and installation into separate programs
authored
93 notice "unpacking $gemfile into $RPGPACKS"
94 mkdir -p "$RPGPACKS"
64c9edb @rtomayko rpg-unpack writes name of unpack directory to stdout
authored
95 rpg-unpack -p "$RPGPACKS" "$gemfile" >/dev/null
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
96 rpg-shit-list "$package" "$version" "$RPGPACKS/$package-$version"
e59261f @rtomayko split package registration and installation into separate programs
authored
97 fi
98
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
99 # If the package already has an active/installed version, check if it's
e59261f @rtomayko split package registration and installation into separate programs
authored
100 # the same as the one we're installing and bail if so. Otherwise unlink
101 # the active version and install over it for now.
102 test -e "$packagedir/active" && {
103 activevers=$(readlink $packagedir/active)
104 if test "$activevers" = "$version"
105 then
106 if $force
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
107 then notice "$package $version is current; reinstalling due to -f"
e59261f @rtomayko split package registration and installation into separate programs
authored
108 unlink "$packagedir/active"
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
109 else notice "$package $version is current; skipping package install"
e59261f @rtomayko split package registration and installation into separate programs
authored
110 exit 0
111 fi
112 else notice "$package $activevers is installed but $version requested"
c51bcb3 @rtomayko uninstall prior package versions before installing new ones
authored
113 rpg-uninstall "$package"
e59261f @rtomayko split package registration and installation into separate programs
authored
114 fi
115 }
116
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
117 # Path to the unpacked package directory.
118 pack="$RPGPACKS/$package-$version"
119
e59261f @rtomayko split package registration and installation into separate programs
authored
120 # Symlink the `installing` file to the version directory. This will let us
121 # detect in progress or failed installations.
122 ln -sf "$version" "$packagedir/installing"
123
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
124 # Anything written to standard output within the main install block is
125 # written to the install manifest. The manifest should include full paths to
126 # all files installed
127 manifest="$packagedir/$version/manifest"
128 {
8b06f12 @rtomayko write package name and date to manifest file so we see it on rpg-mani…
authored
129 echo "# $package $version ($(date))"
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
130
131 # Extension Libraries
132 # -------------------
133
134 # Build extension libraries if they exist. Bail out if the build fails.
135 exts="$(rpg-build "$pack")" || {
136 warn "extension failed to build"
137 exit 1
138 }
139
140 # Install any extensions to `RPGLIB`. This is kind of tricky. We should
141 # be running `make` in the extension directory but I haven't had time to
142 # make it work right so just pull the prefix out of the `Makefile` and
143 # install the shared libs manually.
144 test -n "$exts" && {
145 mkdir -p "$RPGLIB"
146 echo "$exts" |
147 while read dl
148 do
149 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
150 test "$prefix" = "/ext" && prefix=""
77d2211 @rtomayko extension prefix needs to come after RUBYARCH
authored
151 dest="${RPGLIB}/${RUBYARCH}${prefix}/$(basename $dl)"
152 mkdir -p "${RPGLIB}/${RUBYARCH}${prefix}"
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
153 installfile "$dl" "$dest"
154 echo "$dest"
155 done
156 }
157
158 # Ruby Library Files
159 # ------------------
160
161 # Recursively install all library files into `RPGLIB`.
5b244c3 @rtomayko install all libdirs specified by gemspec require_paths
authored
162 #
163 # A big majority of packages have a single lib directory but some use an
164 # alternative libdir (ruby-debug) and it's also possible to have multiple
165 # lib directories. Use the `require_paths` gemspec value to determine lib
166 # sub-directories, ignoring certain incorrect values (`test`, `ext`, `spec`,
167 # etc.).
168
30f572d @richmeyers Redirect standard error into bitbucket in rpg-package-install.sh.
richmeyers authored
169 libdirs=$(cat "$packagedir/$version/require_paths" 2>/dev/null)
5b244c3 @rtomayko install all libdirs specified by gemspec require_paths
authored
170 : ${libdirs:=lib}
171
172 for libdir in $libdirs
173 do
174 test "$libdir" = "ext" && continue
175 test "$libdir" = "test" && continue
176 test "$libdir" = "spec" && continue
177
178 if test -d "$pack/$libdir"
179 then mkdir -p "$RPGLIB"
180 installdir "$pack/$libdir" "$RPGLIB"
181 else notice "warning: $package libdir '$libdir' does not exist"
182 fi
183 done
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
184
185 # Ruby Executables
186 # ----------------
187
30f572d @richmeyers Redirect standard error into bitbucket in rpg-package-install.sh.
richmeyers authored
188 bindir=$(cat "$packagedir/$version/bindir" 2>/dev/null)
babdb18 @richmeyers Correctly handle gems whose bindir is not "bin" (e.g. rspec-core)
richmeyers authored
189 : ${bindir:=bin}
190
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
191 # 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
192 test -d "$pack/$bindir" && {
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
193 mkdir -p "$RPGBIN"
babdb18 @richmeyers Correctly handle gems whose bindir is not "bin" (e.g. rspec-core)
richmeyers authored
194 for file in "$pack/$bindir"/*
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
195 do dest="$RPGBIN/$(basename $file)"
196 notice "$dest [!]"
197 sed "s@^#!.*ruby.*@#!$(ruby_command)@" <"$file" >"$dest"
198 chmod 0755 "$dest"
199 echo "$dest"
200 done
201 }
202
203 # Manpages
204 # --------
205
206 # Install any manpages included with the package into `RPGMAN`. Make
207 # sure files are being installed under the prescribed hierarchy.
208 test -d "$pack/man" && {
209 for file in "$pack/man"/*
210 do
211 if test -f "$file" &&
212 expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
213 then
214 section=${file##*\.}
215 dest="$RPGMAN/man$section/$(basename $file)"
216 mkdir -p "$RPGMAN/man$section"
217 installfile "$file" "$dest"
218 echo "$dest"
219 fi
220 done
221 }
222
223 } > "$manifest"
e59261f @rtomayko split package registration and installation into separate programs
authored
224
225 # Mark this package as active
226 unlink "$packagedir/installing"
227 ln -sf "$version" "$packagedir/active"
Something went wrong with that request. Please try again.