freedombone-app-gnusocial 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # gnusocial application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 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 media'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. GNUSOCIAL_DOMAIN_NAME=
  34. GNUSOCIAL_CODE=
  35. GNUSOCIAL_ONION_PORT=8087
  36. GNUSOCIAL_REPO="https://git.gnu.io/gnu/gnu-social.git"
  37. GNUSOCIAL_COMMIT='c67b89e56bf0f90730a9e22beca7e1bd41fc26c3'
  38. GNUSOCIAL_ADMIN_PASSWORD=
  39. GNUSOCIAL_THEME_REPO="https://git.gnu.io/h2p/Qvitter.git"
  40. GNUSOCIAL_THEME_COMMIT='510b6c5f9ccd89e3693909198aad691492ace081'
  41. GNUSOCIAL_WELCOME_MESSAGE=$'<h1>Welcome to GNU Social – a federated social metwork</h1><p>Another Freedombone site</p>'
  42. GNUSOCIAL_BACKGROUND_IMAGE_URL=
  43. GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
  44. GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
  45. # Sharings plugin for gnusocial
  46. SHARINGS_REPO="http://git.lasindias.club/bashrc/Sharings"
  47. SHARINGS_COMMIT='d5c6c7f855d9afff9086c09ea706f38c859bc0d4'
  48. SHARINGS_THEME_REPO="http://git.lasindias.club/manuel/SharingsTheme"
  49. SHARINGS_THEME_COMMIT='7106c7ef03'
  50. # NSFW plugin
  51. GNUSOCIAL_NSFW_REPO="https://gitgud.io/ShitposterClub/SensitiveContent"
  52. GNUSOCIAL_NSFW_COMMIT='a096bbe0cfae9a9b177682920ffb58d32a48e136'
  53. # script which causes old posts to expire
  54. gnusocial_expire_script=/usr/bin/gnusocial-expire
  55. gnusocial_variables=(GNUSOCIAL_COMMIT
  56. ONION_ONLY
  57. GNUSOCIAL_DOMAIN_NAME
  58. GNUSOCIAL_CODE
  59. GNUSOCIAL_WELCOME_MESSAGE
  60. GNUSOCIAL_BACKGROUND_IMAGE_URL
  61. DDNS_PROVIDER
  62. GNUSOCIAL_MARKDOWN_REPO
  63. GNUSOCIAL_MARKDOWN_COMMIT
  64. SHARINGS_REPO
  65. SHARINGS_COMMIT
  66. SHARINGS_THEME_REPO
  67. SHARINGS_THEME_COMMIT
  68. MY_USERNAME)
  69. function remove_user_gnusocial {
  70. remove_username="$1"
  71. ${PROJECT_NAME}-pass -u $remove_username --rmapp gnusocial
  72. function_check get_completion_param
  73. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  74. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  75. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  76. php scripts/deleteprofile.php -n $remove_username -y
  77. fi
  78. }
  79. function add_user_gnusocial {
  80. new_username="$1"
  81. new_user_password="$2"
  82. ${PROJECT_NAME}-pass -u $new_username -a gnusocial -p "$new_user_password"
  83. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  84. if [ -d /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs ]; then
  85. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  86. php scripts/registeruser.php -n $new_username -w "$new_user_password" -e "$new_username@$HOSTNAME"
  87. ${PROJECT_NAME}-addemail -u $new_username -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  88. echo '0'
  89. else
  90. echo '1'
  91. fi
  92. }
  93. function install_interactive_gnusocial {
  94. if [ ! $ONION_ONLY ]; then
  95. ONION_ONLY='no'
  96. fi
  97. if [[ $ONION_ONLY != "no" ]]; then
  98. GNUSOCIAL_DOMAIN_NAME='gnusocial.local'
  99. else
  100. GNUSOCIAL_DETAILS_COMPLETE=
  101. while [ ! $GNUSOCIAL_DETAILS_COMPLETE ]
  102. do
  103. data=$(tempfile 2>/dev/null)
  104. trap "rm -f $data" 0 1 2 5 15
  105. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  106. dialog --backtitle $"Freedombone Configuration" \
  107. --title $"GNU Social Configuration" \
  108. --form $"\nPlease enter your GNU Social details. Welcome message and background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
  109. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  110. $"Welcome Message:" 2 1 "$(grep '$GNUSOCIAL_WELCOME_MESSAGE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  111. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  112. $"Code:" 4 1 "$(grep 'GNUSOCIAL_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
  113. 2> $data
  114. else
  115. dialog --backtitle $"Freedombone Configuration" \
  116. --title $"GNU Social Configuration" \
  117. --form $"\nPlease enter your GNU Social details. Welcome message and background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
  118. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  119. $"Welcome Message:" 2 1 "$(grep '$GNUSOCIAL_WELCOME_MESSAGE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  120. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  121. 2> $data
  122. fi
  123. sel=$?
  124. case $sel in
  125. 1) exit 1;;
  126. 255) exit 1;;
  127. esac
  128. GNUSOCIAL_DOMAIN_NAME=$(cat $data | sed -n 1p)
  129. welcome_msg=$(cat $data | sed -n 2p)
  130. if [ ${#welcome_msg} -gt 1 ]; then
  131. GNUSOCIAL_WELCOME_MESSAGE=$welcome_msg
  132. fi
  133. img_url=$(cat $data | sed -n 3p)
  134. if [ ${#img_url} -gt 1 ]; then
  135. GNUSOCIAL_BACKGROUND_IMAGE_URL=$img_url
  136. fi
  137. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  138. if [[ $GNUSOCIAL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  139. GNUSOCIAL_DOMAIN_NAME=""
  140. fi
  141. TEST_DOMAIN_NAME=$GNUSOCIAL_DOMAIN_NAME
  142. validate_domain_name
  143. if [[ $TEST_DOMAIN_NAME != $GNUSOCIAL_DOMAIN_NAME ]]; then
  144. GNUSOCIAL_DOMAIN_NAME=
  145. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  146. else
  147. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  148. GNUSOCIAL_CODE=$(cat $data | sed -n 4p)
  149. validate_freedns_code "$GNUSOCIAL_CODE"
  150. if [ ! $VALID_CODE ]; then
  151. GNUSOCIAL_DOMAIN_NAME=
  152. fi
  153. fi
  154. fi
  155. fi
  156. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  157. GNUSOCIAL_DETAILS_COMPLETE="yes"
  158. fi
  159. done
  160. # remove any invalid characters
  161. if [ ${#GNUSOCIAL_WELCOME_MESSAGE} -gt 0 ]; then
  162. new_welcome=$(echo "$GNUSOCIAL_WELCOME_MESSAGE" | sed "s|'||g")
  163. GNUSOCIAL_WELCOME_MESSAGE="$new_welcome"
  164. fi
  165. # save the results in the config file
  166. write_config_param "GNUSOCIAL_CODE" "$GNUSOCIAL_CODE"
  167. write_config_param "GNUSOCIAL_WELCOME_MESSAGE" "$GNUSOCIAL_WELCOME_MESSAGE"
  168. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  169. fi
  170. write_config_param "GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_DOMAIN_NAME"
  171. APP_INSTALLED=1
  172. }
  173. function change_password_gnusocial {
  174. curr_username="$1"
  175. new_user_password="$2"
  176. read_config_param ${GNUSOCIAL_DOMAIN_NAME}
  177. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  178. ./scripts/setpassword "$curr_username" "$new_user_password"
  179. ${PROJECT_NAME}-pass -u "$curr_username" -a gnusocial -p "$new_user_password"
  180. }
  181. function gnusocial_create_database {
  182. if [ -f $IMAGE_PASSWORD_FILE ]; then
  183. GNUSOCIAL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  184. else
  185. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  186. GNUSOCIAL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  187. fi
  188. fi
  189. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  190. return
  191. fi
  192. function_check create_database
  193. create_database gnusocial "$GNUSOCIAL_ADMIN_PASSWORD" $MY_USERNAME
  194. }
  195. function gnusocial_running_script {
  196. # check that the daemon is running
  197. echo '#!/bin/bash' > /etc/cron.hourly/gnusocial-daemons
  198. echo 'daemon_lines=$(ps aux | grep "scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/gnusocial-daemons
  199. echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/gnusocial-daemons
  200. echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/gnusocial-daemons
  201. echo ' MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/gnusocial-daemons
  202. echo ' echo "Restarting GNU Social daemons" | mail -s "GNU Social daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/gnusocial-daemons
  203. echo " cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs" >> /etc/cron.hourly/gnusocial-daemons
  204. echo ' scripts/startdaemons.sh' >> /etc/cron.hourly/gnusocial-daemons
  205. echo 'fi' >> /etc/cron.hourly/gnusocial-daemons
  206. chmod +x /etc/cron.hourly/gnusocial-daemons
  207. }
  208. function reconfigure_gnusocial {
  209. echo -n ''
  210. }
  211. function gnusocial_set_background_image_from_url {
  212. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT=
  213. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  214. if [[ $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".jpeg" || $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".jpg" ]]; then
  215. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="jpg"
  216. fi
  217. if [[ $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".png" ]]; then
  218. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="png"
  219. fi
  220. if [[ $$GNUSOCIAL_BACKGROUND_IMAGE_URL == *".gif" ]]; then
  221. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="gif"
  222. fi
  223. fi
  224. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT ]; then
  225. read_config_param GNUSOCIAL_DOMAIN_NAME
  226. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  227. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter
  228. wget $GNUSOCIAL_BACKGROUND_IMAGE_URL -O img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}
  229. if [ ! -f img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT} ]; then
  230. echo "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  231. echo $'Custom background image for gnusocial could not be downloaded'
  232. echo "1"
  233. return
  234. fi
  235. if grep -q "'img/custom" $gnusocial_config_file; then
  236. sed -i "s|'img/custom.*|'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';|g" $gnusocial_config_file
  237. fi
  238. fi
  239. echo "0"
  240. }
  241. function gnusocial_set_background_image {
  242. data=$(tempfile 2>/dev/null)
  243. trap "rm -f $data" 0 1 2 5 15
  244. dialog --title $"GNU Social" \
  245. --backtitle $"Freedombone Control Panel" \
  246. --inputbox $'Set a login screen background image URL' 10 60 2>$data
  247. sel=$?
  248. case $sel in
  249. 0)
  250. temp_background=$(<$data)
  251. if [ ${#temp_background} -gt 0 ]; then
  252. GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
  253. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  254. if [[ $(gnusocial_set_background_image_from_url) == "0" ]]; then
  255. dialog --title $"Set GNU Social login background" \
  256. --msgbox $"The background image has been set" 6 60
  257. fi
  258. fi
  259. ;;
  260. esac
  261. }
  262. function gnusocial_set_welcome_message {
  263. data=$(tempfile 2>/dev/null)
  264. trap "rm -f $data" 0 1 2 5 15
  265. dialog --title $"GNU Social" \
  266. --backtitle $"Freedombone Control Panel" \
  267. --inputbox $'Set a welcome message, which can include html formatting' 10 60 2>$data
  268. sel=$?
  269. case $sel in
  270. 0)
  271. temp_welcome=$(<$data)
  272. if [ ${#temp_welcome} -gt 0 ]; then
  273. GNUSOCIAL_WELCOME_MESSAGE="$temp_welcome"
  274. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  275. if grep -q "customwelcometext" $gnusocial_config_file; then
  276. write_config_param "GNUSOCIAL_WELCOME_MESSAGE" "$GNUSOCIAL_WELCOME_MESSAGE"
  277. sed -i "s|customwelcometext.*|customwelcometext']['en'] = '${GNUSOCIAL_WELCOME_MESSAGE}';|g" $gnusocial_config_file
  278. dialog --title $"Set GNU Social welcome message" \
  279. --msgbox $"Welcome message has been set" 6 60
  280. fi
  281. fi
  282. ;;
  283. esac
  284. }
  285. function configure_interactive_gnusocial {
  286. while true
  287. do
  288. data=$(tempfile 2>/dev/null)
  289. trap "rm -f $data" 0 1 2 5 15
  290. dialog --backtitle $"Freedombone Control Panel" \
  291. --title $"GNU Social" \
  292. --radiolist $"Choose an operation:" 12 70 3 \
  293. 1 $"Set a login screen background image" off \
  294. 2 $"Set a welcome message" off \
  295. 3 $"Exit" on 2> $data
  296. sel=$?
  297. case $sel in
  298. 1) return;;
  299. 255) return;;
  300. esac
  301. case $(cat $data) in
  302. 1) gnusocial_set_background_image;;
  303. 2) gnusocial_set_welcome_message;;
  304. 3) break;;
  305. esac
  306. done
  307. }
  308. function upgrade_gnusocial {
  309. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  310. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  311. fi
  312. # update to the next commit
  313. function_check set_repo_commit
  314. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs "gnusocial commit" "$GNUSOCIAL_COMMIT" $GNUSOCIAL_REPO
  315. function_check gnusocial_running_script
  316. gnusocial_running_script
  317. }
  318. function backup_local_gnusocial {
  319. GNUSOCIAL_DOMAIN_NAME='gnusocial'
  320. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  321. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  322. fi
  323. source_directory=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  324. if [ -d $source_directory ]; then
  325. dest_directory=gnusocial
  326. function_check suspend_site
  327. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  328. function_check backup_directory_to_usb
  329. backup_directory_to_usb $source_directory $dest_directory
  330. function_check backup_database_to_usb
  331. backup_database_to_usb gnusocial
  332. function_check restart_site
  333. restart_site
  334. fi
  335. }
  336. function restore_local_gnusocial {
  337. if ! grep -q "gnusocial domain" $COMPLETION_FILE; then
  338. return
  339. fi
  340. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  341. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  342. echo $"Restoring gnusocial"
  343. temp_restore_dir=/root/tempgnusocial
  344. gnusocial_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  345. # stop the daemons
  346. cd $gnusocial_dir
  347. scripts/stopdaemons.sh
  348. function_check gnusocial_create_database
  349. gnusocial_create_database
  350. restore_database gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  351. if [ -d $temp_restore_dir ]; then
  352. rm -rf $temp_restore_dir
  353. fi
  354. # start the daemons
  355. cd $gnusocial_dir
  356. scripts/startdaemons.sh
  357. echo $"Restore of gnusocial complete"
  358. fi
  359. }
  360. function backup_remote_gnusocial {
  361. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  362. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  363. temp_backup_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  364. if [ -d $temp_backup_dir ]; then
  365. function_check suspend_site
  366. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  367. function_check backup_database_to_friend
  368. backup_database_to_friend gnusocial
  369. echo $"Backing up GNU social installation"
  370. function_check backup_directory_to_friend
  371. backup_directory_to_friend $temp_backup_dir gnusocial
  372. function_check restart_site
  373. restart_site
  374. else
  375. echo $"gnusocial domain specified but not found in ${temp_backup_dir}"
  376. fi
  377. fi
  378. }
  379. function restore_remote_gnusocial {
  380. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  381. echo $"Restoring gnusocial"
  382. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  383. # stop the daemons
  384. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  385. ./scripts/stopdaemons.sh
  386. function_check gnusocial_create_database
  387. gnusocial_create_database
  388. function_check restore_database_from_friend
  389. restore_database_from_friend gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  390. if [ -d /root/tempgnusocial ]; then
  391. rm -rf /root/tempgnusocial
  392. fi
  393. # start the daemons
  394. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  395. ./scripts/startdaemons.sh
  396. echo $"Restore of gnusocial complete"
  397. fi
  398. }
  399. function remove_gnusocial {
  400. if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
  401. return
  402. fi
  403. read_config_param "GNUSOCIAL_DOMAIN_NAME"
  404. read_config_param "MY_USERNAME"
  405. echo "Removing $GNUSOCIAL_DOMAIN_NAME"
  406. nginx_dissite $GNUSOCIAL_DOMAIN_NAME
  407. remove_certs $GNUSOCIAL_DOMAIN_NAME
  408. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
  409. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts
  410. ./scripts/stopdaemons.sh
  411. fi
  412. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  413. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  414. fi
  415. if [ -f /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME ]; then
  416. rm /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  417. fi
  418. function_check drop_database
  419. drop_database gnusocial
  420. function_check remove_onion_service
  421. remove_onion_service gnusocial ${GNUSOCIAL_ONION_PORT}
  422. if grep -q "gnusocial" /etc/crontab; then
  423. sed -i "/gnusocial/d" /etc/crontab
  424. fi
  425. remove_app gnusocial
  426. remove_completion_param install_gnusocial
  427. sed -i '/gnusocial/d' $COMPLETION_FILE
  428. if [ -f /etc/cron.hourly/gnusocial-daemons ]; then
  429. rm /etc/cron.hourly/gnusocial-daemons
  430. fi
  431. remove_backup_database_local gnusocial
  432. function_check remove_ddns_domain
  433. remove_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  434. }
  435. function install_gnusocial_main {
  436. if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
  437. echo $'No domain name was given for gnusocial'
  438. exit 7359
  439. fi
  440. if [[ $(app_is_installed gnusocial_main) == "1" ]]; then
  441. return
  442. fi
  443. function_check gnusocial_running_script
  444. gnusocial_running_script
  445. function_check install_mariadb
  446. install_mariadb
  447. function_check get_mariadb_password
  448. get_mariadb_password
  449. function_check repair_databases_script
  450. repair_databases_script
  451. apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
  452. apt-get -yq install php5-memcached php5-intl
  453. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  454. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME
  455. fi
  456. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  457. function_check git_clone
  458. git_clone $GNUSOCIAL_REPO /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  459. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  460. echo $'Unable to clone gnusocial repo'
  461. exit 87525
  462. fi
  463. fi
  464. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  465. git checkout $GNUSOCIAL_COMMIT -b $GNUSOCIAL_COMMIT
  466. set_completion_param "gnusocial commit" "$GNUSOCIAL_COMMIT"
  467. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  468. chown www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  469. chmod +x /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  470. function_check gnusocial_create_database
  471. gnusocial_create_database
  472. if [ ! -f "/etc/aliases" ]; then
  473. touch /etc/aliases
  474. fi
  475. if ! grep -q "www-data: root" /etc/aliases; then
  476. echo 'www-data: root' >> /etc/aliases
  477. fi
  478. if ! grep -q "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  479. echo "*: /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  480. fi
  481. function_check add_ddns_domain
  482. add_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  483. gnusocial_nginx_site=/etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  484. if [[ $ONION_ONLY == "no" ]]; then
  485. function_check nginx_http_redirect
  486. nginx_http_redirect $GNUSOCIAL_DOMAIN_NAME
  487. echo 'server {' >> $gnusocial_nginx_site
  488. echo ' listen 443 ssl;' >> $gnusocial_nginx_site
  489. echo ' listen [::]:443 ssl;' >> $gnusocial_nginx_site
  490. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  491. echo '' >> $gnusocial_nginx_site
  492. echo ' # Security' >> $gnusocial_nginx_site
  493. function_check nginx_ssl
  494. nginx_ssl $GNUSOCIAL_DOMAIN_NAME
  495. function_check nginx_disable_sniffing
  496. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  497. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $gnusocial_nginx_site
  498. echo '' >> $gnusocial_nginx_site
  499. echo ' # Logs' >> $gnusocial_nginx_site
  500. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  501. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  502. echo '' >> $gnusocial_nginx_site
  503. echo ' # Root' >> $gnusocial_nginx_site
  504. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  505. echo '' >> $gnusocial_nginx_site
  506. echo ' # Index' >> $gnusocial_nginx_site
  507. echo ' index index.php;' >> $gnusocial_nginx_site
  508. echo '' >> $gnusocial_nginx_site
  509. echo ' # PHP' >> $gnusocial_nginx_site
  510. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  511. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  512. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
  513. echo ' }' >> $gnusocial_nginx_site
  514. echo '' >> $gnusocial_nginx_site
  515. echo ' # Location' >> $gnusocial_nginx_site
  516. echo ' location / {' >> $gnusocial_nginx_site
  517. function_check nginx_limits
  518. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  519. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  520. echo ' }' >> $gnusocial_nginx_site
  521. echo '' >> $gnusocial_nginx_site
  522. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  523. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  524. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  525. echo ' }' >> $gnusocial_nginx_site
  526. echo '' >> $gnusocial_nginx_site
  527. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  528. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  529. echo ' deny all;' >> $gnusocial_nginx_site
  530. echo ' }' >> $gnusocial_nginx_site
  531. echo '' >> $gnusocial_nginx_site
  532. nginx_keybase $GNUSOCIAL_DOMAIN_NAME
  533. echo '}' >> $gnusocial_nginx_site
  534. else
  535. echo -n '' > $gnusocial_nginx_site
  536. fi
  537. echo 'server {' >> $gnusocial_nginx_site
  538. echo " listen 127.0.0.1:$GNUSOCIAL_ONION_PORT default_server;" >> $gnusocial_nginx_site
  539. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  540. echo '' >> $gnusocial_nginx_site
  541. function_check nginx_disable_sniffing
  542. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  543. echo '' >> $gnusocial_nginx_site
  544. echo ' # Logs' >> $gnusocial_nginx_site
  545. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  546. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  547. echo '' >> $gnusocial_nginx_site
  548. echo ' # Root' >> $gnusocial_nginx_site
  549. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  550. echo '' >> $gnusocial_nginx_site
  551. echo ' # Index' >> $gnusocial_nginx_site
  552. echo ' index index.php;' >> $gnusocial_nginx_site
  553. echo '' >> $gnusocial_nginx_site
  554. echo ' # PHP' >> $gnusocial_nginx_site
  555. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  556. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  557. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
  558. echo ' }' >> $gnusocial_nginx_site
  559. echo '' >> $gnusocial_nginx_site
  560. echo ' # Location' >> $gnusocial_nginx_site
  561. echo ' location / {' >> $gnusocial_nginx_site
  562. function_check nginx_limits
  563. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  564. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  565. echo ' }' >> $gnusocial_nginx_site
  566. echo '' >> $gnusocial_nginx_site
  567. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  568. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  569. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  570. echo ' }' >> $gnusocial_nginx_site
  571. echo '' >> $gnusocial_nginx_site
  572. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  573. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  574. echo ' deny all;' >> $gnusocial_nginx_site
  575. echo ' }' >> $gnusocial_nginx_site
  576. echo '' >> $gnusocial_nginx_site
  577. nginx_keybase $GNUSOCIAL_DOMAIN_NAME
  578. echo '}' >> $gnusocial_nginx_site
  579. function_check configure_php
  580. configure_php
  581. function_check create_site_certificate
  582. create_site_certificate $GNUSOCIAL_DOMAIN_NAME 'yes'
  583. # Ensure that the database gets backed up locally, if remote
  584. # backups are not being used
  585. function_check backup_databases_script_header
  586. backup_databases_script_header
  587. function_check backup_database_local
  588. backup_database_local gnusocial
  589. function_check nginx_ensite
  590. nginx_ensite $GNUSOCIAL_DOMAIN_NAME
  591. # NOTE: For the typical case always enable SSL and only
  592. # disable it if in onion only mode. This is due to complexities
  593. # with the way URLs are generated by gnusocial
  594. gnusocial_ssl='always'
  595. if [[ $ONION_ONLY != 'no' ]]; then
  596. gnusocial_ssl='never'
  597. fi
  598. GNUSOCIAL_ONION_HOSTNAME=$(add_onion_service gnusocial 80 ${GNUSOCIAL_ONION_PORT})
  599. GNUSOCIAL_SERVER=${GNUSOCIAL_DOMAIN_NAME}
  600. if [[ $ONION_ONLY != 'no' ]]; then
  601. GNUSOCIAL_SERVER=${GNUSOCIAL_ONION_HOSTNAME}
  602. fi
  603. # Create the configuration
  604. gnusocial_installer=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  605. if [ ! -f $gnusocial_installer ]; then
  606. echo $'No gnusocial commandline installer found'
  607. exit 53026
  608. fi
  609. ${gnusocial_installer} --server "${GNUSOCIAL_SERVER}" \
  610. --host="localhost" --database="gnusocial" \
  611. --dbtype=mysql --username="root" -v \
  612. --password="$MARIADB_PASSWORD" \
  613. --sitename=$"GNU Social" --fancy='yes' \
  614. --admin-nick="$MY_USERNAME" \
  615. --admin-pass="$GNUSOCIAL_ADMIN_PASSWORD" \
  616. --site-profile="community" \
  617. --ssl=${gnusocial_ssl}
  618. # There can be a lot of warnings here so the return value check is disabled
  619. #if [ ! "$?" = "0" ]; then
  620. # # failed to install
  621. # echo $'Could not install GNU Social'
  622. # exit 72357
  623. #fi
  624. # check gnusocial has a config file
  625. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  626. if [ ! -f $gnusocial_config_file ]; then
  627. echo $'Gnusocial config.php not found'
  628. exit 87586
  629. fi
  630. # Some useful settings
  631. if ! grep -q "Recommended GNU social settings" $gnusocial_config_file; then
  632. echo "" >> $gnusocial_config_file
  633. echo "// Recommended GNU social settings" >> $gnusocial_config_file
  634. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $gnusocial_config_file
  635. echo "\$config['profile']['delete'] = true;" >> $gnusocial_config_file
  636. echo "\$config['profile']['changenick'] = true;" >> $gnusocial_config_file
  637. echo "\$config['public']['localonly'] = false;" >> $gnusocial_config_file
  638. echo "addPlugin('StoreRemoteMedia');" >> $gnusocial_config_file
  639. echo "\$config['queue']['enabled'] = true;" >> $gnusocial_config_file
  640. echo "\$config['queue']['daemon'] = true;" >> $gnusocial_config_file
  641. echo "\$config['ostatus']['hub_retries'] = 3;" >> $gnusocial_config_file
  642. fi
  643. # turn off logging
  644. echo "\$config['site']['logfile'] = '/dev/null';" >> $gnusocial_config_file
  645. # This improves performance
  646. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $gnusocial_config_file
  647. systemctl restart php5-fpm
  648. systemctl restart nginx
  649. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  650. ${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
  651. set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"
  652. install_completed gnusocial_main
  653. }
  654. function install_gnusocial_plugin_sharings {
  655. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  656. echo $'No local/plugins directory found for the gnusocial'
  657. exit 72945
  658. fi
  659. apt-get -yq install liblocale-msgfmt-perl gettext
  660. # update to the next commit
  661. function_check set_repo_commit
  662. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
  663. if [[ $(app_is_installed gnusocial_plugin_sharings) == "1" ]]; then
  664. return
  665. fi
  666. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  667. function_check git_clone
  668. git_clone $SHARINGS_REPO Sharings
  669. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
  670. echo $'Unable to clone gnusocial sharings plugin'
  671. exit 36738
  672. fi
  673. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
  674. git stash
  675. git checkout master
  676. git branch -D $SHARINGS_COMMIT
  677. git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
  678. # enable the plugin
  679. if ! grep -q "addPlugin('Sharings');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  680. echo "addPlugin('Sharings');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  681. fi
  682. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  683. php scripts/checkschema.php
  684. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
  685. php scripts/seedsharings.php
  686. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  687. php scripts/checkschema.php
  688. # Languages
  689. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
  690. msgfmt -o Sharings.mo Sharings.po
  691. if [ ! -f Sharings.po ]; then
  692. echo $'English translations for gnusocial sharings plugin were not created'
  693. exit 84352
  694. fi
  695. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
  696. msgfmt -o Sharings.mo Sharings.po
  697. if [ ! -f Sharings.po ]; then
  698. echo $'English (GB) translations for gnusocial sharings plugin were not created'
  699. exit 84352
  700. fi
  701. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
  702. msgfmt -o Sharings.mo Sharings.po
  703. if [ ! -f Sharings.po ]; then
  704. echo $'English (US) translations for gnusocial sharings plugin were not created'
  705. exit 84352
  706. fi
  707. # Looks like this update function isn't supported by the current php version
  708. sed -i 's|ActivityVerb::UPDATE, ||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/SharingsPlugin.php
  709. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  710. set_completion_param gnusocial "sharings plugin commit" "$SHARINGS_COMMIT"
  711. install_completed gnusocial_plugin_sharings
  712. }
  713. function install_gnusocial_plugin_sharings_theme {
  714. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  715. echo $'No local/plugins directory found for the gnusocial'
  716. exit 74458
  717. fi
  718. # update to the next commit
  719. function_check set_repo_commit
  720. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
  721. if [[ $(app_is_installed gnusocial_plugin_sharings_theme) == "1" ]]; then
  722. return
  723. fi
  724. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  725. function_check git_clone
  726. git_clone $SHARINGS_THEME_REPO SharingsTheme
  727. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
  728. echo $'Unable to clone gnusocial sharings plugin theme'
  729. exit 639253
  730. fi
  731. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
  732. git stash
  733. git checkout master
  734. git branch -D $SHARINGS_THEME_COMMIT
  735. git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
  736. # enable the plugin
  737. if ! grep -q "addPlugin('SharingsTheme');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  738. echo "addPlugin('SharingsTheme');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  739. fi
  740. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  741. php scripts/checkschema.php
  742. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  743. set_completion_param "gnusocial sharings plugin theme commit" "$SHARINGS_THEME_COMMIT"
  744. install_completed gnusocial_plugin_sharings_theme
  745. }
  746. function expire_gnusocial_posts {
  747. # To prevent the database size from growing endlessly this script expires posts
  748. # after a number of months
  749. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  750. return
  751. fi
  752. echo '<?php' > $gnusocial_expire_script
  753. echo '' >> $gnusocial_expire_script
  754. echo '// gnusocial post expiry script, based on StatExpire by Tony Baldwin' >> $gnusocial_expire_script
  755. echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
  756. echo '' >> $gnusocial_expire_script
  757. echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $gnusocial_expire_script
  758. echo '$username="root";' >> $gnusocial_expire_script
  759. echo "\$password=trim(file_get_contents(\"$DATABASE_PASSWORD_FILE\"));" >> $gnusocial_expire_script
  760. echo '$database="gnusocial";' >> $gnusocial_expire_script
  761. echo '' >> $gnusocial_expire_script
  762. echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
  763. echo ' echo "Could not connect to mariadb";' >> $gnusocial_expire_script
  764. echo ' exit;' >> $gnusocial_expire_script
  765. echo '}' >> $gnusocial_expire_script
  766. echo '' >> $gnusocial_expire_script
  767. echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
  768. echo ' echo "Could not select gnusocial database";' >> $gnusocial_expire_script
  769. echo ' exit;' >> $gnusocial_expire_script
  770. echo '}' >> $gnusocial_expire_script
  771. echo '' >> $gnusocial_expire_script
  772. echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
  773. echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
  774. echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
  775. echo '' >> $gnusocial_expire_script
  776. echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
  777. echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
  778. echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
  779. echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
  780. echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
  781. echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
  782. echo 'mysql_close();' >> $gnusocial_expire_script
  783. echo '' >> $gnusocial_expire_script
  784. echo 'echo "Expire gnusocial posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
  785. chmod +x $gnusocial_expire_script
  786. # Add a cron job
  787. if ! grep -q "$gnusocial_expire_script" /etc/crontab; then
  788. echo "10 3 5 * * root /usr/bin/timeout 500 /usr/bin/php $gnusocial_expire_script" >> /etc/crontab
  789. fi
  790. # remove old expire script
  791. if [ -f /etc/cron.weekly/clear-gnusocial-database ]; then
  792. rm /etc/cron.weekly/clear-gnusocial-database
  793. fi
  794. }
  795. function install_gnusocial_theme {
  796. # update to the next commit
  797. function_check set_repo_commit
  798. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter "gnusocial theme commit" "$GNUSOCIAL_THEME_COMMIT" $GNUSOCIAL_THEME_REPO
  799. # customise with project logo
  800. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  801. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  802. cp ~/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  803. else
  804. if [ -f /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png ]; then
  805. cp /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  806. fi
  807. fi
  808. fi
  809. if [[ $(app_is_installed gnusocial_theme) == "1" ]]; then
  810. return
  811. fi
  812. apt-get -yq install wget
  813. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  814. mkdir -p /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  815. fi
  816. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  817. function_check git_clone
  818. git_clone $GNUSOCIAL_THEME_REPO Qvitter
  819. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter
  820. git checkout $GNUSOCIAL_THEME_COMMIT -b $GNUSOCIAL_THEME_COMMIT
  821. # download a custom background image
  822. if [[ $(gnusocial_set_background_image_from_url) != "0" ]]; then
  823. exit 356723
  824. fi
  825. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  826. filename=$(basename "$GNUSOCIAL_BACKGROUND_IMAGE_URL")
  827. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="${filename##*.}"
  828. fi
  829. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  830. if ! grep -q "addPlugin('Qvitter')" $gnusocial_config_file; then
  831. GNUSOCIAL_WELCOME_MESSAGE=$(echo $GNUSOCIAL_WELCOME_MESSAGE | sed "s|\$GNUSOCIAL_DOMAIN_NAME|$GNUSOCIAL_DOMAIN_NAME|g")
  832. echo "" >> $gnusocial_config_file
  833. echo "// Qvitter settings" >> $gnusocial_config_file
  834. echo "addPlugin('Qvitter');" >> $gnusocial_config_file
  835. echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $gnusocial_config_file
  836. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $gnusocial_config_file
  837. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $gnusocial_config_file
  838. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $gnusocial_config_file
  839. if [[ $ONION_ONLY != 'no' ]]; then
  840. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $gnusocial_config_file
  841. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $gnusocial_config_file
  842. fi
  843. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  844. echo "\$config['site']['qvitter']['sitebackground'] = 'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';" >> $gnusocial_config_file
  845. else
  846. echo "\$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg';" >> $gnusocial_config_file
  847. fi
  848. echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $gnusocial_config_file
  849. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $gnusocial_config_file
  850. echo "\$config['site']['qvitter']['enablewelcometext'] = true;" >> $gnusocial_config_file
  851. echo "\$config['site']['qvitter']['customwelcometext']['en'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  852. echo "\$config['site']['qvitter']['customwelcometext']['de'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  853. echo "\$config['site']['qvitter']['customwelcometext']['fr'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  854. echo "\$config['site']['qvitter']['customwelcometext']['es'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  855. echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $gnusocial_config_file
  856. else
  857. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT ]; then
  858. if [ -f img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT} ]; then
  859. sed -i "s|\$config['site']['qvitter']['sitebackground'].*|\$config['site']['qvitter']['sitebackground'] = 'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';|g" $gnusocial_config_file
  860. fi
  861. fi
  862. fi
  863. # customise with project logo
  864. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  865. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  866. cp ~/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  867. fi
  868. fi
  869. set_completion_param "gnusocial theme commit" "$GNUSOCIAL_THEME_COMMIT"
  870. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  871. install_completed gnusocial_theme
  872. }
  873. function install_gnusocial_markdown {
  874. GNUSOCIAL_PATH=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  875. # update to the next commit
  876. function_check set_repo_commit
  877. set_repo_commit $GNUSOCIAL_PATH/local/plugins/Markdown "gnusocial Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" $GNUSOCIAL_MARKDOWN_REPO
  878. if [[ $(app_is_installed gnusocial_markdown) == "1" ]]; then
  879. return
  880. fi
  881. if [ -d $GNUSOCIAL_PATH/local/plugins/Markdown ]; then
  882. rm -rf $GNUSOCIAL_PATH/local/plugins/Markdown
  883. fi
  884. if [ ! -d $GNUSOCIAL_PATH/local/plugins ]; then
  885. mkdir -p $GNUSOCIAL_PATH/local/plugins
  886. fi
  887. cd $GNUSOCIAL_PATH/local/plugins
  888. function_check git_clone
  889. git_clone $GNUSOCIAL_MARKDOWN_REPO Markdown
  890. cd $GNUSOCIAL_PATH/local/plugins/Markdown
  891. git checkout $GNUSOCIAL_MARKDOWN_COMMIT -b $GNUSOCIAL_MARKDOWN_COMMIT
  892. gnusocial_config_file=$GNUSOCIAL_PATH/config.php
  893. if ! grep -q "addPlugin('Markdown'" $gnusocial_config_file; then
  894. echo "" >> $gnusocial_config_file
  895. echo "// Markdown settings" >> $gnusocial_config_file
  896. echo "addPlugin('Markdown');" >> $gnusocial_config_file
  897. fi
  898. set_completion_param "gnusocial markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT"
  899. chown -R www-data:www-data $GNUSOCIAL_PATH
  900. install_completed gnusocial_markdown
  901. }
  902. function install_gnusocial_plugin_nsfw {
  903. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  904. echo $'No local/plugins directory found for the gnusocial'
  905. exit 37252
  906. fi
  907. # update to the next commit
  908. function_check set_repo_commit
  909. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT" $GNUSOCIAL_NSFW_REPO
  910. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  911. return
  912. fi
  913. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  914. function_check git_clone
  915. git_clone $GNUSOCIAL_NSFW_REPO SensitiveContent
  916. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent ]; then
  917. echo $'Unable to clone gnusocial NSFW plugin'
  918. exit 36738
  919. fi
  920. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent
  921. git stash
  922. git checkout master
  923. git branch -D $GNUSOCIAL_NSFW_COMMIT
  924. git checkout $GNUSOCIAL_NSFW_COMMIT -b $GNUSOCIAL_NSFW_COMMIT
  925. # enable the plugin
  926. if ! grep -q "addPlugin('SensitiveContent');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  927. echo "addPlugin('SensitiveContent');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  928. fi
  929. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  930. php scripts/checkschema.php
  931. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  932. set_completion_param "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT"
  933. install_completed gnusocial_plugin_nsfw
  934. }
  935. function install_gnusocial {
  936. if [ ! $ONION_ONLY ]; then
  937. ONION_ONLY='no'
  938. fi
  939. install_gnusocial_main
  940. expire_gnusocial_posts
  941. install_gnusocial_theme
  942. install_gnusocial_markdown
  943. install_gnusocial_plugin_sharings
  944. install_gnusocial_plugin_sharings_theme
  945. install_gnusocial_plugin_nsfw
  946. # unleash the daemons!
  947. /etc/cron.hourly/gnusocial-daemons
  948. APP_INSTALLED=1
  949. }
  950. # NOTE: deliberately there is no "exit 0"