package-add 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. if [[ ! -f src/$1/build.sh ]];then
  13. cp etc/build.sh.in src/$1/build.sh
  14. fi;
  15. chmod +x src/$1/build.sh
  16. echo -e "Type:\n (1) script\n (2) git\n (3) svn";
  17. while [[ ! $btype =~ ^1|2|3$ ]]; do
  18. read btype;
  19. done;
  20. case $btype in
  21. 2)
  22. btype="git";
  23. ;;
  24. 3)
  25. btype="svn";
  26. ;;
  27. *)
  28. btype="script";
  29. read -p "Script path: " script;
  30. ;;
  31. esac;
  32. if [[ ! -f src/$1/PKGBUILD ]];then
  33. cp etc/PKGBUILD.in src/$1/PKGBUILD;
  34. case $btype in
  35. git)
  36. 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;
  37. ;;
  38. svn)
  39. 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;
  40. ;;
  41. script)
  42. 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;
  43. ;;
  44. esac;
  45. echo -e "pkgname=$1\n"|cat - src/$1/PKGBUILD > /tmp/out && mv /tmp/out src/$1/PKGBUILD;
  46. fi;
  47. file=`dirname $BASH_SOURCE`/../etc/packages.d/$1;
  48. touch $file;
  49. echo "packages+=(\"[name]='$1' [type]='$btype' [script]='$script'\")" > $file;
  50. echo "Created package $1";
  51. else
  52. echo "Usage: $0 <package> [<sourcedir>]";
  53. fi;