package-add 1.5 KB

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