summaryrefslogtreecommitdiff
path: root/packaging/freebsd/pkg-install
blob: c2af9602830ab6fa6d5ca30e38b0e365a8bf1491 (plain)
  1. #!/bin/sh
  2. # an installation script for monkeysphere (borrowing liberally from
  3. # Wnn6's port and from monkeysphere's debian/monkeysphere.postinst)
  4. # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  5. # Copyright 2008
  6. # FIXME: is /var/lib/monkeysphere the right place for this stuff on
  7. # FreeBSD?
  8. VARLIB="/var/lib/monkeysphere"
  9. check_pw()
  10. {
  11. if which -s pw; then
  12. :
  13. else
  14. cat <<EOF
  15. This system looks like a pre-2.2 version of FreeBSD. We see that it
  16. is missing the "pw" utility. We need this utility. Please get and
  17. install it, and try again. You can get the source from:
  18. ftp://ftp.freebsd.org/pub/FreeBSD/FreeBSD-current/src/usr.sbin/pw.tar.gz
  19. EOF
  20. exit 1
  21. fi
  22. }
  23. ask() {
  24. local question default answer
  25. question=$1
  26. default=$2
  27. if [ -z "${PACKAGE_BUILDING}" ]; then
  28. read -p "${question} (y/n) [${default}]? " answer
  29. fi
  30. if [ x${answer} = x ]; then
  31. answer=${default}
  32. fi
  33. echo ${answer}
  34. }
  35. yesno() {
  36. local dflt question answer
  37. question=$1
  38. dflt=$2
  39. while :; do
  40. answer=$(ask "${question}" "${dflt}")
  41. case "${answer}" in
  42. [Yy]*) return 0;;
  43. [Nn]*) return 1;;
  44. esac
  45. echo "Please answer yes or no."
  46. done
  47. }
  48. failure() {
  49. local retval badgroups badusers
  50. retval=$1
  51. badgroups=`getent group monkeysphere 641`
  52. badusers=`getent passwd monkeysphere 641`
  53. if [ X"$badgroups" != X ]; then
  54. badgroups="
  55. Conflicting group(s):
  56. $badgroups"
  57. fi
  58. if [ X"$badusers" != X ]; then
  59. badusers="Conflicting user(s):
  60. $badusers"
  61. fi
  62. cat <<EOF
  63. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. This port or package assumes that the ID number of 'monkeysphere' will
  65. be 641. But this system has:
  66. $badgroups
  67. $badusers
  68. Please correct these conflict(s) and try again.
  69. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70. EOF
  71. exit $retval
  72. }
  73. case $2 in
  74. POST-INSTALL)
  75. # make sure that the correct user and group are present:
  76. id_monkeysphere=`id -u monkeysphere 2> /dev/null`
  77. gid_monkeysphere=`getent group monkeysphere | cut -f3 -d: 2> /dev/null`
  78. if [ X"$id_monkeysphere" = X641 ] && [ X"$gid_monkeysphere" = X641 ];then
  79. exit 0
  80. else
  81. # add an account 'monkeysphere' to this system
  82. echo ""
  83. echo "You need an account 'monkeysphere' whose ID number is 641, with group 'monkeysphere' (GID 641)"
  84. if yesno "Would you like to create it automatically?" y; then
  85. # We need a command 'pw(8)'
  86. check_pw
  87. pw groupadd monkeysphere -g 641 || failure $?
  88. pw useradd monkeysphere -u 641 -g 641 -h - -d "$VARLIB" \
  89. -s /bin/sh -c 'monkeysphere authentication user,,,' || failure $?
  90. # FIXME: should we really be using a real shell? Convention
  91. # (/usr/ports/UIDs) seems to indicate /nonexistent is
  92. # preferred
  93. else
  94. echo "Please create it, and try again."
  95. exit 1
  96. fi
  97. fi
  98. # FIXME: we should create $VARLIB and chown the relevant subdirs
  99. # (see debian/monkeysphere.postinst)
  100. ;;
  101. esac