Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 212 lines (182 sloc) 6.441 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" || {
81 warn "package not registered: $package/$version"
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"
0783e80 @rtomayko rpg-unpack for extracting gems and gemspecs
authored
95 rpg-unpack -p "$RPGPACKS" "$gemfile"
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
99 # If the package already has an active/installed version, check if its
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 #
103 # TODO handle uninstalling previous package version or fail or something.
104 test -e "$packagedir/active" && {
105 activevers=$(readlink $packagedir/active)
106 if test "$activevers" = "$version"
107 then
108 if $force
109 then notice "$package $version is current. reinstalling due to -f"
110 unlink "$packagedir/active"
111 else notice "$package $version is current. not reinstalling."
112 exit 0
113 fi
114 else notice "$package $activevers is installed but $version requested"
115 unlink "$packagedir/active"
116 fi
117 }
118
bbf5937 @rtomayko rpg-shit-list fixes up non-compatible packages
authored
119 # Path to the unpacked package directory.
120 pack="$RPGPACKS/$package-$version"
121
e59261f @rtomayko split package registration and installation into separate programs
authored
122 # This is our file manifest. We record everything installed in here
123 # so we know how to uninstall the package. Create/truncate it in case
124 # it already exists.
125 #
126 # Symlink the `installing` file to the version directory. This will let us
127 # detect in progress or failed installations.
128 ln -sf "$version" "$packagedir/installing"
129
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
130 # Anything written to standard output within the main install block is
131 # written to the install manifest. The manifest should include full paths to
132 # all files installed
133 manifest="$packagedir/$version/manifest"
134 {
135 echo "# $(date)"
136
137 # Extension Libraries
138 # -------------------
139
140 # Build extension libraries if they exist. Bail out if the build fails.
141 exts="$(rpg-build "$pack")" || {
142 warn "extension failed to build"
143 exit 1
144 }
145
146 # Install any extensions to `RPGLIB`. This is kind of tricky. We should
147 # be running `make` in the extension directory but I haven't had time to
148 # make it work right so just pull the prefix out of the `Makefile` and
149 # install the shared libs manually.
150 test -n "$exts" && {
151 mkdir -p "$RPGLIB"
152 echo "$exts" |
153 while read dl
154 do
155 prefix=$(sed -n 's/^target_prefix *= *//p' "$(dirname $dl)/Makefile")
156 dest="${RPGLIB}${prefix}/$(basename $dl)"
157 mkdir -p "${RPGLIB}${prefix}"
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`.
167 test -d "$pack/lib" && {
168 mkdir -p "$RPGLIB"
169 installdir "$pack/lib" "$RPGLIB"
170 }
171
172 # Ruby Executables
173 # ----------------
174
175 # Write executable scripts into `RPGBIN` and rewrite shebang lines.
176 test -d "$pack/bin" && {
177 mkdir -p "$RPGBIN"
178 for file in "$pack/bin"/*
179 do dest="$RPGBIN/$(basename $file)"
180 notice "$dest [!]"
181 sed "s@^#!.*ruby.*@#!$(ruby_command)@" <"$file" >"$dest"
182 chmod 0755 "$dest"
183 echo "$dest"
184 done
185 }
186
187 # Manpages
188 # --------
189
190 # Install any manpages included with the package into `RPGMAN`. Make
191 # sure files are being installed under the prescribed hierarchy.
192 test -d "$pack/man" && {
193 for file in "$pack/man"/*
194 do
195 if test -f "$file" &&
196 expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
197 then
198 section=${file##*\.}
199 dest="$RPGMAN/man$section/$(basename $file)"
200 mkdir -p "$RPGMAN/man$section"
201 installfile "$file" "$dest"
202 echo "$dest"
203 fi
204 done
205 }
206
207 } > "$manifest"
e59261f @rtomayko split package registration and installation into separate programs
authored
208
209 # Mark this package as active
210 unlink "$packagedir/installing"
211 ln -sf "$version" "$packagedir/active"
Something went wrong with that request. Please try again.