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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. JICOFO_AUTH_USER="focus"
  40. db_get jicofo/jicofo-authpassword
  41. if [ -z "$RET" ] ; then
  42. # if password is missing generate it, and store it
  43. JICOFO_AUTH_PASSWORD=`generateRandomPassword`
  44. db_set jicofo/jicofo-authpassword "$JICOFO_AUTH_PASSWORD"
  45. else
  46. JICOFO_AUTH_PASSWORD="$RET"
  47. fi
  48. JICOFO_AUTH_DOMAIN="auth.$JVB_HOSTNAME"
  49. # detect dpkg-reconfigure, just delete old links
  50. db_get jitsi-meet-prosody/jvb-hostname
  51. JVB_HOSTNAME_OLD=$(echo "$RET" | xargs echo -n)
  52. if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
  53. rm -f /etc/prosody/conf.d/$JVB_HOSTNAME_OLD.cfg.lua
  54. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.key
  55. rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.crt
  56. fi
  57. # stores the hostname so we will reuse it later, like in purge
  58. db_set jitsi-meet-prosody/jvb-hostname "$JVB_HOSTNAME"
  59. db_get jitsi-meet-prosody/turn-secret
  60. if [ -z "$RET" ] ; then
  61. # 8-chars random secret used for the turnserver
  62. TURN_SECRET=`generateRandomPassword`
  63. db_set jitsi-meet-prosody/turn-secret "$TURN_SECRET"
  64. else
  65. TURN_SECRET="$RET"
  66. fi
  67. SELF_SIGNED_CHOICE="Generate a new self-signed certificate"
  68. # In the case of updating from an older version the configure of -prosody package may happen before the -config
  69. # one, so if JAAS_INPUT is empty (the question is not asked), let's ask it now.
  70. # If db_get returns an error (workaround for strange Debian failure) continue without stopping the config
  71. db_get jitsi-meet/cert-choice || CERT_CHOICE=$SELF_SIGNED_CHOICE
  72. CERT_CHOICE="$RET"
  73. if [ -z "$CERT_CHOICE" ] ; then
  74. db_input critical jitsi-meet/cert-choice || true
  75. db_go
  76. db_get jitsi-meet/cert-choice
  77. CERT_CHOICE="$RET"
  78. fi
  79. if [ "$CERT_CHOICE" != "$SELF_SIGNED_CHOICE" ]; then
  80. db_get jitsi-meet/jaas-choice
  81. JAAS_INPUT="$RET"
  82. if [ -z "$JAAS_INPUT" ] ; then
  83. db_subst jitsi-meet/jaas-choice domain "${JVB_HOSTNAME}"
  84. db_set jitsi-meet/jaas-choice false
  85. db_input critical jitsi-meet/jaas-choice || true
  86. db_go
  87. db_get jitsi-meet/jaas-choice
  88. JAAS_INPUT="$RET"
  89. fi
  90. fi
  91. # and we're done with debconf
  92. db_stop
  93. PROSODY_CONFIG_PRESENT="true"
  94. PROSODY_CREATE_JICOFO_USER="false"
  95. PROSODY_HOST_CONFIG="/etc/prosody/conf.avail/$JVB_HOSTNAME.cfg.lua"
  96. PROSODY_CONFIG_OLD="/etc/prosody/prosody.cfg.lua"
  97. # if there is no prosody config extract our template
  98. # check for config in conf.avail or check whether it wasn't already configured in main config
  99. if [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JVB_HOSTNAME\"" $PROSODY_CONFIG_OLD; then
  100. PROSODY_CONFIG_PRESENT="false"
  101. mkdir -p /etc/prosody/conf.avail/
  102. mkdir -p /etc/prosody/conf.d/
  103. cp /usr/share/jitsi-meet-prosody/prosody.cfg.lua-jvb.example $PROSODY_HOST_CONFIG
  104. sed -i "s/jitmeet.example.com/$JVB_HOSTNAME/g" $PROSODY_HOST_CONFIG
  105. sed -i "s/focusUser/$JICOFO_AUTH_USER/g" $PROSODY_HOST_CONFIG
  106. sed -i "s/__turnSecret__/$TURN_SECRET/g" $PROSODY_HOST_CONFIG
  107. if [ ! -f /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua ]; then
  108. ln -s $PROSODY_HOST_CONFIG /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua
  109. fi
  110. PROSODY_CREATE_JICOFO_USER="true"
  111. # on some distributions main prosody config doesn't include configs
  112. # from conf.d folder enable it as this where we put our config by default
  113. if ! grep -q "Include \"conf\.d\/\*\.cfg.lua\"" $PROSODY_CONFIG_OLD; then
  114. echo -e "\nInclude \"conf.d/*.cfg.lua\"" >> $PROSODY_CONFIG_OLD
  115. fi
  116. fi
  117. if [ "$PROSODY_CREATE_JICOFO_USER" = "true" ]; then
  118. # create 'focus@auth.domain' prosody user
  119. prosodyctl register $JICOFO_AUTH_USER $JICOFO_AUTH_DOMAIN $JICOFO_AUTH_PASSWORD
  120. # trigger a restart
  121. PROSODY_CONFIG_PRESENT="false"
  122. fi
  123. # creates the user if it does not exist
  124. echo -e "$JVB_SECRET\n$JVB_SECRET" | prosodyctl adduser jvb@$JICOFO_AUTH_DOMAIN > /dev/null || true
  125. # Check whether prosody config has the internal muc, if not add it,
  126. # as we are migrating configs
  127. if [ -f $PROSODY_HOST_CONFIG ] && ! grep -q "internal.$JICOFO_AUTH_DOMAIN" $PROSODY_HOST_CONFIG; then
  128. echo -e "\nComponent \"internal.$JICOFO_AUTH_DOMAIN\" \"muc\"" >> $PROSODY_HOST_CONFIG
  129. echo -e " storage = \"memory\"" >> $PROSODY_HOST_CONFIG
  130. echo -e " modules_enabled = { \"ping\"; }" >> $PROSODY_HOST_CONFIG
  131. echo -e " admins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\", \"jvb@$JICOFO_AUTH_DOMAIN\" }" >> $PROSODY_HOST_CONFIG
  132. echo -e " muc_room_locking = false" >> $PROSODY_HOST_CONFIG
  133. echo -e " muc_room_default_public_jids = true" >> $PROSODY_HOST_CONFIG
  134. fi
  135. # Convert the old focus component config to the new one.
  136. # Old:
  137. # Component "focus.jitmeet.example.com"
  138. # component_secret = "focusSecret"
  139. # New:
  140. # Component "focus.jitmeet.example.com" "client_proxy"
  141. # target_address = "focus@auth.jitmeet.example.com"
  142. if grep -q "Component \"focus.$JVB_HOSTNAME\"" $PROSODY_HOST_CONFIG && ! grep -q "Component \"focus.$JVB_HOSTNAME\" \"client_proxy\"" $PROSODY_HOST_CONFIG ;then
  143. 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
  144. PROSODY_CONFIG_PRESENT="false"
  145. fi
  146. # Old versions of jitsi-meet-prosody come with the extra plugin path commented out (https://github.com/jitsi/jitsi-meet/commit/e11d4d3101e5228bf956a69a9e8da73d0aee7949)
  147. # Make sure it is uncommented, as it contains required modules.
  148. if grep -q -- '--plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }' $PROSODY_HOST_CONFIG ;then
  149. sed -i 's#--plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }#plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }#g' $PROSODY_HOST_CONFIG
  150. PROSODY_CONFIG_PRESENT="false"
  151. fi
  152. # Updates main muc component
  153. MAIN_MUC_PATTERN="Component \"conference.$JVB_HOSTNAME\" \"muc\""
  154. if ! grep -A 2 -- "${MAIN_MUC_PATTERN}" $PROSODY_HOST_CONFIG | grep -q "restrict_room_creation" ;then
  155. sed -i "s/${MAIN_MUC_PATTERN}/${MAIN_MUC_PATTERN}\n restrict_room_creation = true/g" $PROSODY_HOST_CONFIG
  156. PROSODY_CONFIG_PRESENT="false"
  157. fi
  158. if ! grep -q -- 'unlimited_jids' $PROSODY_HOST_CONFIG ;then
  159. sed -i "1s/^/unlimited_jids = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\", \"jvb@$JICOFO_AUTH_DOMAIN\" }\n/" $PROSODY_HOST_CONFIG
  160. sed -i "s/VirtualHost \"$JICOFO_AUTH_DOMAIN\"/VirtualHost \"$JICOFO_AUTH_DOMAIN\"\n modules_enabled = { \"limits_exception\"; }/g" $PROSODY_HOST_CONFIG
  161. PROSODY_CONFIG_PRESENT="false"
  162. fi
  163. JAAS_HOST_CONFIG="/etc/prosody/conf.avail/jaas.cfg.lua"
  164. if [ "${JAAS_INPUT}" = "true" ] && [ ! -f $JAAS_HOST_CONFIG ]; then
  165. sed -i "s/enabled = false -- Jitsi meet components/enabled = true -- Jitsi meet components/g" $PROSODY_HOST_CONFIG
  166. PROSODY_CONFIG_PRESENT="false"
  167. fi
  168. # For those deployments that don't have the config in the jitsi-meet prosody config add the new jaas file
  169. if [ ! -f $JAAS_HOST_CONFIG ] && ! grep -q "VirtualHost \"jigasi.meet.jitsi\"" $PROSODY_HOST_CONFIG; then
  170. PROSODY_CONFIG_PRESENT="false"
  171. cp /usr/share/jitsi-meet-prosody/jaas.cfg.lua $JAAS_HOST_CONFIG
  172. sed -i "s/jitmeet.example.com/$JVB_HOSTNAME/g" $JAAS_HOST_CONFIG
  173. fi
  174. if [ "${JAAS_INPUT}" = "true" ]; then
  175. JAAS_HOST_CONFIG_ENABLED="/etc/prosody/conf.d/jaas.cfg.lua "
  176. if [ ! -f $JAAS_HOST_CONFIG_ENABLED ] && ! grep -q "VirtualHost \"jigasi.meet.jitsi\"" $PROSODY_HOST_CONFIG; then
  177. if [ -f $JAAS_HOST_CONFIG ]; then
  178. ln -s $JAAS_HOST_CONFIG $JAAS_HOST_CONFIG_ENABLED
  179. PROSODY_CONFIG_PRESENT="false"
  180. fi
  181. fi
  182. fi
  183. # Make sure the focus@auth user's roster includes the proxy component (this is idempotent)
  184. prosodyctl mod_roster_command subscribe focus.$JVB_HOSTNAME $JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN
  185. if [ ! -f /var/lib/prosody/$JVB_HOSTNAME.crt ]; then
  186. # prosodyctl takes care for the permissions
  187. # echo for using all default values
  188. echo | prosodyctl cert generate $JVB_HOSTNAME
  189. ln -sf /var/lib/prosody/$JVB_HOSTNAME.key /etc/prosody/certs/$JVB_HOSTNAME.key
  190. ln -sf /var/lib/prosody/$JVB_HOSTNAME.crt /etc/prosody/certs/$JVB_HOSTNAME.crt
  191. fi
  192. CERT_ADDED_TO_TRUST="false"
  193. if [ ! -f /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt ]; then
  194. # prosodyctl takes care for the permissions
  195. # echo for using all default values
  196. echo | prosodyctl cert generate $JICOFO_AUTH_DOMAIN
  197. AUTH_KEY_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.key"
  198. AUTH_CRT_FILE="/etc/prosody/certs/$JICOFO_AUTH_DOMAIN.crt"
  199. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.key $AUTH_KEY_FILE
  200. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt $AUTH_CRT_FILE
  201. ln -sf /var/lib/prosody/$JICOFO_AUTH_DOMAIN.crt /usr/local/share/ca-certificates/$JICOFO_AUTH_DOMAIN.crt
  202. # we need to force updating certificates, in some cases java trust
  203. # store not get re-generated with latest changes
  204. update-ca-certificates -f
  205. CERT_ADDED_TO_TRUST="true"
  206. # don't fail on systems with custom config ($PROSODY_HOST_CONFIG is missing)
  207. if [ -f $PROSODY_HOST_CONFIG ]; then
  208. # now let's add the ssl cert for the auth. domain (we use # as a sed delimiter cause filepaths are confused with default / delimiter)
  209. 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
  210. fi
  211. # trigger a restart
  212. PROSODY_CONFIG_PRESENT="false"
  213. fi
  214. if [ "$PROSODY_CONFIG_PRESENT" = "false" ]; then
  215. invoke-rc.d prosody restart || true
  216. # In case we had updated the certificates and restarted prosody, let's restart and the bridge and jicofo if possible
  217. if [ -d /run/systemd/system ] && [ "$CERT_ADDED_TO_TRUST" = "true" ]; then
  218. systemctl restart jitsi-videobridge2.service >/dev/null || true
  219. systemctl restart jicofo.service >/dev/null || true
  220. fi
  221. fi
  222. ;;
  223. abort-upgrade|abort-remove|abort-deconfigure)
  224. ;;
  225. *)
  226. echo "postinst called with unknown argument \`$1'" >&2
  227. exit 1
  228. ;;
  229. esac
  230. # dh_installdeb will replace this with shell code automatically
  231. # generated by other debhelper scripts.
  232. #DEBHELPER#
  233. exit 0