freedombone-app-profanity 13KB

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