freedombone-app-xmpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # XMPP functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS='full chat'
  31. # Directory where XMPP settings are stored
  32. XMPP_DIRECTORY="/var/lib/prosody"
  33. XMPP_PASSWORD=
  34. XMPP_CIPHERS='"EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA"'
  35. XMPP_ECC_CURVE='"secp384r1"'
  36. function reconfigure_xmpp {
  37. echo -n ''
  38. }
  39. function update_prosody_modules {
  40. if [ ! -d $INSTALL_DIR/prosody-modules ]; then
  41. return
  42. fi
  43. if [ ! -d /usr/lib/prosody ]; then
  44. return
  45. fi
  46. cd $INSTALL_DIR/prosody-modules
  47. hg pull
  48. hg update
  49. # support onion addresses
  50. if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
  51. cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
  52. fi
  53. # XEP-0313 message archive management
  54. # https://modules.prosody.im/mod_mam.html
  55. # Allows you to download your previous messages onto a new client
  56. # This only applies if you are not using forward secret crypto
  57. # such as OTR or OMEMO (eg. OpenPGP)
  58. if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
  59. cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
  60. fi
  61. # XEP-0352 Client State Indication
  62. # Notifies the server if the app is in the background or not
  63. if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
  64. cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
  65. fi
  66. # XEP-0280 Message Carbons
  67. # Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
  68. if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
  69. cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
  70. fi
  71. # XEP-0198 Stream management
  72. # Helps mobile apps recover when a device switches networks.
  73. if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
  74. cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
  75. fi
  76. if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
  77. cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
  78. fi
  79. # XEP-0191: blocking
  80. if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
  81. cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
  82. fi
  83. # XEP-0016 Privacy lists
  84. if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
  85. cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
  86. fi
  87. }
  88. function upgrade_xmpp {
  89. if ! grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
  90. return
  91. fi
  92. function_check update_prosody_modules
  93. update_prosody_modules
  94. }
  95. function backup_local_xmpp {
  96. source_directory=/var/lib/prosody xmpp
  97. if [ -d $source_directory ]; then
  98. dest_directory=xmpp
  99. echo $"Backing up $source_directory to $dest_directory"
  100. function_check backup_directory_to_usb
  101. backup_directory_to_usb $source_directory $dest_directory
  102. echo $"Backup to $dest_directory complete"
  103. fi
  104. }
  105. function restore_local_xmpp {
  106. if [ -d /var/lib/prosody ]; then
  107. echo $"Restoring XMPP settings"
  108. temp_restore_dir=/root/tempxmpp
  109. function_check restore_directory_from_usb
  110. restore_directory_from_usb $temp_restore_dir xmpp
  111. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  112. if [ ! "$?" = "0" ]; then
  113. function_check set_user_permissions
  114. set_user_permissions
  115. function_check backup_unmount_drive
  116. backup_unmount_drive
  117. exit 725
  118. fi
  119. rm -rf $temp_restore_dir
  120. service prosody restart
  121. chown -R prosody:prosody /var/lib/prosody/*
  122. echo $"Restore of XMPP settings complete"
  123. fi
  124. }
  125. function backup_remote_xmpp {
  126. if [ -d /var/lib/prosody ]; then
  127. echo $"Backing up the XMPP settings"
  128. backup_directory_to_friend /var/lib/prosody xmpp
  129. echo $"Backup of XMPP settings complete"
  130. fi
  131. }
  132. function restore_remote_xmpp {
  133. if [ -d /var/lib/prosody ]; then
  134. echo $"Restoring XMPP settings"
  135. temp_restore_dir=/root/tempxmpp
  136. function_check restore_directory_from_friend
  137. restore_directory_from_friend $temp_restore_dir xmpp
  138. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  139. if [ ! "$?" = "0" ]; then
  140. exit 725
  141. fi
  142. rm -rf $temp_restore_dir
  143. service prosody restart
  144. chown -R prosody:prosody /var/lib/prosody/*
  145. echo $"Restore of XMPP settings complete"
  146. fi
  147. }
  148. function configure_firewall_for_xmpp {
  149. if [ ! -d /etc/prosody ]; then
  150. return
  151. fi
  152. if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
  153. return
  154. fi
  155. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  156. # docker does its own firewalling
  157. return
  158. fi
  159. if [[ $ONION_ONLY != "no" ]]; then
  160. return
  161. fi
  162. iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
  163. iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
  164. iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
  165. function_check save_firewall_settings
  166. save_firewall_settings
  167. OPEN_PORTS+=('XMPP 5222-5223')
  168. OPEN_PORTS+=('XMPP 5269')
  169. OPEN_PORTS+=('XMPP 5280-5281')
  170. echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
  171. }
  172. function remove_xmpp_client {
  173. if ! grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
  174. return
  175. fi
  176. apt-get -y remove --purge profanity
  177. sed '/install_xmpp_client/d' $COMPLETION_FILE
  178. }
  179. function remove_xmpp {
  180. remove_xmpp_client
  181. if ! grep -Fxq "install_xmpp" $COMPLETION_FILE; then
  182. return
  183. fi
  184. iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
  185. iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
  186. iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
  187. function_check save_firewall_settings
  188. save_firewall_settings
  189. function_check remove_onion_service
  190. remove_onion_service xmpp 5222 5223 5269
  191. apt-get -y remove --purge prosody prosody-modules
  192. if [ -d $INSTALL_DIR/prosody-modules ]; then
  193. rm -rf $INSTALL_DIR/prosody-modules
  194. fi
  195. if [ -d /etc/prosody ]; then
  196. rm -rf /etc/prosody
  197. fi
  198. sed '/install_xmpp/d' $COMPLETION_FILE
  199. sed '/XMPP /d' $COMPLETION_FILE
  200. }
  201. function install_xmpp_main {
  202. update_prosody_modules
  203. if grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
  204. return
  205. fi
  206. apt-get -y install lua-sec lua-bitop
  207. apt-get -y install prosody prosody-modules mercurial
  208. if [ ! -d /etc/prosody ]; then
  209. echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
  210. exit 52
  211. fi
  212. # obtain the prosody modules
  213. cd $INSTALL_DIR
  214. hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
  215. if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
  216. echo $'mod_onions prosody module could not be found'
  217. exit 73254
  218. fi
  219. # install the onions module
  220. update_prosody_modules
  221. if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
  222. echo $'mod_onions.lua could not be copied to the prosody modules directory'
  223. exit 63952
  224. fi
  225. # create a certificate
  226. if [ ! -f /etc/ssl/certs/xmpp.dhparam ]; then
  227. ${PROJECT_NAME}-addcert -h xmpp --dhkey $DH_KEYLENGTH
  228. check_certificates xmpp
  229. fi
  230. chown prosody:prosody /etc/ssl/private/xmpp.key
  231. chown prosody:prosody /etc/ssl/certs/xmpp.*
  232. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  233. sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  234. sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  235. if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  236. sed -i '/certificate =/a\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
  237. fi
  238. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  239. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
  240. fi
  241. if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  242. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
  243. fi
  244. if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  245. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
  246. fi
  247. if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  248. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
  249. fi
  250. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
  251. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
  252. if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  253. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  254. echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  255. echo ' "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  256. echo ' "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  257. echo ' "saslauth"; -- Enable mod_saslauth' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  258. echo ' "onions"; -- Enable chat via onion service' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  259. echo ' "mam"; -- Message archive management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  260. echo ' "csi"; -- Client state indication' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  261. echo ' "carbons"; -- Message carbons' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  262. echo ' "smacks"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  263. echo ' "smacks_offline"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  264. echo ' "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  265. echo ' "privacy"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  266. echo ' "privacy_lists"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  267. echo ' "blocking"; -- Blocking command' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  268. echo ' "roster"; -- Roster versioning' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  269. echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  270. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  271. echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  272. echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  273. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  274. fi
  275. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  276. sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
  277. sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
  278. if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
  279. sed -i '/certificate =/a\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
  280. fi
  281. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
  282. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
  283. fi
  284. if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
  285. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
  286. fi
  287. if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
  288. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/prosody.cfg.lua
  289. fi
  290. if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
  291. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
  292. fi
  293. sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
  294. if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
  295. sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
  296. fi
  297. if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
  298. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  299. fi
  300. sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
  301. sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
  302. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
  303. sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/ssl/private/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
  304. sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/ssl/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
  305. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
  306. systemctl restart prosody
  307. touch /home/$MY_USERNAME/README
  308. if [ ! -d /var/lib/tor ]; then
  309. echo $'No Tor installation found. XMPP onion site cannot be configured.'
  310. exit 877367
  311. fi
  312. if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
  313. echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
  314. echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
  315. echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
  316. echo $'Added onion site for XMPP chat'
  317. fi
  318. systemctl restart tor
  319. wait_for_onion_service 'xmpp'
  320. if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  321. echo $'XMPP onion site hostname not found'
  322. exit 65349
  323. fi
  324. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  325. if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  326. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  327. echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
  328. echo ' modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  329. fi
  330. if ! grep -q "XMPP onion domain" $COMPLETION_FILE; then
  331. echo "XMPP onion domain:${XMPP_ONION_HOSTNAME}" >> $COMPLETION_FILE
  332. else
  333. sed -i "s|XMPP onion domain.*|XMPP onion domain:${XMPP_ONION_HOSTNAME}|g" $COMPLETION_FILE
  334. fi
  335. if ! grep -q "Your XMPP password is" /home/$MY_USERNAME/README; then
  336. if [ ${#XMPP_PASSWORD} -lt 8 ]; then
  337. if [ -f $IMAGE_PASSWORD_FILE ]; then
  338. XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  339. else
  340. XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  341. fi
  342. fi
  343. prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME $XMPP_PASSWORD
  344. echo '' >> /home/$MY_USERNAME/README
  345. echo '' >> /home/$MY_USERNAME/README
  346. echo $'XMPP' >> /home/$MY_USERNAME/README
  347. echo '====' >> /home/$MY_USERNAME/README
  348. echo $"XMPP onion domain: ${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  349. echo $"Your XMPP password is: $XMPP_PASSWORD" >> /home/$MY_USERNAME/README
  350. echo $'You can change it with: ' >> /home/$MY_USERNAME/README
  351. echo '' >> /home/$MY_USERNAME/README
  352. echo " prosodyctl passwd $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/README
  353. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  354. chmod 600 /home/$MY_USERNAME/README
  355. fi
  356. function_check configure_firewall_for_xmpp
  357. configure_firewall_for_xmpp
  358. echo 'install_xmpp_main' >> $COMPLETION_FILE
  359. }
  360. function install_xmpp_client {
  361. if grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
  362. return
  363. fi
  364. apt-get -y install profanity
  365. XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
  366. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  367. if [ ! -d $XMPP_CLIENT_DIR ]; then
  368. mkdir -p $XMPP_CLIENT_DIR
  369. fi
  370. if [[ $ONION_ONLY == 'no' ]]; then
  371. echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
  372. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  373. echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  374. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  375. echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  376. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  377. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  378. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  379. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  380. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  381. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  382. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  383. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  384. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  385. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  386. fi
  387. fi
  388. if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  389. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  390. echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
  391. if [[ $ONION_ONLY == 'no' ]]; then
  392. echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
  393. else
  394. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  395. fi
  396. echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  397. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  398. echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  399. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  400. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  401. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  402. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  403. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  404. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  405. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  406. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  407. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  408. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  409. fi
  410. fi
  411. if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
  412. mkdir /home/$MY_USERNAME/.config/profanity
  413. fi
  414. echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
  415. echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
  416. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  417. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  418. echo 'install_xmpp_client' >> $COMPLETION_FILE
  419. }
  420. function install_xmpp {
  421. if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
  422. return
  423. fi
  424. install_xmpp_main
  425. install_xmpp_client
  426. echo 'install_xmpp' >> $COMPLETION_FILE
  427. }
  428. # NOTE: deliberately no exit 0