freedombone-app-profanity 13KB

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