#!/bin/bash # # builds packages from given dir # # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/pkgbuild_dir.sh,v 1.15 2007-03-19 19:24:46 niro Exp $ # set default user mage.rc : ${MAGERC="/etc/mage.rc"} PKGSUFFIX="mpk" PKGNAME="$1" SEARCHDIRS="$2" MLIBDIR=/usr/lib/mage ## only for tests -> normally in /etc/rc.d/init.d/functions COLRED="\033[1;6m\033[31m" COLGREEN="\033[1;6m\033[32m" COLYELLOW="\033[1;6m\033[33m" COLBLUE="\033[1;6m\033[34m" COLMAGENTA="\033[1;6m\033[35m" COLWHITE="\033[1;6m\033[37m" COLGRAY="\033[0;6m\033[37m" COLBOLD="\033[1m" COLDEFAULT="\033[0m" if [[ ${NOCOLORS} = true ]] then COLRED="" COLGREEN="" COLYELLOW="" COLBLUE="" COLMAGENTA="" COLWHITE="" COLGRAY="" COLBOLD="" COLDEFAULT="" fi # export default C locale export LC_ALL=C [[ -z $1 ]] && echo "No package name given. Aborting." && exit 1 [[ -z $2 ]] && echo "No source dir given. Aborting." && exit 1 source /etc/mage.rc.global [[ -f ${MAGERC} ]] && source ${MAGERC} source ${MLIBDIR}/mage4.functions.sh # set PKGDIR and BUILDDIR and BINDIR to MROOT if [[ -n ${MROOT} ]] then export PKGDIR=${MROOT}/${PKGDIR} export BUILDDIR=${MROOT}/${BUILDDIR} export BINDIR=${MROOT}/${BINDIR} fi build_preinstall() { if [ -d ${BUILDDIR}/${PKGNAME} ] then rm -rf ${BUILDDIR}/${PKGNAME} fi install -d ${BUILDDIR}/${PKGNAME}/binfiles touch ${BUILDDIR}/${PKGNAME}/.dirs touch ${BUILDDIR}/${PKGNAME}/.symlinks touch ${BUILDDIR}/${PKGNAME}/.files touch ${BUILDDIR}/${PKGNAME}/.pipes touch ${BUILDDIR}/${PKGNAME}/.char touch ${BUILDDIR}/${PKGNAME}/.fifo } build_postinstall() { local m_mtime local m_md5sum local filelist local item local check_srcdir local filetype local fileposix local fileowner local filegroup local lnkdest local filedir local char_major local char_minor echo -e "${COLBLUE}===${COLGREEN} fetching files for package '${PKGNAME}' ...${COLDEFAULT}" # md5sums will only be generated for files: $m_md5sum # sets mtime to same value of the $BINDIR: $m_mtime # only needed for files and symlinks m_mtime=$(stat -c %Y ${BINDIR}) # install mtime to package (needed for later checks) echo "${m_mtime}" > ${BUILDDIR}/${PKGNAME}/.mtime # !! we use § as field seperator !! # doing so prevent us to get errors by filenames with spaces filelist=$(find ${SEARCHDIRS} -printf %p§) # sets fieldseperator to "§" instead of " " IFS=§ for item in ${filelist} do check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})" if [[ -z ${check_srcdir} ]] then filetype="$(stat -c %F ${item})" fileposix="$(stat -c %a ${item})" fileowner="$(stat -c %U ${item})" filegroup="$(stat -c %G ${item})" [[ ${fileowner} = UNKNOWN ]] && fileowner="root" [[ ${filegroup} = UNKNOWN ]] && filegroup="root" case "${filetype}" in "directory") if [[ ${item} != ${SEARCHDIRS} ]] then echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs fi ;; "symbolic link") lnkdest="$(readlink ${item})" echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks ;; "regular empty file") filedir="$(dirname ${item})" filedir="${filedir#${SEARCHDIRS}*}" m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_mtime}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} ;; "regular file" ) filedir="$(dirname ${item})" filedir="${filedir#${SEARCHDIRS}*}" m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_time}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} ;; "block special file") # convert hex2dec # printf '%d' 0x12 -> 18 char_major="$(printf 0x$(stat -c %t ${item}))" char_minor="$(printf 0x$(stat -c %T ${item}))" echo "${item#${SEARCHDIRS}*}§${fileposix}§${char_major}§${char_minor}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.pipes ;; "character special file") # convert hex2dec # printf '%d' 0x12 -> 18 char_major="$(printf 0x$(stat -c %t ${item}))" char_minor="$(printf 0x$(stat -c %T ${item}))" echo "${item#${SEARCHDIRS}*}§${fileposix}§${char_major}§${char_minor}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.char ;; "fifo") echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.fifo ;; *) echo "What I am ? -- $I" echo "$0 paused ... Press Enter" read ;; esac fi done # very important: unsetting the '§' fieldseperator unset IFS # forcing mtime to same value echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}" find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' } build_rmtimestamp() { rm /var/tmp/timestamp } build_package() { echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}" cd ${BUILDDIR} tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} install -d ${PKGDIR} mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} } build_preinstall build_postinstall build_package