Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 215 lines (184 sloc) 6.33 kb
e59261f6 »
2010-03-14 split package registration and installation into separate programs
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
34 # Usage: rpg_ln <source> <dest>
35 # Attempt to hard link <dest> to <source> but fall back to cp(1) if
36 # you're crossing file systems or the ln fails otherwise.
37 rpg_ln () {
56f3312f »
2010-03-14 create extension lib directories before copying
38 if ln -f "$1" "$2" 2>/dev/null
e59261f6 »
2010-03-14 split package registration and installation into separate programs
39 then notice "$2 [ln]"
40 else notice "$2 [cp]"
41 cp "$1" "$2"
42 fi
43 }
44
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
45 # Usage: rpg_install_dir `<source>` `<dest>` `<manifest>`
46 #
e59261f6 »
2010-03-14 split package registration and installation into separate programs
47 # Recursive file hierarchy copy routine. Attempts to hardlink files
48 # and falls back to normal copies.
49 rpg_install_dir () {
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
50 mkdir -p "$2"
e59261f6 »
2010-03-14 split package registration and installation into separate programs
51 for file in "$1"/*
52 do
53 if test -f "$file"
54 then # link dest to source
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
55 rpg_ln "$file" "$2/$(basename $file)"
56 echo "$2/$(basename $file)" >> "$3"
e59261f6 »
2010-03-14 split package registration and installation into separate programs
57
58 elif test -d "$file"
59 then # recurse into directories
489d6e55 »
2010-03-16 oops. that var doesn't exist anymore
60 rpg_install_dir "$file" "$2/$(basename $file)" "$3"
e59261f6 »
2010-03-14 split package registration and installation into separate programs
61
62 else warn "unknown file type: $file"
63 return 1
64 fi
65 done
66 return 0
67 }
68
69 # Package Database Prep
70 # ---------------------
71
72 # Establish our directories in the package database. These should
73 # have already been created by `rpg-package-register`. If not, bail
74 # out now since something isn't right.
c41c7582 »
2010-03-14 two phase rpg-install fetches / dep solves before installing
75 package="$1";shift
76 version="$1";shift
333e5a24 »
2010-03-16 speed up dep solving by checking solved file first
77 test "$version" = '=' && { version="$1";shift; }
e59261f6 »
2010-03-14 split package registration and installation into separate programs
78 packagedir="$RPGDB/$package"
79
80 test -d "$packagedir/$version" || {
81 warn "package not registered: $package/$version"
82 exit 1
83 }
84
85 notice "$package $version"
86
87 # Fetch the gem into the cache and unpack into the packs area if
88 # its not already there.
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
89 if ! $force && test -d "$RPGPACKS/$package-$version"
f5f71407 »
2010-03-17 rpg-install -s actually resumes the session
90 then notice "$package $version sources exist. bypassing fetch / unpack."
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
91 else rm -rf "$RPGPACKS/$package-$version"
92 gemfile=$(rpg-fetch "$package" "$version")
e59261f6 »
2010-03-14 split package registration and installation into separate programs
93 notice "unpacking $gemfile into $RPGPACKS"
94 mkdir -p "$RPGPACKS"
0783e800 »
2010-03-14 rpg-unpack for extracting gems and gemspecs
95 rpg-unpack -p "$RPGPACKS" "$gemfile"
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
96 rpg-shit-list "$package" "$version" "$RPGPACKS/$package-$version"
e59261f6 »
2010-03-14 split package registration and installation into separate programs
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
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
119 # Path to the unpacked package directory.
120 pack="$RPGPACKS/$package-$version"
121
e59261f6 »
2010-03-14 split package registration and installation into separate programs
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 # TODO if the manifest already exists that means the package was
127 # previously installed or may currently be installed. Do something with
128 # that information.
129 manifest="$packagedir/$version/manifest"
130 echo "# $(date)" > "$manifest"
131
132 # Symlink the `installing` file to the version directory. This will let us
133 # detect in progress or failed installations.
134 ln -sf "$version" "$packagedir/installing"
135
136
137
138 # Extension Libraries
139 # -------------------
140
141 # Build extension libraries if they exist. Bail out if the build fails.
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
142 exts="$(rpg-build "$pack")" || {
e59261f6 »
2010-03-14 split package registration and installation into separate programs
143 warn "extension failed to build"
144 exit 1
145 }
146
147 # Install any extensions to `RPGLIB`. This is kind of tricky. We should
148 # be running `make` in the extension directory but I haven't had time to
149 # make it work right so just pull the prefix out of the `Makefile` and
150 # install the shared libs manually.
151 test -n "$exts" && {
152 mkdir -p "$RPGLIB"
153 echo "$exts" |
154 while read dl
155 do
156 prefix=$(
95486602 »
2010-03-16 fix extension install
157 grep '^target_prefix.=' "$(dirname $dl)/Makefile" |
e59261f6 »
2010-03-14 split package registration and installation into separate programs
158 sed 's/^target_prefix *= *//'
159 )
160 dest="${RPGLIB}${prefix}/$(basename $dl)"
56f3312f »
2010-03-14 create extension lib directories before copying
161 mkdir -p "${RPGLIB}${prefix}"
95486602 »
2010-03-16 fix extension install
162 rpg_ln "$dl" "$dest"
e59261f6 »
2010-03-14 split package registration and installation into separate programs
163 echo "$dest" >> "$manifest"
164 done
165 }
166
167 # Ruby Library Files
168 # ------------------
169
170 # Recursively install all library files into `RPGLIB`.
1066621a »
2010-03-16 rpg-package-install actually installs stuff
171 test -d "$pack"/lib && {
e59261f6 »
2010-03-14 split package registration and installation into separate programs
172 mkdir -p "$RPGLIB"
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
173 rpg_install_dir "$pack/lib" "$RPGLIB" "$manifest"
e59261f6 »
2010-03-14 split package registration and installation into separate programs
174 }
175
176 # Ruby Executables
177 # ----------------
178
179 # Write executable scripts into `RPGBIN` and rewrite shebang lines.
1066621a »
2010-03-16 rpg-package-install actually installs stuff
180 test -d "$pack"/bin && {
e59261f6 »
2010-03-14 split package registration and installation into separate programs
181 mkdir -p "$RPGBIN"
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
182 for file in "$pack"/bin/*
e59261f6 »
2010-03-14 split package registration and installation into separate programs
183 do dest="$RPGBIN/$(basename $file)"
184 notice "$dest [!]"
185 sed "s@^#!.*ruby.*@#!$(ruby_command)@" \
186 < "$file" \
187 > "$dest"
188 chmod 0755 "$dest"
189 echo "$dest" >> "$manifest"
190 done
191 }
192
193 # Manpages
194 # --------
195
196 # Install any manpages included with the package into `RPGMAN`. Make
197 # sure files are being installed under the prescribed hierarchy.
1066621a »
2010-03-16 rpg-package-install actually installs stuff
198 test -d "$pack"/man && {
bbf59372 »
2010-03-16 rpg-shit-list fixes up non-compatible packages
199 for file in "$pack"/man/*
200 do if test -f "$file" &&
201 expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
e59261f6 »
2010-03-14 split package registration and installation into separate programs
202 then
203 section=${file##*\.}
204 dest="$RPGMAN/man$section/$(basename $file)"
205 mkdir -p "$RPGMAN/man$section"
206 rpg_ln "$file" "$dest"
207 echo "$dest" >> "$manifest"
208 fi
209 done
210 }
211
212 # Mark this package as active
213 unlink "$packagedir/installing"
214 ln -sf "$version" "$packagedir/active"
Something went wrong with that request. Please try again.