NoPaste

ipk-build script

von KBDCALLS

SNIPPET_TEXT:
  1. #!/bin/sh
  2.  
  3. # ipkg-build -- construct a .ipk from a directory
  4. # Carl Worth <cworth@east.isi.edu>
  5. # based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001
  6. set -e
  7.  
  8. ipkg_extract_value() {
  9.         sed -e "s/^[^:]*:[[:space:]]*//"
  10. }
  11.  
  12. required_field() {
  13.         field=$1
  14.  
  15.         value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
  16.         if [ -z "$value" ]; then
  17.                 echo "ipkg-build: Error: $CONTROL/control is missing field $field" ;
  18.                 PKG_ERROR=1
  19.         fi
  20.         echo $value
  21. }
  22.  
  23. pkg_appears_sane() {
  24.         local pkg_dir=$1
  25.  
  26.         local owd=`pwd`
  27.         cd $pkg_dir
  28.  
  29.         PKG_ERROR=0
  30.         if [ ! -f "$CONTROL/control" ]; then
  31.                 echo "ipkg-build: Error: Control file $pkg_dir/$CONTROL/control not found."
  32.                 cd $owd
  33.                 return 1
  34.         fi
  35.  
  36.         pkg=`required_field Package`
  37.         version=`required_field Version | sed 's/.*://;'`
  38.         arch=`required_field Architecture`
  39.         required_field Maintainer >/dev/null
  40.         required_field Description >/dev/null
  41.  
  42.         if echo $pkg | grep '[^a-z0-9.+-]'; then
  43.                 echo "ipkg-build: Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])"
  44.                 PKG_ERROR=1;
  45.         fi
  46.  
  47.         local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
  48.         if [ -n "$bad_fields" ]; then
  49.                 bad_fields=`echo $bad_fields`
  50.                 echo "ipkg-build: Error: The following fields in $CONTROL/control are missing a ':'"
  51.                 echo "  $bad_fields"
  52.                 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value"
  53.                 PKG_ERROR=1
  54.         fi
  55.  
  56.         for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
  57.                 if [ -f $script -a ! -x $script ]; then
  58.                         echo "ipkg-build: Error: package script $script is not executable"
  59.                         PKG_ERROR=1
  60.                 fi
  61.         done
  62.  
  63.         if [ -f $CONTROL/conffiles ]; then
  64.                 for cf in `cat $CONTROL/conffiles`; do
  65.                         if [ ! -f ./$cf ]; then
  66.                                 echo "ipkg-build: Error: $CONTROL/conffiles mentions conffile $cf which does not exist"
  67.                                 PKG_ERROR=1
  68.                         fi
  69.                 done
  70.         fi
  71.  
  72.         cd $owd
  73.         return $PKG_ERROR
  74. }
  75.  
  76. ###
  77. # ipkg-build "main"
  78. ###
  79.  
  80. case $# in
  81. 1)
  82.         dest_dir=.
  83.         ;;
  84. 2)
  85.         dest_dir=$2
  86.         ;;
  87. *)
  88.         echo "Usage: ipkg-build <pkg_directory> [<destination_directory>]" ;
  89.         exit 1
  90.         ;;
  91. esac
  92.  
  93. pkg_dir=$1
  94.  
  95. if [ ! -d $pkg_dir ]; then
  96.         echo "ipkg-build: Error: Directory $pkg_dir does not exist"
  97.         exit 1
  98. fi
  99.  
  100. # CONTROL is second so that it takes precedence
  101. CONTROL=
  102. [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN
  103. [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
  104. if [ -z "$CONTROL" ]; then
  105.         echo "ipkg-build: Error: Directory $pkg_dir has no CONTROL subdirectory."
  106.         exit 1
  107. fi
  108.  
  109. if ! pkg_appears_sane $pkg_dir; then
  110.         echo "Please fix the above errors and try again."
  111.         exit 1
  112. fi
  113.  
  114. tmp_dir=$dest_dir/IPKG_BUILD.$$
  115. mkdir $tmp_dir
  116.  
  117. #tar -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$pkg_dir/CONTROL
  118. #
  119. # gutemine's fix for --exclude bug
  120. #
  121. FILESWITHOUTCONTROL=`cd $pkg_dir; ls -1 | grep -v CONTROL`
  122. #echo $FILESWITHOUTCONTROL
  123.  
  124. tar -C $pkg_dir -czf $tmp_dir/data.tar.gz $FILESWITHOUTCONTROL
  125. tar -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz .
  126.  
  127. echo "2.0" > $tmp_dir/debian-binary
  128.  
  129. pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk
  130. if [ -f /usr/bin/enigma2 ]; then
  131.    if [ ! -f /usr/local/bin/ar ]; then
  132.       BUSYBOX=`ls -F /usr/bin/ar | grep @ | wc -l`
  133.       if [ $BUSYBOX -eq 1 ]; then
  134.          echo ar seems to be from busybox - not capable to create archive
  135.          echo Install ar from binutils at /usr/local/bin
  136.          echo or replace link from /usr/bin/ar to busybox with real ar binary
  137.          exit 0
  138.       fi
  139.    fi
  140. fi
  141. cd $tmp_dir
  142. ar -r $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz
  143. mv $pkg_file ..
  144. cd ..
  145. rm -r -f $tmp_dir
  146.  
  147. echo "Packaged content was moved at $pkg_dir into $pkg_file"

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN