You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jitsi-meet-prosody.postinst 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. # postinst script for jitsi-meet-prosody
  3. #
  4. # see: dh_installdeb(1)
  5. set -e
  6. # summary of how this script can be called:
  7. # * <postinst> `configure' <most-recently-configured-version>
  8. # * <old-postinst> `abort-upgrade' <new version>
  9. # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  10. # <new-version>
  11. # * <postinst> `abort-remove'
  12. # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  13. # <failed-install-package> <version> `removing'
  14. # <conflicting-package> <version>
  15. # for details, see http://www.debian.org/doc/debian-policy/ or
  16. # the debian-policy package
  17. case "$1" in
  18. configure)
  19. # loading debconf
  20. . /usr/share/debconf/confmodule
  21. # try to get host from jitsi-videobridge
  22. db_get jitsi-videobridge/jvb-hostname
  23. if [ -z "$RET" ] ; then
  24. # server hostname
  25. db_set jitsi-videobridge/jvb-hostname "localhost"
  26. db_input critical jitsi-videobridge/jvb-hostname || true
  27. db_go
  28. fi
  29. JVB_HOSTNAME="$RET"
  30. db_get jitsi-videobridge/jvbsecret
  31. if [ -z "$RET" ] ; then
  32. db_input critical jitsi-videobridge/jvbsecret || true
  33. db_go
  34. fi
  35. JVB_SECRET="$RET"
  36. db_get jicofo/jicofo-authuser
  37. if [ -z "$RET" ] ; then
  38. db_input critical jicofo/jicofo-authuser || true
  39. db_go
  40. fi
  41. JICOFO_AUTH_USER="$RET"
  42. db_get jicofo/jicofo-authpassword
  43. if [ -z "$RET" ] ; then
  44. db_input critical jicofo/jicofo-authpassword || true
  45. db_go
  46. fi
  47. JICOFO_AUTH_PASSWORD="$RET"
  48. db_get jicofo/jicofosecret
  49. if [ -z "$RET" ] ; then
  50. db_input critical jicofo/jicofosecret || true
  51. db_go
  52. fi
  53. JICOFO_SECRET="$RET"
  54. JICOFO_AUTH_DOMAIN="auth.$JVB_HOSTNAME"
  55. # detect dpkg-reconfigure, just delete old links
  56. db_get jitsi-meet-prosody/jvb-hostname
  57. JVB_HOSTNAME_OLD=$RET
  58. if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
  59. rm -f /etc/prosody/conf.d/$JVB_HOSTNAME_OLD.cfg.lua
  60. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.key
  61. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.crt
  62. fi
  63. # stores the hostname so we will reuse it later, like in purge
  64. db_set jitsi-meet-prosody/jvb-hostname "$JVB_HOSTNAME"
  65. # and we're done with debconf
  66. db_stop
  67. PROSODY_CONFIG_PRESENT="true"
  68. PROSODY_CREATE_JICOFO_USER="false"
  69. PROSODY_HOST_CONFIG="/etc/prosody/conf.avail/$JVB_HOSTNAME.cfg.lua"
  70. PROSODY_CONFIG_OLD="/etc/prosody/prosody.cfg.lua"
  71. # if there is no prosody config extract our template
  72. # check for config in conf.avail or check whether it wasn't already configured in main config
  73. if [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JVB_HOSTNAME\"" $PROSODY_CONFIG_OLD; then
  74. PROSODY_CONFIG_PRESENT="false"
  75. mkdir -p /etc/prosody/conf.avail/
  76. cp /usr/share/doc/jitsi-meet-prosody/prosody.cfg.lua-jvb.example $PROSODY_HOST_CONFIG
  77. sed -i "s/jitmeet.example.com/$JVB_HOSTNAME/g" $PROSODY_HOST_CONFIG
  78. sed -i "s/jitmeetSecret/$JVB_SECRET/g" $PROSODY_HOST_CONFIG
  79. sed -i "s/focusSecret/$JICOFO_SECRET/g" $PROSODY_HOST_CONFIG
  80. sed -i "s/focusUser/$JICOFO_AUTH_USER/g" $PROSODY_HOST_CONFIG
  81. if [ ! -f /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua ]; then
  82. ln -s $PROSODY_HOST_CONFIG /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua
  83. fi
  84. PROSODY_CREATE_JICOFO_USER="true"
  85. # on some distributions main prosody config doesn't include configs
  86. # from conf.d folder enable it as this where we put our config by default
  87. if ! grep -q "Include \"conf\.d\/\*\.cfg.lua\"" $PROSODY_CONFIG_OLD; then
  88. echo -e "\nInclude \"conf.d/*.cfg.lua\"" >> $PROSODY_CONFIG_OLD
  89. fi
  90. fi
  91. # UPGRADE to server side focus check if focus is configured
  92. if [ -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JICOFO_AUTH_DOMAIN\"" $PROSODY_HOST_CONFIG; then
  93. echo -e "\nVirtualHost \"$JICOFO_AUTH_DOMAIN\"" >> $PROSODY_HOST_CONFIG
  94. echo -e " authentication = \"internal_plain\"\n" >> $PROSODY_HOST_CONFIG
  95. sed -i "s/Component \"conference.$JVB_HOSTNAME\" \"muc\"/Component \"conference.$JVB_HOSTNAME\" \"muc\"\nadmins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\" }\n/g" $PROSODY_HOST_CONFIG
  96. echo -e "Component \"focus.$JVB_HOSTNAME\"" >> $PROSODY_HOST_CONFIG
  97. echo -e " component_secret=\"$JICOFO_SECRET\"\n" >> $PROSODY_HOST_CONFIG
  98. PROSODY_CREATE_JICOFO_USER="true"
  99. # UPGRADE to server side focus on old config(/etc/prosody/prosody.cfg.lua)
  100. elif [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JICOFO_AUTH_DOMAIN\"" $PROSODY_CONFIG_OLD; then
  101. echo -e "\nVirtualHost \"$JICOFO_AUTH_DOMAIN\"" >> $PROSODY_CONFIG_OLD
  102. echo -e " authentication = \"internal_plain\"\n" >> $PROSODY_CONFIG_OLD
  103. if ! grep -q "admins = { }" $PROSODY_CONFIG_OLD; then
  104. echo -e "admins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\" }\n" >> $PROSODY_CONFIG_OLD
  105. else
  106. sed -i "s/admins = { }/admins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\" }\n/g" $PROSODY_CONFIG_OLD
  107. fi
  108. echo -e "Component \"focus.$JVB_HOSTNAME\"" >> $PROSODY_CONFIG_OLD
  109. echo -e " component_secret=\"$JICOFO_SECRET\"\n" >> $PROSODY_CONFIG_OLD
  110. PROSODY_CREATE_JICOFO_USER="true"
  111. fi
  112. if [ "$PROSODY_CREATE_JICOFO_USER" = "true" ]; then
  113. # create 'focus@auth.domain' prosody user
  114. prosodyctl register $JICOFO_AUTH_USER $JICOFO_AUTH_DOMAIN $JICOFO_AUTH_PASSWORD
  115. # trigger a restart
  116. PROSODY_CONFIG_PRESENT="false"
  117. fi
  118. if [ ! -f /var/lib/prosody/$JVB_HOSTNAME.crt ]; then
  119. HOST="$( (hostname -s; echo localhost) | head -n 1)"
  120. DOMAIN="$( (hostname -d; echo localdomain) | head -n 1)"
  121. openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \
  122. "/O=$DOMAIN/OU=$HOST/CN=$JVB_HOSTNAME/emailAddress=webmaster@$HOST.$DOMAIN" \
  123. -keyout /var/lib/prosody/$JVB_HOSTNAME.key \
  124. -out /var/lib/prosody/$JVB_HOSTNAME.crt
  125. fi
  126. ln -sf /var/lib/prosody/$JVB_HOSTNAME.key /etc/prosody/certs/$JVB_HOSTNAME.key
  127. ln -sf /var/lib/prosody/$JVB_HOSTNAME.crt /etc/prosody/certs/$JVB_HOSTNAME.crt
  128. if [ "$PROSODY_CONFIG_PRESENT" = "false" ]; then
  129. invoke-rc.d prosody restart
  130. fi
  131. ;;
  132. abort-upgrade|abort-remove|abort-deconfigure)
  133. ;;
  134. *)
  135. echo "postinst called with unknown argument \`$1'" >&2
  136. exit 1
  137. ;;
  138. esac
  139. # dh_installdeb will replace this with shell code automatically
  140. # generated by other debhelper scripts.
  141. #DEBHELPER#
  142. exit 0