view scripts/install.sh @ 1087:b73a61542297 draft

I've finally gotten 'cpio' into a shape where it could be useable. This version can archive and extract directories, sockets, FIFOs, devices, symlinks, and regular files. Supported options are -iot, -H FMT (which is a dummy right now). It only writes newc, and could read newc or newcrc. This does NOT implement -d, which essentially is equivalent to mkdir -p $(dirname $FILE) for every file that needs it. Hard links are not supported, though it would be easy to add them given a hash table or something like that. I also have not implemented the "<n> blocks" output on stderr. If desired, I can add it pretty simply. There is one assumption this makes: that the mode of a file, as mode_t, is bitwise equivalent to the mode as defined for the cpio format. This is true of Linux, but is not mandated by POSIX. If it is compiled for a system where that is false, the archives will not be portable.
author Isaac Dunham <ibid.ag@gmail.com>
date Mon, 14 Oct 2013 11:15:22 -0500
parents 1c15ba60aa64
children
line wrap: on
line source

#!/bin/bash

# Grab default values for $CFLAGS and such.

source ./configure

# Parse command line arguments.

[ -z "$PREFIX" ] && PREFIX="."

LONG_PATH=""
while [ ! -z "$1" ]
do
  # Create symlinks instead of hardlinks?

  [ "$1" == "--symlink" ] && LINK_TYPE="-s"

  # Uninstall?

  [ "$1" == "--uninstall" ] && UNINSTALL=1

  # Delete destination command if it exists?

  [ "$1" == "--force" ] && DO_FORCE="-f"

  # Use {,usr}/{bin,sbin} paths instead of all files in one directory?

  if [ "$1" == "--long" ]
  then
    LONG_PATH="bin/"
  fi

  shift
done

echo "Compile instlist..."

$DEBUG $HOSTCC -I . scripts/install.c -o generated/instlist || exit 1
COMMANDS="$(generated/instlist $LONG_PATH)"

echo "Install commands..."

# Copy toybox itself

if [ -z "$UNINSTALL" ]
then
  mkdir -p ${PREFIX}/${LONG_PATH} || exit 1
  cp toybox ${PREFIX}/${LONG_PATH} || exit 1
else
  rm "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null
  rmdir "${PREFIX}/${LONG_PATH}" 2>/dev/null
fi
cd "${PREFIX}"

# Make links to toybox

for i in $COMMANDS
do
  # Figure out target of link

  if [ -z "$LONG_PATH" ]
  then
    DOTPATH=""
  else
    # Create subdirectory for command to go in (if necessary)

    DOTPATH="$(echo $i | sed 's@\(.*/\).*@\1@')"
    if [ -z "$UNINSTALL" ]
    then
      mkdir -p "$DOTPATH" || exit 1
    else
      rmdir "$DOTPATH" 2>/dev/null
    fi

    if [ -z "$LINK_TYPE" ]
    then
      dotpath="bin/"
    else
      if [ "$DOTPATH" != "$LONG_PATH" ]
      then
        DOTPATH="$(echo $DOTPATH | sed -e 's@[^/]*/@../@g')"$LONG_PATH
      else
        DOTPATH=""
      fi
    fi
  fi

  # Create link
  [ -z "$UNINSTALL" ] &&
    ln $DO_FORCE $LINK_TYPE ${DOTPATH}toybox $i ||
    rm $i 2>/dev/null
done