Skip to content
Browse files

cleaner manifest writing in rpg-package-install

  • Loading branch information...
1 parent e4d0de3 commit fbe899145d6f1ceb77b7c35ca1bc6092092edc00 @rtomayko committed
Showing with 90 additions and 93 deletions.
  1. +90 −93 rpg-package-install.sh
View
183 rpg-package-install.sh
@@ -31,10 +31,11 @@ test "$1" = '-f' && {
# Utility Functions
# -----------------
-# Usage: rpg_ln <source> <dest>
-# Attempt to hard link <dest> to <source> but fall back to cp(1) if
-# you're crossing file systems or the ln fails otherwise.
-rpg_ln () {
+# Usage: `installfile <source> <dest>`
+#
+# Attempt to hard link `<dest>` to `<source>` but fall back to `cp(1)` if
+# you're crossing file systems or `ln` fails otherwise.
+installfile () {
if ln -f "$1" "$2" 2>/dev/null
then notice "$2 [ln]"
else notice "$2 [cp]"
@@ -42,22 +43,22 @@ rpg_ln () {
fi
}
-# Usage: rpg_install_dir `<source>` `<dest>` `<manifest>`
+# Usage: `installdir <source> <dest>`
#
# Recursive file hierarchy copy routine. Attempts to hardlink files
# and falls back to normal copies.
-rpg_install_dir () {
+installdir () {
mkdir -p "$2"
for file in "$1"/*
do
if test -f "$file"
then # link dest to source
- rpg_ln "$file" "$2/$(basename $file)"
- echo "$2/$(basename $file)" >> "$3"
+ installfile "$file" "$2/$(basename $file)"
+ echo "$2/$(basename $file)"
elif test -d "$file"
then # recurse into directories
- rpg_install_dir "$file" "$2/$(basename $file)" "$3"
+ installdir "$file" "$2/$(basename $file)"
else warn "unknown file type: $file"
return 1
@@ -72,9 +73,8 @@ rpg_install_dir () {
# Establish our directories in the package database. These should
# have already been created by `rpg-package-register`. If not, bail
# out now since something isn't right.
-package="$1";shift
-version="$1";shift
-test "$version" = '=' && { version="$1";shift; }
+package="$1" version="$2"; shift 2
+test "$version" = '=' && { version="$1"; shift; }
packagedir="$RPGDB/$package"
test -d "$packagedir/$version" || {
@@ -123,91 +123,88 @@ pack="$RPGPACKS/$package-$version"
# so we know how to uninstall the package. Create/truncate it in case
# it already exists.
#
-# TODO if the manifest already exists that means the package was
-# previously installed or may currently be installed. Do something with
-# that information.
-manifest="$packagedir/$version/manifest"
-echo "# $(date)" > "$manifest"
-
# Symlink the `installing` file to the version directory. This will let us
# detect in progress or failed installations.
ln -sf "$version" "$packagedir/installing"
-
-
-# Extension Libraries
-# -------------------
-
-# Build extension libraries if they exist. Bail out if the build fails.
-exts="$(rpg-build "$pack")" || {
- warn "extension failed to build"
- exit 1
-}
-
-# Install any extensions to `RPGLIB`. This is kind of tricky. We should
-# be running `make` in the extension directory but I haven't had time to
-# make it work right so just pull the prefix out of the `Makefile` and
-# install the shared libs manually.
-test -n "$exts" && {
- mkdir -p "$RPGLIB"
- echo "$exts" |
- while read dl
- do
- prefix=$(
- grep '^target_prefix.=' "$(dirname $dl)/Makefile" |
- sed 's/^target_prefix *= *//'
- )
- dest="${RPGLIB}${prefix}/$(basename $dl)"
- mkdir -p "${RPGLIB}${prefix}"
- rpg_ln "$dl" "$dest"
- echo "$dest" >> "$manifest"
- done
-}
-
-# Ruby Library Files
-# ------------------
-
-# Recursively install all library files into `RPGLIB`.
-test -d "$pack"/lib && {
- mkdir -p "$RPGLIB"
- rpg_install_dir "$pack/lib" "$RPGLIB" "$manifest"
-}
-
-# Ruby Executables
-# ----------------
-
-# Write executable scripts into `RPGBIN` and rewrite shebang lines.
-test -d "$pack"/bin && {
- mkdir -p "$RPGBIN"
- for file in "$pack"/bin/*
- do dest="$RPGBIN/$(basename $file)"
- notice "$dest [!]"
- sed "s@^#!.*ruby.*@#!$(ruby_command)@" \
- < "$file" \
- > "$dest"
- chmod 0755 "$dest"
- echo "$dest" >> "$manifest"
- done
-}
-
-# Manpages
-# --------
-
-# Install any manpages included with the package into `RPGMAN`. Make
-# sure files are being installed under the prescribed hierarchy.
-test -d "$pack"/man && {
- for file in "$pack"/man/*
- do if test -f "$file" &&
- expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
- then
- section=${file##*\.}
- dest="$RPGMAN/man$section/$(basename $file)"
- mkdir -p "$RPGMAN/man$section"
- rpg_ln "$file" "$dest"
- echo "$dest" >> "$manifest"
- fi
- done
-}
+# Anything written to standard output within the main install block is
+# written to the install manifest. The manifest should include full paths to
+# all files installed
+manifest="$packagedir/$version/manifest"
+{
+ echo "# $(date)"
+
+ # Extension Libraries
+ # -------------------
+
+ # Build extension libraries if they exist. Bail out if the build fails.
+ exts="$(rpg-build "$pack")" || {
+ warn "extension failed to build"
+ exit 1
+ }
+
+ # Install any extensions to `RPGLIB`. This is kind of tricky. We should
+ # be running `make` in the extension directory but I haven't had time to
+ # make it work right so just pull the prefix out of the `Makefile` and
+ # install the shared libs manually.
+ test -n "$exts" && {
+ mkdir -p "$RPGLIB"
+ echo "$exts" |
+ while read dl
+ do
+ prefix=$(sed -n 's/^target_prefix *= *//p' "$(dirname $dl)/Makefile")
+ dest="${RPGLIB}${prefix}/$(basename $dl)"
+ mkdir -p "${RPGLIB}${prefix}"
+ installfile "$dl" "$dest"
+ echo "$dest"
+ done
+ }
+
+ # Ruby Library Files
+ # ------------------
+
+ # Recursively install all library files into `RPGLIB`.
+ test -d "$pack/lib" && {
+ mkdir -p "$RPGLIB"
+ installdir "$pack/lib" "$RPGLIB"
+ }
+
+ # Ruby Executables
+ # ----------------
+
+ # Write executable scripts into `RPGBIN` and rewrite shebang lines.
+ test -d "$pack/bin" && {
+ mkdir -p "$RPGBIN"
+ for file in "$pack/bin"/*
+ do dest="$RPGBIN/$(basename $file)"
+ notice "$dest [!]"
+ sed "s@^#!.*ruby.*@#!$(ruby_command)@" <"$file" >"$dest"
+ chmod 0755 "$dest"
+ echo "$dest"
+ done
+ }
+
+ # Manpages
+ # --------
+
+ # Install any manpages included with the package into `RPGMAN`. Make
+ # sure files are being installed under the prescribed hierarchy.
+ test -d "$pack/man" && {
+ for file in "$pack/man"/*
+ do
+ if test -f "$file" &&
+ expr "$file" : '.*\.[0-9][0-9A-Za-z]*$' >/dev/null
+ then
+ section=${file##*\.}
+ dest="$RPGMAN/man$section/$(basename $file)"
+ mkdir -p "$RPGMAN/man$section"
+ installfile "$file" "$dest"
+ echo "$dest"
+ fi
+ done
+ }
+
+} > "$manifest"
# Mark this package as active
unlink "$packagedir/installing"

0 comments on commit fbe8991

Please sign in to comment.
Something went wrong with that request. Please try again.