package-add 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. root="$(readlink -f $(dirname $BASH_SOURCE)/..)";
  3. if [[ "$1" != "" ]];then
  4. btype="";
  5. script="";
  6. if [[ "$2" != "" ]];then
  7. mkdir -p $root/src/$1;
  8. ln -s `readlink -f $2` $root/src/$1/source;
  9. echo "Linked source in $2";
  10. else
  11. mkdir -p $root/src/$1/source;
  12. fi;
  13. echo -e "Type:\n (1) script\n (2) git\n (3) svn";
  14. while [[ ! $btype =~ ^1|2|3$ ]]; do
  15. read btype;
  16. done;
  17. case $btype in
  18. 2)
  19. btype="git";
  20. ;;
  21. 3)
  22. btype="svn";
  23. ;;
  24. *)
  25. btype="script";
  26. read -p "Script path: " script;
  27. ;;
  28. esac;
  29. if [[ ! -f $root/src/$1/PKGBUILD ]];then
  30. cp $root/etc/PKGBUILD.in $root/src/$1/PKGBUILD;
  31. case $btype in
  32. git)
  33. echo -e "pkgver=0.0.0\npkgver() {\n\tcd \"\${srcdir%/*}/source\"\n\tif git describe --tags > /dev/null 2>&1;then\n\t\tgit describe --tags --long | sed -E 's/([^-]*-g)/r\1/;s/-/./g';\n\telse\n\t\tdate +%Y%m%d;\n\tfi;}"|cat - $root/src/$1/PKGBUILD > /tmp/out && mv /tmp/out $root/src/$1/PKGBUILD;
  34. ;;
  35. svn)
  36. echo -e "pkgver=0.0.0\npkgver() {\n\tcd \"\${srcdir%/*}/source\"\n\tlocal ver=\"\$(svnversion)\"\n\tprintf \"r%s\" \"\${ver//[[:alpha:]]}\"\n}"|cat - $root/src/$1/PKGBUILD > /tmp/out && mv /tmp/out $root/src/$1/PKGBUILD;
  37. ;;
  38. script)
  39. echo -e "pkgver=0.0.0\npkgver() {\n date +%Y%m%d\n}"|cat - $root/src/$1/PKGBUILD > /tmp/out && mv /tmp/out $root/src/$1/PKGBUILD;
  40. ;;
  41. esac;
  42. echo -e "pkgname=$1\n"|cat - $root/src/$1/PKGBUILD > /tmp/out && mv /tmp/out $root/src/$1/PKGBUILD;
  43. fi;
  44. file=$root/etc/packages.d/$1;
  45. touch $file;
  46. echo "packages+=(\"[name]='$1' [type]='$btype' [script]='$script'\")" > $file;
  47. echo "Created package $1";
  48. else
  49. echo "Usage: $0 <package> [<sourcedir>]";
  50. fi;