選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

jitsi-meet-prosody.postinst 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. function generateRandomPassword() {
  18. cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 16
  19. }
  20. case "$1" in
  21. configure)
  22. # loading debconf
  23. . /usr/share/debconf/confmodule
  24. # try to get host from jitsi-videobridge
  25. db_get jitsi-videobridge/jvb-hostname
  26. if [ -z "$RET" ] ; then
  27. # server hostname
  28. db_set jitsi-videobridge/jvb-hostname "localhost"
  29. db_input critical jitsi-videobridge/jvb-hostname || true
  30. db_go
  31. fi
  32. JVB_HOSTNAME=$(echo "$RET" | xargs echo -n)
  33. db_get jitsi-videobridge/jvbsecret
  34. if [ -z "$RET" ] ; then
  35. db_input critical jitsi-videobridge/jvbsecret || true
  36. db_go
  37. fi
  38. JVB_SECRET="$RET"
  39. db_get jicofo/jicofo-authuser
  40. if [ -z "$RET" ] ; then
  41. db_input critical jicofo/jicofo-authuser || true
  42. db_go
  43. fi
  44. JICOFO_AUTH_USER="$RET"
  45. db_get jicofo/jicofo-authpassword
  46. if [ -z "$RET" ] ; then
  47. # if password is missing generate it, and store it
  48. JICOFO_AUTH_PASSWORD=`generateRandomPassword`
  49. db_set jicofo/jicofo-authpassword "$JICOFO_AUTH_PASSWORD"
  50. else
  51. JICOFO_AUTH_PASSWORD="$RET"
  52. fi
  53. JICOFO_AUTH_DOMAIN="auth.$JVB_HOSTNAME"
  54. # detect dpkg-reconfigure, just delete old links
  55. db_get jitsi-meet-prosody/jvb-hostname
  56. JVB_HOSTNAME_OLD=$(echo "$RET" | xargs echo -n)
  57. if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
  58. rm -f /etc/prosody/conf.d/$JVB_HOSTNAME_OLD.cfg.lua
  59. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.key
  60. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.crt
  61. fi
  62. # stores the hostname so we will reuse it later, like in purge
  63. db_set jitsi-meet-prosody/jvb-hostname "$JVB_HOSTNAME"
  64. db_get jitsi-meet-prosody/turn-secret
  65. if [ -z "$RET" ] ; then
  66. # 8-chars random secret used for the turnserver
  67. TURN_SECRET=`generateRandomPassword`
  68. db_set jitsi-meet-prosody/turn-secret "$TURN_SECRET"
  69. else
  70. TURN_SECRET="$RET"
  71. fi
  72. # and we're done with debconf
  73. db_stop
  74. PROSODY_CONFIG_PRESENT="true"
  75. PROSODY_CREATE_JICOFO_USER="false"
  76. PROSODY_HOST_CONFIG="/etc/prosody/conf.avail/$JVB_HOSTNAME.cfg.lua"
  77. PROSODY_CONFIG_OLD="/etc/prosody/prosody.cfg.lua"
  78. # if there is no prosody config extract our template
  79. # check for config in conf.avail or check whether it wasn't already configured in main config
  80. if [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JVB_HOSTNAME\"" $PROSODY_CONFIG_OLD; then
  81. PROSODY_CONFIG_PRESENT="false"
  82. mkdir -p /etc/prosody/conf.avail/
  83. mkdir -p /etc/prosody/conf.d/
  84. cp /usr/share/jitsi-meet-prosody/prosody.cfg.lua-jvb.example $PROSODY_HOST_CONFIG
  85. sed -i "s/jitmeet.example.com/$JVB_HOSTNAME/g" $PROSODY_HOST_CONFIG
  86. sed -i "s/focusUser/$JICOFO_AUTH_USER/g" $PROSODY_HOST_CONFIG
  87. sed -i "s/__turnSecret__/$TURN_SECRET/g" $PROSODY_HOST_CONFIG
  88. if [ ! -f /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua ]; then
  89. ln -s $PROSODY_HOST_CONFIG /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua
  90. fi
  91. PROSODY_CREATE_JICOFO_USER="true"
  92. # on some distributions main prosody config doesn't include configs
  93. # from conf.d folder enable it as this where we put our config by default
  94. if ! grep -q "Include \"conf\.d\/\*\.cfg.lua\"" $PROSODY_CONFIG_OLD; then
  95. echo -e "\nInclude \"conf.d/*.cfg.lua\"" >> $PROSODY_CONFIG_OLD
  96. fi
  97. fi
  98. if [ "$PROSODY_CREATE_JICOFO_USER" = "true" ]; then
  99. # create 'focus@auth.domain' prosody user
  100. prosodyctl register $JICOFO_AUTH_USER $JICOFO_AUTH_DOMAIN $JICOFO_AUTH_PASSWORD
  101. # trigger a restart
  102. PROSODY_CONFIG_PRESENT="false"
  103. fi
  104. USER_EXISTS_CHECK=`prosodyctl adduser jvb@$JICOFO_AUTH_DOMAIN < /dev/null || true`
  105. if [ ! "$USER_EXISTS_CHECK" = "That user already exists" ]; then
  106. prosodyctl register jvb $JICOFO_AUTH_DOMAIN $JVB_SECRET || true
  107. fi
  108. # Check whether prosody config has the internal muc, if not add it,
  109. # as we are migrating configs
  110. if [ -f $PROSODY_HOST_CONFIG ] && ! grep -q "internal.$JICOFO_AUTH_DOMAIN" $PROSODY_HOST_CONFIG; then
  111. echo -e "\nComponent \"internal.$JICOFO_AUTH_DOMAIN\" \"muc\"" >> $PROSODY_HOST_CONFIG
  112. echo -e " storage = \"memory\"" >> $PROSODY_HOST_CONFIG
  113. echo -e " modules_enabled = { \"ping\"; }" >> $PROSODY_HOST_CONFIG
  114. echo -e " admins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\", \"jvb@$JICOFO_AUTH_DOMAIN\" }" >> $PROSODY_HOST_CONFIG
  115. echo -e " muc_room_locking = false" >> $PROSODY_HOST_CONFIG
  116. echo -e " muc_room_default_public_jids = true" >> $PROSODY_HOST_CONFIG
  117. fi
  118. # Convert the old focus component config to the new one.
  119. # Old:
  120. # Component "focus.jitmeet.example.com"
  121. # component_secret = "focusSecret"
  122. # New:
  123. # Component "focus.jitmeet.example.com" "client_proxy"
  124. # target_address = "focus@auth.jitmeet.example.com"
  125. if grep -q "Component \"focus.$JVB_HOSTNAME\"" $PROSODY_HOST_CONFIG && ! grep "Component \"focus.$JVB_HOSTNAME\" \"client_proxy\"" $PROSODY_HOST_CONFIG ;then
  126. sed -i "s/Component \"focus.$JVB_HOSTNAME\"/Component \"focus.$JVB_HOSTNAME\" \"client_proxy\"\n target_address = \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\"/g" $PROSODY_HOST_CONFIG
  127. PROSODY_CONFIG_PRESENT="false"
  128. fi
  129. # Old versions of jitsi-meet-prosody come with the extra plugin path commented out (https://github.com/jitsi/jitsi-meet/commit/e11d4d3101e5228bf956a69a9e8da73d0aee7949)
  130. # Make sure it is uncommented, as it contains required modules.
  131. if grep -q -- '--plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }' $PROSODY_HOST_CONFIG ;then
  132. sed -i 's#--plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }#plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }#g' $PROSODY_HOST_CONFIG
  133. PROSODY_CONFIG_PRESENT="false"
  134. fi
  135. # Updates main muc component
  136. MAIN_MUC_PATTERN="Component \"conference.$JVB_HOSTNAME\" \"muc\""
  137. if ! grep -A 2 -- "${MAIN_MUC_PATTERN}" $PROSODY_HOST_CONFIG | grep -q "restrict_room_creation" ;then
  138. sed -i "s/${MAIN_MUC_PATTERN}/${MAIN_MUC_PATTERN}\n restrict_room_creation = true/g" $PROSODY_HOST_CONFIG
  139. PROSODY_CONFIG_PRESENT="false"
  140. fi
  141. if ! grep -q -- 'unlimited_jids' $PROSODY_HOST_CONFIG ;then
  142. sed -i "1s/^/unlimited_jids = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\", \"jvb@$JICOFO_AUTH_DOMAIN\" }\n/" $PROSODY_HOST_CONFIG
  143. sed -i "s/VirtualHost \"$JICOFO_AUTH_DOMAIN\"/VirtualHost \"$JICOFO_AUTH_DOMAIN\"\n modules_enabled = { \"limits_exception\"; }/g" $PROSODY_HOST_CONFIG
  144. PROSODY_CONFIG_PRESENT="false"
  145. fi
  146. # Make sure the focus@auth user's roster includes the proxy component (this is idempotent)
  147. prosodyctl mod_roster_command subscribe focus.$JVB_HOSTNAME $JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN
  148. if [ ! -f /var/lib/prosody/$JVB_HOSTNAME.crt ]; then
  149. # prosodyctl takes care for the permissions
  150. # echo for using all default values
  151. echo | prosodyctl cert generate $JVB_HOSTNAME
  152. ln -sf /var/lib/prosody/$JVB_HOSTNAME.key /etc/prosody/certs/$JVB_HOSTNAME.key
  153. ln -sf /var/lib/prosody/$JVB_HOSTNAME.crt /etc/prosody/certs/$JVB_HOSTNAME.crt
  154. fi
  155. PRTRUNK_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'prosody-trunk' 2>/dev/null | awk '{print $3}' || true)"
  156. PR10_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'prosody-0.10' 2>/dev/null | awk '{print $3}' || true)"
  157. PR_VER_INSTALLED=$(dpkg-query -f='${Version}\n' --show prosody 2>/dev/null || true)
  158. if [ "$PRTRUNK_INSTALL_CHECK" = "installed" ] \
  159. || [ "$PRTRUNK_INSTALL_CHECK" = "unpacked" ] ; then
  160. if [ -f $PROSODY_HOST_CONFIG ]; then
  161. sed -i 's/storage = \"memory\"/storage = \"null\"/g' $PROSODY_HOST_CONFIG
  162. # trigger a restart
  163. PROSODY_CONFIG_PRESENT="false"
  164. fi
  165. fi
  166. if [ "$PR10_INSTALL_CHECK" = "installed" ] \
  167. || [ "$PR10_INSTALL_CHECK" = "unpacked" ] \
  168. || dpkg --compare-versions "$PR_VER_INSTALLED" gt "0.10" ; then
  169. # if the version is 0.10.X (>0.10 and <0.11)
  170. if [ -f $PROSODY_HOST_CONFIG ] \
  171. && dpkg --compare-versions "$PR_VER_INSTALLED" lt "0.11" ; then
  172. sed -i 's/storage = \"memory\"/storage = \"none\"/g' $PROSODY_HOST_CONFIG
  173. # trigger a restart
  174. PROSODY_CONFIG_PRESENT="false"
  175. fi
  176. fi
  177. CERT_ADDED_TO_TRUST="false"
  178. if [ ! -f /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt ]; then
  179. # prosodyctl takes care for the permissions
  180. # echo for using all default values
  181. echo | prosodyctl cert generate $JICOFO_AUTH_DOMAIN
  182. AUTH_KEY_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.key"
  183. AUTH_CRT_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.crt"
  184. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.key $AUTH_KEY_FILE
  185. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt $AUTH_CRT_FILE
  186. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt /usr/local/share/ca-certificates/$JICOFO_AUTH_DOMAIN.crt
  187. # we need to force updating certificates, in some cases java trust
  188. # store not get re-generated with latest changes
  189. update-ca-certificates -f
  190. CERT_ADDED_TO_TRUST="true"
  191. # don't fail on systems with custom config ($PROSODY_HOST_CONFIG is missing)
  192. if [ -f $PROSODY_HOST_CONFIG ]; then
  193. # now let's add the ssl cert for the auth. domain (we use # as a sed delimiter cause filepaths are confused with default / delimiter)
  194. sed -i "s#VirtualHost \"$JICOFO_AUTH_DOMAIN\"#VirtualHost \"$JICOFO_AUTH_DOMAIN\"\n ssl = {\n key = \"$AUTH_KEY_FILE\";\n certificate = \"$AUTH_CRT_FILE\";\n \}#g" $PROSODY_HOST_CONFIG
  195. fi
  196. # trigger a restart
  197. PROSODY_CONFIG_PRESENT="false"
  198. fi
  199. if [ "$PROSODY_CONFIG_PRESENT" = "false" ]; then
  200. invoke-rc.d prosody restart || true
  201. # In case we had updated the certificates and restarted prosody, let's restart and the bridge if possible
  202. if [ -d /run/systemd/system ] && [ "$CERT_ADDED_TO_TRUST" = "true" ]; then
  203. systemctl restart jitsi-videobridge2.service >/dev/null || true
  204. fi
  205. fi
  206. ;;
  207. abort-upgrade|abort-remove|abort-deconfigure)
  208. ;;
  209. *)
  210. echo "postinst called with unknown argument \`$1'" >&2
  211. exit 1
  212. ;;
  213. esac
  214. # dh_installdeb will replace this with shell code automatically
  215. # generated by other debhelper scripts.
  216. #DEBHELPER#
  217. exit 0