freedombone-app-profanity 13KB

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