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

jitsi-meet-prosody.postinst 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. # if password is missing generate it, and store it
  45. JICOFO_AUTH_PASSWORD=`head -c 8 /dev/urandom | tr '\0-\377' 'a-zA-Z0-9a-zA-Z0-9a-zA-Z0-9a-zA-Z0-9@@@@####'`
  46. db_set jicofo/jicofo-authpassword "$JICOFO_AUTH_PASSWORD"
  47. else
  48. JICOFO_AUTH_PASSWORD="$RET"
  49. fi
  50. db_get jicofo/jicofosecret
  51. if [ -z "$RET" ] ; then
  52. # if secret is missing generate it, and store it
  53. JICOFO_SECRET=`head -c 8 /dev/urandom | tr '\0-\377' 'a-zA-Z0-9a-zA-Z0-9a-zA-Z0-9a-zA-Z0-9@@@@####'`
  54. db_set jicofo/jicofosecret "$JICOFO_SECRET"
  55. else
  56. JICOFO_SECRET="$RET"
  57. fi
  58. JICOFO_AUTH_DOMAIN="auth.$JVB_HOSTNAME"
  59. # detect dpkg-reconfigure, just delete old links
  60. db_get jitsi-meet-prosody/jvb-hostname
  61. JVB_HOSTNAME_OLD=$RET
  62. if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
  63. rm -f /etc/prosody/conf.d/$JVB_HOSTNAME_OLD.cfg.lua
  64. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.key
  65. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.crt
  66. fi
  67. # stores the hostname so we will reuse it later, like in purge
  68. db_set jitsi-meet-prosody/jvb-hostname "$JVB_HOSTNAME"
  69. db_get jitsi-meet-prosody/turn-secret
  70. if [ -z "$RET" ] ; then
  71. # 8-chars random secret used for the turnserver
  72. TURN_SECRET=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1`
  73. db_set jitsi-meet-prosody/turn-secret "$TURN_SECRET"
  74. else
  75. TURN_SECRET="$RET"
  76. fi
  77. # and we're done with debconf
  78. db_stop
  79. PROSODY_CONFIG_PRESENT="true"
  80. PROSODY_CREATE_JICOFO_USER="false"
  81. PROSODY_HOST_CONFIG="/etc/prosody/conf.avail/$JVB_HOSTNAME.cfg.lua"
  82. PROSODY_CONFIG_OLD="/etc/prosody/prosody.cfg.lua"
  83. # if there is no prosody config extract our template
  84. # check for config in conf.avail or check whether it wasn't already configured in main config
  85. if [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JVB_HOSTNAME\"" $PROSODY_CONFIG_OLD; then
  86. PROSODY_CONFIG_PRESENT="false"
  87. mkdir -p /etc/prosody/conf.avail/
  88. mkdir -p /etc/prosody/conf.d/
  89. cp /usr/share/jitsi-meet-prosody/prosody.cfg.lua-jvb.example $PROSODY_HOST_CONFIG
  90. sed -i "s/jitmeet.example.com/$JVB_HOSTNAME/g" $PROSODY_HOST_CONFIG
  91. sed -i "s/focusSecret/$JICOFO_SECRET/g" $PROSODY_HOST_CONFIG
  92. sed -i "s/focusUser/$JICOFO_AUTH_USER/g" $PROSODY_HOST_CONFIG
  93. sed -i "s/__turnSecret__/$TURN_SECRET/g" $PROSODY_HOST_CONFIG
  94. if [ ! -f /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua ]; then
  95. ln -s $PROSODY_HOST_CONFIG /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua
  96. fi
  97. PROSODY_CREATE_JICOFO_USER="true"
  98. # on some distributions main prosody config doesn't include configs
  99. # from conf.d folder enable it as this where we put our config by default
  100. if ! grep -q "Include \"conf\.d\/\*\.cfg.lua\"" $PROSODY_CONFIG_OLD; then
  101. echo -e "\nInclude \"conf.d/*.cfg.lua\"" >> $PROSODY_CONFIG_OLD
  102. fi
  103. fi
  104. if [ "$PROSODY_CREATE_JICOFO_USER" = "true" ]; then
  105. # create 'focus@auth.domain' prosody user
  106. prosodyctl register $JICOFO_AUTH_USER $JICOFO_AUTH_DOMAIN $JICOFO_AUTH_PASSWORD
  107. # trigger a restart
  108. PROSODY_CONFIG_PRESENT="false"
  109. fi
  110. USER_EXISTS_CHECK=`prosodyctl adduser jvb@$JICOFO_AUTH_DOMAIN < /dev/null || true`
  111. if [ ! "$USER_EXISTS_CHECK" = "That user already exists" ]; then
  112. prosodyctl register jvb $JICOFO_AUTH_DOMAIN $JVB_SECRET || true
  113. fi
  114. # Check whether prosody config has the internal muc, if not add it,
  115. # as we are migrating configs
  116. if [ -f $PROSODY_HOST_CONFIG ] && ! grep -q "internal.auth.$JVB_HOSTNAME" $PROSODY_HOST_CONFIG; then
  117. echo -e "\nComponent \"internal.auth.$JVB_HOSTNAME\" \"muc\"" >> $PROSODY_HOST_CONFIG
  118. echo -e " storage = \"null\"" >> $PROSODY_HOST_CONFIG
  119. echo -e " modules_enabled = { \"ping\"; }" >> $PROSODY_HOST_CONFIG
  120. echo -e " admins = { \"focusUser@auth.jitmeet.example.com\", \"jvb@auth.jitmeet.example.com\" }" >> $PROSODY_HOST_CONFIG
  121. fi
  122. if [ ! -f /var/lib/prosody/$JVB_HOSTNAME.crt ]; then
  123. # prosodyctl takes care for the permissions
  124. # echo for using all default values
  125. echo | prosodyctl cert generate $JVB_HOSTNAME
  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. fi
  129. PR11_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'prosody-0.11' 2>/dev/null | awk '{print $3}' || true)"
  130. PR10_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'prosody-0.10' 2>/dev/null | awk '{print $3}' || true)"
  131. PR_VER_INSTALLED=$(dpkg-query -f='${Version}\n' --show prosody 2>/dev/null || true)
  132. if [ "$PR11_INSTALL_CHECK" = "installed" ] \
  133. || [ "$PR11_INSTALL_CHECK" = "unpacked" ] \
  134. || dpkg --compare-versions "$PR_VER_INSTALLED" gt "0.11" ; then
  135. if [ -f $PROSODY_HOST_CONFIG ]; then
  136. sed -i 's/storage = \"null\"/storage = \"memory\"/g' $PROSODY_HOST_CONFIG
  137. # trigger a restart
  138. PROSODY_CONFIG_PRESENT="false"
  139. fi
  140. fi
  141. if [ "$PR10_INSTALL_CHECK" = "installed" ] \
  142. || [ "$PR10_INSTALL_CHECK" = "unpacked" ] \
  143. || dpkg --compare-versions "$PR_VER_INSTALLED" gt "0.10" ; then
  144. # if the version is 0.10.X (>0.10 and <0.11)
  145. if [ -f $PROSODY_HOST_CONFIG ] \
  146. && dpkg --compare-versions "$PR_VER_INSTALLED" lt "0.11" ; then
  147. sed -i 's/storage = \"null\"/storage = \"none\"/g' $PROSODY_HOST_CONFIG
  148. # trigger a restart
  149. PROSODY_CONFIG_PRESENT="false"
  150. fi
  151. fi
  152. if [ ! -f /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt ]; then
  153. # prosodyctl takes care for the permissions
  154. # echo for using all default values
  155. echo | prosodyctl cert generate $JICOFO_AUTH_DOMAIN
  156. AUTH_KEY_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.key"
  157. AUTH_CRT_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.crt"
  158. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.key $AUTH_KEY_FILE
  159. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt $AUTH_CRT_FILE
  160. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt /usr/local/share/ca-certificates/$JICOFO_AUTH_DOMAIN.crt
  161. # we need to force updating certificates, in some cases java trust
  162. # store not get re-generated with latest changes
  163. update-ca-certificates -f
  164. # don't fail on systems with custom config ($PROSODY_HOST_CONFIG is missing)
  165. if [ -f $PROSODY_HOST_CONFIG ]; then
  166. # now let's add the ssl cert for the auth. domain (we use # as a sed delimiter cause filepaths are confused with default / delimiter)
  167. 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
  168. fi
  169. # trigger a restart
  170. PROSODY_CONFIG_PRESENT="false"
  171. fi
  172. if [ "$PROSODY_CONFIG_PRESENT" = "false" ]; then
  173. invoke-rc.d prosody restart || true
  174. fi
  175. ;;
  176. abort-upgrade|abort-remove|abort-deconfigure)
  177. ;;
  178. *)
  179. echo "postinst called with unknown argument \`$1'" >&2
  180. exit 1
  181. ;;
  182. esac
  183. # dh_installdeb will replace this with shell code automatically
  184. # generated by other debhelper scripts.
  185. #DEBHELPER#
  186. exit 0