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

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