portimport 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/ksh
  2. #
  3. # $OpenBSD: portimport,v 1.5 2014/02/09 15:10:49 zhuk Exp $
  4. # Copyright (c) 2013 Robert Peichaer
  5. #
  6. # Permission to use, copy, modify, and distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. #
  18. # Based on Marc Espie's portimport.
  19. # sthen: Modified to handle imports from mystuff/ and do a dry run first.
  20. # rpe: rewrite based on sthen@'s version
  21. # zhuk: checks and detection of pkgpath moved to portcheck(1)
  22. set -e
  23. set -u
  24. usage() {
  25. echo "usage: $(basename $0) [-p portsdir] [-u username]" >&2
  26. exit 1
  27. }
  28. user=$(id -un)
  29. portsdir=
  30. set -A portcheck_args -- -N
  31. while getopts "p:u:" OPT; do
  32. case $OPT in
  33. p) portsdir="$OPTARG"
  34. portcheck_args[${#portcheck_args[@]}]="-p$portsdir";;
  35. u) user=$OPTARG;;
  36. *) usage;;
  37. esac
  38. done
  39. shift $(($OPTIND - 1))
  40. (($# > 0)) && usage
  41. error=false
  42. pkgpath=$(portcheck "${portcheck_args[@]}") || error=true
  43. if $error; then
  44. read ans?'Do you want to continue after those errors? [y/N] '
  45. [[ $ans == +(y|Y) ]] || exit
  46. fi
  47. portsdir=${portsdir:-${PWD%"/$pkgpath"}}
  48. timestamp=$(date '+%Y%m%d')
  49. cvsroot=$user@cvs.openbsd.org:/cvs
  50. echo -n "Import would go into: "
  51. cvs -n -d$cvsroot import ports/$pkgpath $user ${user}_$timestamp 2>/dev/null | \
  52. grep Makefile | head -1 | awk '{print $2}' | xargs dirname
  53. read ans?'Does this look correct? [y/n] '
  54. if [[ $ans == +(y|Y) ]]; then
  55. cvs -d$cvsroot import ports/$pkgpath $user ${user}_$timestamp
  56. cd "$portsdir/${pkgpath%/*}"
  57. cvs -d$cvsroot update -AdP ${pkgpath##*/}
  58. echo "Don't forget to commit the ${pkgpath%/*}/Makefile when you're done!"
  59. pwd
  60. fi