#!/bin/sh ############################################################## # Copyright (C) 2002 Stewart Allen # # Licensed under the terms of the GNU Public License V2 # # # # dir-to-rpm: converts a directory structure into an # # installable RPM image. basically, it's a glorified tar. # # the real utility in this is the ability to create images # # that are easy to install/uninstall without all the hassles # # of creating a formal source RPM. # # # # to endow your RPM with personalized settings, put them in # # the ${HOME}/.rpmmacros configuration file (like this): # # # # %packager Me Myself and I # # %distribution My Linux Distro # # %vendor TarPM Universal Widgets # ############################################################## CALL=$(basename ${0}) function usage { echo "usage: ${CALL} [OPTION]... [rpmbuild args]" if [ "$1" != "long" ]; then echo "try '${CALL} --help' for more options" exit 1 fi echo "" echo " base name of rpm" echo " base directory for files" echo " -h --help this help message" echo " -V --version=# rpm version # (default 1)" echo " -R --release=# rpm release # (default 1)" echo " -d --desc=STR a brief description" echo " -r --root= root of files inside 'dir'" echo " -o --out output directory or file" echo " [rpmbuild args] optional list of rpmbuild arguments" echo "" echo "report bugs to stewart@neuron.com" exit 1 } function error { echo "error: $@" exit 1 } version=1 release=1 out=$(pwd) root=/ for i in "$@"; do case "$i" in --version=*) version=${i/--version=/}; shift ;; --release=*) release=${i/--release=/}; shift ;; --desc=*) desc=${i/--desc=/}; shift ;; --root=*) root=${i/--root=/}; shift ;; --out=*) out=${i/--out=/}; shift ;; -V) shift; version=${1}; shift ;; -R) shift; release=${1}; shift ;; -d) shift; desc=${1}; shift ;; -r) shift; root=${1}; shift ;; -o) shift; out=${1}; shift ;; --help|-h) usage long ;; esac done name=$1 dir=$2 shift shift test "${dir}" = "" && usage test "${name}" = "" && usage test "${dir/\/*/XXX}" = "XXX" || error "directory path must be absolute" test -d "${dir}" || error "'${dir}' missing or not a directory" tmpdir=$(mktemp -d /tmp/dir2rpmXXXXXX) rpmtop=${tmpdir}/rpms outdir=${tmpdir}/rpm.dir specfl=${tmpdir}/rpm.spec macrfl=${tmpdir}/rpm.macros rpmlog=${tmpdir}/rpm.log mkdir -p ${rpmtop} cat > ${specfl} << EOF Summary: ${desc:-${name}-${version}-${release}} Name: ${name} Version: ${version} Release: ${release} Copyright: Unknown Group: TarPMs BuildRoot: ${dir} AutoReqProv: no Prefix: ${root} %undefine __check_files %define _topdir ${rpmtop} %define _rpmdir ${tmpdir} %define _builddir ${tmpdir} %prep echo "%_target_cpu" > ${outdir} %description ${desc} %files %defattr(-,root,root) ${root} EOF rpmbuild -bb ${specfl} $@ &> ${rpmlog} && mv ${tmpdir}/$(cat ${outdir})/*.rpm ${out} && rm -rf ${tmpdir} || ( find ${tmpdir} && error "Build Error" )