package-add 1.6 KB

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