Code, mostly.

Archives:

[ Home | RSS 2.0 | ATOM 1.0 | Comment ]

Fri, 07 Aug 2009

``zipas`` - ensure .zip file contains an outer wrapper folder

A trivial bash script to create a .zip file where everything's in a top-level folder. Saves creating a folder temporarily, and copying / linking things into it:

#!/bin/sh

if [ @# -lt 2 ]; then cat <<EOF
usage: $0 <wrapper-folder> <target files>

e.g. zipas jul0907 *.c
EOF
else

  PATHNAME="$1"
  HEADNAME=${PATHNAME%%/*}  # i.e 'foo' from 'foo/bar/inner'

  if [ -a "$HEADNAME" ]; then
    echo "ERROR: '$HEADNAME' exists"
  else
    shift
    mkdir -p $PATHNAME
    for i in $@; do
      ln -s "$PWD/$i" "$PATHNAME/$i"
    done
    zip -r $HEADNAME.zip $HEADNAME
    rm -rf "$HEADNAME"
  fi
fi

posted at: 15:01 | path: /code/bash | permanent link to this entry

Made with PyBlosxom