Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 210 lines (180 sloc) 6.39 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"
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
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 # This is our file manifest. We record everything installed in here
121 # so we know how to uninstall the package. Create/truncate it in case
122 # it already exists.
123 #
124 # Symlink the `installing` file to the version directory. This will let us
125 # detect in progress or failed installations.
126 ln -sf "$version" "$packagedir/installing"
127
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
128 # Anything written to standard output within the main install block is
129 # written to the install manifest. The manifest should include full paths to
130 # all files installed
131 manifest="$packagedir/$version/manifest"
132 {
8b06f12 @rtomayko write package name and date to manifest file so we see it on rpg-mani…
authored
133 echo "# $package $version ($(date))"
fbe8991 @rtomayko cleaner manifest writing in rpg-package-install
authored
134
135 # Extension Libraries
136 # -------------------
137
138 # Build extension libraries if they exist. Bail out if the build fails.
139 exts="$(rpg-build "$pack")" || {
140 warn "extension failed to build"
141 exit 1
142 }
143
144 # Install any extensions to `RPGLIB`. This is kind of tricky. We should
145 # be running `make` in the extension directory but I haven't had time to
146 # make it work right so just pull the prefix out of the `Makefile` and
147 # install the shared libs manually.
148 test -n "$exts" && {
149 mkdir -p "$RPGLIB"
150 echo "$exts" |
151 while read dl
152 do
153 prefix=$(sed -n 's/^target_prefix *= *//p' "$(dirname $dl)/Makefile")
154 dest="${RPGLIB}${prefix}/$(basename $dl)"
155 mkdir -p "${RPGLIB}${prefix}"
156 installfile "$dl" "$dest"
157 echo "$dest"
158 done
159 }
160
161 # Ruby Library Files
162 # ------------------
163
164 # Recursively install all library files into `RPGLIB`.
165 test -d "$pack/lib" && {
166 mkdir -p "$RPGLIB"
167 installdir "$pack/lib" "$RPGLIB"
168 }
169
170 # Ruby Executables
171 # ----------------
172
173 # Write executable scripts into `RPGBIN` and rewrite shebang lines.
174 test -d "$pack/bin" && {
175 mkdir -p "$RPGBIN"
176 for file in "$pack/bin"/*
177 do dest="$RPGBIN/$(basename $file)"
178 notice "$dest [!]"
179 sed "s@^#!.*ruby.*@#!$(ruby_command)@" <"$file" >"$dest"
180 chmod 0755 "$dest"
181 echo "$dest"
182 done
183 }
184
185 # Manpages
186 # --------
187
188 # Install any manpages included with the package into `RPGMAN`. Make
189 # sure files are being installed under the prescribed hierarchy.
190 test -d "$pack/man" && {
191 for file in "$pack/man"/*
192 do
193 if test -f "$file" &&
194 expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
195 then
196 section=${file##*\.}
197 dest="$RPGMAN/man$section/$(basename $file)"
198 mkdir -p "$RPGMAN/man$section"
199 installfile "$file" "$dest"
200 echo "$dest"
201 fi
202 done
203 }
204
205 } > "$manifest"
e59261f @rtomayko split package registration and installation into separate programs
authored
206
207 # Mark this package as active
208 unlink "$packagedir/installing"
209 ln -sf "$version" "$packagedir/active"
Something went wrong with that request. Please try again.