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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. fi
  116. # Convert the old focus component config to the new one.
  117. # Old:
  118. # Component "focus.jitmeet.example.com"
  119. # component_secret = "focusSecret"
  120. # New:
  121. # Component "focus.jitmeet.example.com" "client_proxy"
  122. # target_address = "focus@auth.jitmeet.example.com"
  123. if grep -q "Component \"focus.$JVB_HOSTNAME\"" $PROSODY_HOST_CONFIG && ! grep "Component \"focus.$JVB_HOSTNAME\" \"client_proxy\"" $PROSODY_HOST_CONFIG ;then
  124. 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
  125. PROSODY_CONFIG_PRESENT="false"
  126. fi
  127. # Old versions of jitsi-meet-prosody come with the extra plugin path commented out (https://github.com/jitsi/jitsi-meet/commit/e11d4d3101e5228bf956a69a9e8da73d0aee7949)
  128. # Make sure it is uncommented, as it contains required modules.
  129. if grep -q -- '--plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }' $PROSODY_HOST_CONFIG ;then
  130. sed -i 's#--plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }#plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }#g' $PROSODY_HOST_CONFIG
  131. PROSODY_CONFIG_PRESENT="false"
  132. fi
  133. # Updates main muc component
  134. MAIN_MUC_PATTERN="Component \"conference.$JVB_HOSTNAME\" \"muc\""
  135. if ! grep -A 2 -- "${MAIN_MUC_PATTERN}" $PROSODY_HOST_CONFIG | grep -q "restrict_room_creation" ;then
  136. sed -i "s/${MAIN_MUC_PATTERN}/${MAIN_MUC_PATTERN}\n restrict_room_creation = true/g" $PROSODY_HOST_CONFIG
  137. PROSODY_CONFIG_PRESENT="false"
  138. fi
  139. if ! grep -q -- 'unlimited_jids' $PROSODY_HOST_CONFIG ;then
  140. sed -i "1s/^/unlimited_jids = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\", \"jvb@$JICOFO_AUTH_DOMAIN\" }\n/" $PROSODY_HOST_CONFIG
  141. sed -i "s/VirtualHost \"$JICOFO_AUTH_DOMAIN\"/VirtualHost \"$JICOFO_AUTH_DOMAIN\"\n modules_enabled = { \"limits_exception\"; }/g" $PROSODY_HOST_CONFIG
  142. PROSODY_CONFIG_PRESENT="false"
  143. fi
  144. # Make sure the focus@auth user's roster includes the proxy component (this is idempotent)
  145. prosodyctl mod_roster_command subscribe focus.$JVB_HOSTNAME $JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN
  146. if [ ! -f /var/lib/prosody/$JVB_HOSTNAME.crt ]; then
  147. # prosodyctl takes care for the permissions
  148. # echo for using all default values
  149. echo | prosodyctl cert generate $JVB_HOSTNAME
  150. ln -sf /var/lib/prosody/$JVB_HOSTNAME.key /etc/prosody/certs/$JVB_HOSTNAME.key
  151. ln -sf /var/lib/prosody/$JVB_HOSTNAME.crt /etc/prosody/certs/$JVB_HOSTNAME.crt
  152. fi
  153. PRTRUNK_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'prosody-trunk' 2>/dev/null | awk '{print $3}' || true)"
  154. PR10_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'prosody-0.10' 2>/dev/null | awk '{print $3}' || true)"
  155. PR_VER_INSTALLED=$(dpkg-query -f='${Version}\n' --show prosody 2>/dev/null || true)
  156. if [ "$PRTRUNK_INSTALL_CHECK" = "installed" ] \
  157. || [ "$PRTRUNK_INSTALL_CHECK" = "unpacked" ] ; then
  158. if [ -f $PROSODY_HOST_CONFIG ]; then
  159. sed -i 's/storage = \"memory\"/storage = \"null\"/g' $PROSODY_HOST_CONFIG
  160. # trigger a restart
  161. PROSODY_CONFIG_PRESENT="false"
  162. fi
  163. fi
  164. if [ "$PR10_INSTALL_CHECK" = "installed" ] \
  165. || [ "$PR10_INSTALL_CHECK" = "unpacked" ] \
  166. || dpkg --compare-versions "$PR_VER_INSTALLED" gt "0.10" ; then
  167. # if the version is 0.10.X (>0.10 and <0.11)
  168. if [ -f $PROSODY_HOST_CONFIG ] \
  169. && dpkg --compare-versions "$PR_VER_INSTALLED" lt "0.11" ; then
  170. sed -i 's/storage = \"memory\"/storage = \"none\"/g' $PROSODY_HOST_CONFIG
  171. # trigger a restart
  172. PROSODY_CONFIG_PRESENT="false"
  173. fi
  174. fi
  175. if [ ! -f /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt ]; then
  176. # prosodyctl takes care for the permissions
  177. # echo for using all default values
  178. echo | prosodyctl cert generate $JICOFO_AUTH_DOMAIN
  179. AUTH_KEY_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.key"
  180. AUTH_CRT_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.crt"
  181. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.key $AUTH_KEY_FILE
  182. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt $AUTH_CRT_FILE
  183. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt /usr/local/share/ca-certificates/$JICOFO_AUTH_DOMAIN.crt
  184. # we need to force updating certificates, in some cases java trust
  185. # store not get re-generated with latest changes
  186. update-ca-certificates -f
  187. # don't fail on systems with custom config ($PROSODY_HOST_CONFIG is missing)
  188. if [ -f $PROSODY_HOST_CONFIG ]; then
  189. # now let's add the ssl cert for the auth. domain (we use # as a sed delimiter cause filepaths are confused with default / delimiter)
  190. 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
  191. fi
  192. # trigger a restart
  193. PROSODY_CONFIG_PRESENT="false"
  194. fi
  195. if [ "$PROSODY_CONFIG_PRESENT" = "false" ]; then
  196. invoke-rc.d prosody restart || true
  197. fi
  198. ;;
  199. abort-upgrade|abort-remove|abort-deconfigure)
  200. ;;
  201. *)
  202. echo "postinst called with unknown argument \`$1'" >&2
  203. exit 1
  204. ;;
  205. esac
  206. # dh_installdeb will replace this with shell code automatically
  207. # generated by other debhelper scripts.
  208. #DEBHELPER#
  209. exit 0