1#!/bin/sh 2# @(#) utility to create ipkg package for a udpxy distro 3 4# extract architecture tag from file 5getarch() 6{ 7 fname=${1:?} 8 9 tag=`file -b $fname | cut -d',' -f2 | tr -d ' '` || return 1 10 case "$tag" in 11 Intel80386) arch=i686 ;; 12 MIPS*) arch=mipsel ;; 13 *) arch=$tag ;; 14 esac 15 16 echo $arch 17 return 0 18} 19 20#### 21# main 22# 23 24if [ $# -lt 1 ]; then 25 echo >&2 Usage: $0 udpxy_source_dir package_dest_dir 26 exit $? 27fi 28 29udpxy_root=${1:?} 30destdir=${2:-.} 31 32if [ ! -d "$udpxy_root" -o ! -d "$destdir" ]; then 33 echo >&2 "Cannot find [$udpxy_root] or [$destdir] directory" 34 exit 1 35fi 36 37binfiles="$udpxy_root/udpxy $udpxy_root/udpxrec" 38 39files="$binfiles $udpxy_root/BUILD $udpxy_root/VERSION" 40for f in `echo $files`; do 41 if [ ! -f "$f" ]; then 42 echo >&2 "$0: Cannot find [$f] executable" 43 exit 1 44 fi 45done 46 47if ! type ipkg-build >/dev/null 2>&1; then 48 echo >&2 "$0: ipkg-build tool is not accessible" 49 exit 1 50else 51 build=`which ipkg-build` || exit 1 52fi 53 54ARCH=`getarch $udpxy_root/udpxy 2>/dev/null` || return $? 55[ -n "$MKIPK_DEBUG" ] && echo "Architecture: [${ARCH}]" 56 57#case $EUID in 58# 0) SUDO= ;; 59# *) SUDO=sudo ;; 60#esac 61SUDO= 62: ${MKIPK_USE_TAR:='1'} 63 64 65rc=1; while : 66do 67 ipkg_dir=${TMPDIR:-/tmp}/ipkg.$$ 68 69 ${SUDO} mkdir -p $ipkg_dir/opt/bin $ipkg_dir/CONTROL || break 70 71 UDPXY_NAME="udpxy" 72 VERSION=`cat $udpxy_root/VERSION | tr -d '"'`-`cat $udpxy_root/BUILD` 73 control_spec=$ipkg_dir/CONTROL/control 74 75 [ -n "$MKIPK_DEBUG" ] && echo >&2 "Creating [$control_spec]" 76 ${SUDO} touch $control_spec || break 77 ${SUDO} chmod o+w $control_spec || break 78 79 cat <<__EOM_ >$control_spec 80Package: $UDPXY_NAME 81Architecture: ${ARCH} 82Priority: optional 83Section: base 84Version: ${VERSION} 85Maintainer: Pavel Cherenkov<pcherenkov@gmail.com> 86Source: http://downloads.sourceforge.net/udpxy/udpxy.${VERSION}.tgz 87Description: UDP-to-HTTP multicast traffic relay daemon 88Depends: 89Suggests: 90Conflicts: 91__EOM_ 92 [ $? -eq 0 ] || break 93 94 ${SUDO} cp -P $binfiles $ipkg_dir/opt/bin || break 95 if [ -n "${STRIP}" ]; then 96 [ -n "${MKIPK_DEBUG}" ] && echo >&2 "Stripping udpxy executable" 97 ${SUDO} ${STRIP} $ipkg_dir/opt/bin/udpxy || break 98 [ -n "${MKIPK_DEBUG}" ] && ls -lh $ipkg_dir/opt/bin/udpxy 99 fi 100 101 buildopt="-o root -g root" 102 [ -n "${MKIPK_USE_TAR}" -a "0" != "${MKIPK_USE_TAR}" ] && \ 103 buildopt="$buildopt -c" 104 ${SUDO} ${build} $buildopt $ipkg_dir $destdir || break 105 106 rc=0; break 107done 108 109if [ -z "$MKIPK_DEBUG" ]; then 110 ${SUDO} rm -fr $ipkg_dir 111else 112 echo >&2 "Leaving behind [$ipkg_dir]" 113fi 114 115[ -n "${MKIPK_DEBUG}" ] && echo "$0: exiting with rc=$rc" 116exit $rc 117 118# __EOF__ 119 120