ipkg-build 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/bin/sh
  2. # ipkg-build -- construct a .ipk from a directory
  3. # Carl Worth <cworth@east.isi.edu>
  4. # based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001
  5. # 2003-04-25 rea@sr.unh.edu
  6. # Updated to work on Familiar Pre0.7rc1, with busybox tar.
  7. # Note it Requires: binutils-ar (since the busybox ar can't create)
  8. # For UID debugging it needs a better "find".
  9. set -e
  10. version=1.0
  11. FIND="$(which find)"
  12. FIND="${FIND:-$(which gfind)}"
  13. TAR="${TAR:-$(which tar)}"
  14. ipkg_extract_value() {
  15. sed -e "s/^[^:]*:[[:space:]]*//"
  16. }
  17. required_field() {
  18. field=$1
  19. grep "^$field:" < $CONTROL/control | ipkg_extract_value
  20. }
  21. pkg_appears_sane() {
  22. local pkg_dir=$1
  23. local owd=$PWD
  24. cd $pkg_dir
  25. PKG_ERROR=0
  26. pkg=`required_field Package`
  27. version=`required_field Version | sed 's/Version://; s/^.://g;'`
  28. arch=`required_field Architecture`
  29. if echo $pkg | grep '[^a-zA-Z0-9_.+-]'; then
  30. echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
  31. PKG_ERROR=1;
  32. fi
  33. if [ -f $CONTROL/conffiles ]; then
  34. rm -f $CONTROL/conffiles.resolved
  35. for cf in `$FIND $(sed -e "s!^/!$pkg_dir/!" $CONTROL/conffiles) -type f`; do
  36. echo "${cf#$pkg_dir}" >> $CONTROL/conffiles.resolved
  37. done
  38. rm $CONTROL/conffiles
  39. mv $CONTROL/conffiles.resolved $CONTROL/conffiles
  40. chmod 0644 $CONTROL/conffiles
  41. fi
  42. cd $owd
  43. return $PKG_ERROR
  44. }
  45. ###
  46. # ipkg-build "main"
  47. ###
  48. ogargs=""
  49. noclean=0
  50. usage="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
  51. while getopts "cg:ho:v" opt; do
  52. case $opt in
  53. o ) owner=$OPTARG
  54. ogargs="--owner=$owner"
  55. ;;
  56. g ) group=$OPTARG
  57. ogargs="$ogargs --group=$group"
  58. ;;
  59. c ) ;;
  60. C ) noclean=1;;
  61. v ) echo $version
  62. exit 0
  63. ;;
  64. h ) echo $usage >&2 ;;
  65. \? ) echo $usage >&2
  66. esac
  67. done
  68. shift $(($OPTIND - 1))
  69. # continue on to process additional arguments
  70. case $# in
  71. 1)
  72. dest_dir=$PWD
  73. ;;
  74. 2)
  75. dest_dir=$2
  76. if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
  77. dest_dir=$PWD
  78. fi
  79. ;;
  80. *)
  81. echo $usage >&2
  82. exit 1
  83. ;;
  84. esac
  85. pkg_dir=$1
  86. if [ ! -d $pkg_dir ]; then
  87. echo "*** Error: Directory $pkg_dir does not exist" >&2
  88. exit 1
  89. fi
  90. # CONTROL is second so that it takes precedence
  91. CONTROL=
  92. [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
  93. if [ -z "$CONTROL" ]; then
  94. echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
  95. exit 1
  96. fi
  97. if ! pkg_appears_sane $pkg_dir; then
  98. echo >&2
  99. echo "ipkg-build: Please fix the above errors and try again." >&2
  100. exit 1
  101. fi
  102. tmp_dir=$dest_dir/IPKG_BUILD.$$
  103. mkdir $tmp_dir
  104. echo $CONTROL > $tmp_dir/tarX
  105. # Preserve permissions (-p) when creating data.tar.gz as non-root user
  106. ( cd $pkg_dir && $TAR $ogargs -X $tmp_dir/tarX --format=gnu -czpf $tmp_dir/data.tar.gz . )
  107. installed_size=`stat -c "%s" $tmp_dir/data.tar.gz`
  108. sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
  109. $pkg_dir/$CONTROL/control
  110. ( cd $pkg_dir/$CONTROL && $TAR $ogargs --format=gnu -czf $tmp_dir/control.tar.gz . )
  111. rm $tmp_dir/tarX
  112. echo "2.0" > $tmp_dir/debian-binary
  113. pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk
  114. rm -f $pkg_file
  115. ( cd $tmp_dir && $TAR --format=gnu -zcf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
  116. rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
  117. rmdir $tmp_dir
  118. echo "Packaged contents of $pkg_dir into $pkg_file"