freedombone-app-profanity 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Profanity XMPP client
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  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 full-vim chat'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. LIBMESODE_REPO="https://github.com/boothj5/libmesode"
  34. LIBMESODE_COMMIT='b91872cf7e7ed4d2443ab5c622f4cdb395d64dbe'
  35. PROFANITY_REPO="https://github.com/boothj5/profanity"
  36. PROFANITY_COMMIT='ca1dcdda6cd6114061ff99963e59c76bd92e4603'
  37. PROFANITY_OMEMO_PLUGIN_REPO="https://github.com/ReneVolution/profanity-omemo-plugin"
  38. PROFANITY_OMEMO_PLUGIN_COMMIT='982612f9a16068366434771d8f55bbfc3e8d6822'
  39. xmpp_variables=(ONION_ONLY
  40. INSTALLED_WITHIN_DOCKER
  41. MY_USERNAME
  42. DEFAULT_DOMAIN_NAME
  43. XMPP_DOMAIN_CODE)
  44. function logging_on_profanity {
  45. echo -n ''
  46. }
  47. function logging_off_profanity {
  48. echo -n ''
  49. }
  50. function remove_user_profanity {
  51. remove_username="$1"
  52. }
  53. function add_user_profanity {
  54. new_username="$1"
  55. new_user_password="$2"
  56. echo '0'
  57. }
  58. function run_client_profanity {
  59. torify profanity
  60. }
  61. function install_interactive_profanity {
  62. echo -n ''
  63. APP_INSTALLED=1
  64. }
  65. function change_password_profanity {
  66. curr_username="$1"
  67. new_user_password="$2"
  68. read_config_param DEFAULT_DOMAIN_NAME
  69. ${PROJECT_NAME}-pass -u $curr_username -a xmpp -p "$new_user_password"
  70. # TODO: this is currently interactive. Really there needs to be a
  71. # non-interactive password change option for prosodyctl
  72. clear
  73. echo ''
  74. echo $'Currently Prosody requires password changes to be done interactively'
  75. prosodyctl passwd ${curr_username}@${DEFAULT_DOMAIN_NAME}
  76. XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
  77. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  78. if [ -f $XMPP_CLIENT_ACCOUNTS ]; then
  79. sed -i "s|password=.*|password=$new_user_password|g" $XMPP_CLIENT_ACCOUNTS
  80. fi
  81. }
  82. function reconfigure_profanity {
  83. echo -n ''
  84. }
  85. function upgrade_profanity {
  86. # update profanity client
  87. if [ -f /usr/bin/profanity ]; then
  88. apt-get -y remove --purge profanity
  89. fi
  90. rm -rf /tmp/*
  91. CURR_LIBMESODE_COMMIT=$(cat $COMPLETION_FILE | grep "libmesode commit" | awk -F ':' '{print $2}')
  92. if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
  93. function_check set_repo_commit
  94. set_repo_commit $INSTALL_DIR/libmesode "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
  95. cd $INSTALL_DIR/libmesode
  96. ./bootstrap.sh
  97. ./configure
  98. make
  99. make install
  100. cp /usr/local/lib/libmesode* /usr/lib
  101. fi
  102. rm -rf /tmp/*
  103. CURR_PROFANITY_COMMIT=$(cat $COMPLETION_FILE | grep "profanity commit" | awk -F ':' '{print $2}')
  104. if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
  105. function_check set_repo_commit
  106. set_repo_commit $INSTALL_DIR/profanity "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
  107. cd $INSTALL_DIR/profanity
  108. ./bootstrap.sh
  109. ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
  110. make
  111. make install
  112. fi
  113. CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(cat $COMPLETION_FILE | grep "profanity omemo plugin commit" | awk -F ':' '{print $2}')
  114. if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
  115. # upgrade omemo plugins for all users
  116. set_repo_commit $INSTALL_DIR/profanity-omemo-plugin "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
  117. cd $INSTALL_DIR/profanity-omemo-plugin
  118. sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
  119. pip uninstall -y profanity-omemo-plugin
  120. ./install.sh
  121. for d in /home/*/ ; do
  122. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  123. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  124. if [ ! -d /home/$USERNAME/.local/share/profanity/plugins ]; then
  125. mkdir -p /home/$USERNAME/.local/share/profanity/plugins
  126. fi
  127. if [ -f $INSTALL_DIR/profanity-omemo-plugin/omemo.py ]; then
  128. rm $INSTALL_DIR/profanity-omemo-plugin/omemo.*
  129. fi
  130. cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$USERNAME/.local/share/profanity/plugins
  131. chown -R $USERNAME:$USERNAME /home/$USERNAME/.local
  132. fi
  133. done
  134. if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
  135. rm /etc/skel/.local/share/profanity/plugins/omemo.*
  136. fi
  137. cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
  138. fi
  139. chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
  140. }
  141. function backup_local_profanity {
  142. echo -n ''
  143. }
  144. function restore_local_profanity {
  145. echo -n ''
  146. }
  147. function backup_remote_profanity {
  148. echo -n ''
  149. }
  150. function restore_remote_profanity {
  151. echo -n ''
  152. }
  153. function remove_profanity {
  154. if [ -f /usr/local/bin/profanity ]; then
  155. cd $INSTALL_DIR/profanity
  156. make uninstall
  157. remove_completion_param install_profanity
  158. sed -i '/profanity/d' $COMPLETION_FILE
  159. fi
  160. }
  161. function install_profanity {
  162. # xmpp must already be installed
  163. if [ ! -d /etc/prosody ]; then
  164. return
  165. fi
  166. # install profanity from source in order to get OMEMO support
  167. if [ ! -d $INSTALL_DIR ]; then
  168. mkdir -p $INSTALL_DIR
  169. fi
  170. apt-get -yq install automake autoconf autoconf-archive libtool build-essential
  171. apt-get -yq install libncursesw5-dev libglib2.0-dev libcurl3-dev sqlite3
  172. apt-get -yq install libotr5-dev libgpgme11-dev python-dev libreadline-dev
  173. # dependency for profanity not available in debian
  174. if [ -d /repos/libmesode ]; then
  175. mkdir $INSTALL_DIR/libmesode
  176. cp -r -p /repos/libmesode/. $INSTALL_DIR/libmesode
  177. cd $INSTALL_DIR/libmesode
  178. git pull
  179. else
  180. git_clone $LIBMESODE_REPO $INSTALL_DIR/libmesode
  181. fi
  182. cd $INSTALL_DIR/libmesode
  183. git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
  184. ./bootstrap.sh
  185. ./configure
  186. make
  187. make install
  188. cp /usr/local/lib/libmesode* /usr/lib
  189. # build profanity
  190. if [ -d /repos/profanity ]; then
  191. mkdir $INSTALL_DIR/profanity
  192. cp -r -p /repos/profanity/. $INSTALL_DIR/profanity
  193. cd $INSTALL_DIR/profanity
  194. git pull
  195. else
  196. git_clone $PROFANITY_REPO $INSTALL_DIR/profanity
  197. fi
  198. cd $INSTALL_DIR/profanity
  199. git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
  200. ./bootstrap.sh
  201. ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
  202. make
  203. make install
  204. if [ ! -f /usr/local/bin/profanity ]; then
  205. echo $'Unable to build profanity'
  206. exit 7825272
  207. fi
  208. # install the omemo plugin
  209. apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
  210. if [ -d /repos/profanity-omemo ]; then
  211. mkdir $INSTALL_DIR/profanity-omemo-plugin
  212. cp -r -p /repos/profanity-omemo/. $INSTALL_DIR/profanity-omemo-plugin
  213. cd $INSTALL_DIR/profanity-omemo-plugin
  214. git pull
  215. else
  216. git_clone $PROFANITY_OMEMO_PLUGIN_REPO $INSTALL_DIR/profanity-omemo-plugin
  217. fi
  218. cd $INSTALL_DIR/profanity-omemo-plugin
  219. git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
  220. if [ ! -f $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py ]; then
  221. echo $'prof_omemo_plugin.py not found'
  222. exit 389225
  223. fi
  224. sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
  225. ./install.sh
  226. mkdir -p /etc/skel/.local/share/profanity/plugins
  227. cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
  228. cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$MY_USERNAME/.local/share/profanity/plugins
  229. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  230. XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
  231. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  232. if [ ! -d $XMPP_CLIENT_DIR ]; then
  233. mkdir -p $XMPP_CLIENT_DIR
  234. fi
  235. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  236. MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME")
  237. if [[ $ONION_ONLY == 'no' ]]; then
  238. echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
  239. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  240. echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  241. echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
  242. # There is a bug where profanity doesn't refresh the screen
  243. # after gpg-agent has asked for a password, so for now
  244. # don't set the gpg key by default
  245. #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
  246. echo "pgp.keyid=" >> $XMPP_CLIENT_ACCOUNTS
  247. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  248. echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  249. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  250. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  251. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  252. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  253. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  254. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  255. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  256. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  257. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  258. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  259. fi
  260. fi
  261. if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  262. echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
  263. if [[ $ONION_ONLY == 'no' ]]; then
  264. echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
  265. else
  266. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  267. fi
  268. echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  269. echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
  270. # There is a bug where profanity doesn't refresh the screen
  271. # after gpg-agent has asked for a password, so for now
  272. # don't set the gpg key by default
  273. #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
  274. echo "pgp.keyid=" >> $XMPP_CLIENT_ACCOUNTS
  275. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  276. echo "muc.service=${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  277. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  278. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  279. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  280. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  281. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  282. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  283. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  284. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  285. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  286. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  287. fi
  288. fi
  289. if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
  290. mkdir -p /home/$MY_USERNAME/.config/profanity
  291. fi
  292. echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
  293. if [[ $ONION_ONLY == 'no' ]]; then
  294. echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
  295. else
  296. echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
  297. fi
  298. echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
  299. echo '[plugins]' >> /home/$MY_USERNAME/.config/profanity/profrc
  300. echo 'load=prof_omemo_plugin.py;' >> /home/$MY_USERNAME/.config/profanity/profrc
  301. echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
  302. echo '[otr]' >> /home/$MY_USERNAME/.config/profanity/profrc
  303. echo 'policy=opportunistic' >> /home/$MY_USERNAME/.config/profanity/profrc
  304. echo 'log=off' >> /home/$MY_USERNAME/.config/profanity/profrc
  305. echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
  306. echo '[pgp]' >> /home/$MY_USERNAME/.config/profanity/profrc
  307. echo 'log=off' >> /home/$MY_USERNAME/.config/profanity/profrc
  308. echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
  309. echo '[ui]' >> /home/$MY_USERNAME/.config/profanity/profrc
  310. echo 'enc.warn=true' >> /home/$MY_USERNAME/.config/profanity/profrc
  311. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  312. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  313. chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
  314. APP_INSTALLED=1
  315. }
  316. # NOTE: deliberately no exit 0