ipkg-make-index.sh 919 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. set -e
  3. pkg_dir=$1
  4. if [ -z $pkg_dir ] || [ ! -d $pkg_dir ]; then
  5. echo "Usage: ipkg-make-index <package_directory>" >&2
  6. exit 1
  7. fi
  8. which md5sum >/dev/null 2>&1 || alias md5sum=md5
  9. empty=1
  10. for pkg in `find $pkg_dir -name '*.ipk' | sort`; do
  11. empty=
  12. name="${pkg##*/}"
  13. name="${name%%_*}"
  14. [[ "$name" = "kernel" ]] && continue
  15. [[ "$name" = "libc" ]] && continue
  16. echo "Generating index for package $pkg" >&2
  17. file_size=$(ls -l $pkg | awk '{print $5}')
  18. md5sum=$(md5sum $pkg | awk '{print $1}')
  19. sha256sum=$(openssl dgst -sha256 $pkg | awk '{print $2}')
  20. # Take pains to make variable value sed-safe
  21. sed_safe_pkg=`echo $pkg | sed -e 's/^\.\///g' -e 's/\\//\\\\\\//g'`
  22. tar -xzOf $pkg ./control.tar.gz | tar xzOf - ./control | sed -e "s/^Description:/Filename: $sed_safe_pkg\\
  23. Size: $file_size\\
  24. MD5Sum: $md5sum\\
  25. SHA256sum: $sha256sum\\
  26. Description:/"
  27. echo ""
  28. done
  29. [ -n "$empty" ] && echo
  30. exit 0