freedombone-app-mediagoblin 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Mediagoblin application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016-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 media'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. MEDIAGOBLIN_DOMAIN_NAME=
  34. MEDIAGOBLIN_ADMIN_PASSWORD=
  35. MEDIAGOBLIN_CODE=
  36. MEDIAGOBLIN_ONION_PORT=8108
  37. MEDIAGOBLIN_REPO="http://git.savannah.gnu.org/r/mediagoblin.git"
  38. MEDIAGOBLIN_COMMIT='c4d3293dfa4076719e60fe9e052add07426f9a9a'
  39. MEDIAGOBLIN_BASE_DIR=/var/www/mediagoblin.local/htdocs
  40. MEDIAGOBLIN_PORT=6543
  41. mediagoblin_variables=(ONION_ONLY
  42. MY_USERNAME
  43. MEDIAGOBLIN_DOMAIN_NAME
  44. MEDIAGOBLIN_CODE
  45. DEFAULT_DOMAIN_NAME
  46. DDNS_PROVIDER)
  47. function logging_on_mediagoblin {
  48. echo -n ''
  49. }
  50. function logging_off_mediagoblin {
  51. echo -n ''
  52. }
  53. function mediagoblin_fix_email {
  54. # This is a crude hack and there may be a better solution
  55. # The cause of verification problems might be that the mediagoblin user
  56. # does not have mail access
  57. read_config_param 'MEDIAGOBLIN_DOMAIN_NAME'
  58. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  59. mgfile=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/tools/mail.py
  60. if [ ! -f $mgfile ]; then
  61. echo $'Unable to fix email sending'
  62. exit 792532
  63. fi
  64. if ! grep -q 'import os' $mgfile; then
  65. sed -i '/import sys/a import os' $mgfile
  66. fi
  67. sed -i "s|return mhost.sendmail(from_addr, to_addrs, message.as_string())|return os.system(\"echo '\" + message_body + \"' \| mail -s '\" + message['Subject'] + \"' \" + message['To'])|g" $mgfile
  68. }
  69. function install_interactive_mediagoblin {
  70. if [[ $ONION_ONLY != "no" ]]; then
  71. MEDIAGOBLIN_DOMAIN_NAME='mediagoblin.local'
  72. write_config_param "MEDIAGOBLIN_DOMAIN_NAME" "$MEDIAGOBLIN_DOMAIN_NAME"
  73. else
  74. function_check interactive_site_details
  75. interactive_site_details "mediagoblin" "MEDIAGOBLIN_DOMAIN_NAME" "MEDIAGOBLIN_CODE"
  76. fi
  77. APP_INSTALLED=1
  78. }
  79. function configure_interactive_mediagoblin {
  80. read_config_param 'MEDIAGOBLIN_DOMAIN_NAME'
  81. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  82. dialog --title $"Mediagoblin" \
  83. --backtitle $"Freedombone Control Panel" \
  84. --defaultno \
  85. --yesno $"\nAllow registration of new users?" 10 60
  86. sel=$?
  87. case $sel in
  88. 0)
  89. sed -i 's|allow_registration.*|allow_registration = true|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
  90. sed -i 's|allow_registration.*|allow_registration = true|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  91. ;;
  92. 1)
  93. sed -i 's|allow_registration.*|allow_registration = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
  94. sed -i 's|allow_registration.*|allow_registration = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  95. ;;
  96. 255) return;;
  97. esac
  98. systemctl restart mediagoblin
  99. }
  100. function change_password_mediagoblin {
  101. curr_username="$1"
  102. new_user_password="$2"
  103. }
  104. function add_user_mediagoblin {
  105. new_username="$1"
  106. new_user_password="$2"
  107. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  108. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $new_username --password $new_username $new_user_password" - mediagoblin
  109. echo "0"
  110. }
  111. function remove_user_mediagoblin {
  112. remove_username="$1"
  113. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  114. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg deleteuser --username $new_username" - mediagoblin
  115. echo "0"
  116. }
  117. function reconfigure_mediagoblin {
  118. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  119. rm -f /var/lib/mediagoblin/*.db
  120. rm -rf /var/lib/mediagoblin/media/*
  121. rm -f $MEDIAGOBLIN_BASE_DIR/user_dev
  122. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ln -s /var/lib/mediagoblin user_dev" - mediagoblin
  123. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && ./bin/gmg dbupdate" - mediagoblin
  124. }
  125. function upgrade_mediagoblin {
  126. CURR_MEDIAGOBLIN_COMMIT=$(cat $COMPLETION_FILE | grep "mediagoblin commit" | awk -F ':' '{print $2}')
  127. if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
  128. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  129. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
  130. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT" - mediagoblin
  131. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule sync" - mediagoblin
  132. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule update --force --init --recursive" - mediagoblin
  133. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./bootstrap.sh" - mediagoblin
  134. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./configure" - mediagoblin
  135. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && make" - mediagoblin
  136. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate" - mediagoblin
  137. mediagoblin_fix_email
  138. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && ./bin/gmg dbupdate" - mediagoblin
  139. set_completion_param "mediagoblin commit" "$MEDIAGOBLIN_COMMIT"
  140. fi
  141. echo "0"
  142. }
  143. function backup_local_mediagoblin {
  144. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  145. source_directory=/var/lib/mediagoblin
  146. if [ -d $source_directory ]; then
  147. dest_directory=mediagoblin
  148. function_check backup_directory_to_usb
  149. backup_directory_to_usb $MEDIAGOBLIN_BASE_DIR $dest_directory
  150. backup_directory_to_usb /var/lib/mediagoblin mediagoblindata
  151. fi
  152. }
  153. function restore_local_mediagoblin {
  154. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  155. if [ -d /var/lib/mediagoblin ]; then
  156. echo $"Restoring Mediagoblin installation"
  157. function_check get_completion_param
  158. MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
  159. temp_restore_dir=/root/tempmediagoblin
  160. function_check restore_directory_from_usb
  161. restore_directory_from_usb ${temp_restore_dir} mediagoblin
  162. cp -r ${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR/* $MEDIAGOBLIN_BASE_DIR/
  163. if [ ! "$?" = "0" ]; then
  164. function_check restore_directory_from_usb
  165. set_user_permissions
  166. function_check backup_unmount_drive
  167. backup_unmount_drive
  168. exit 45327
  169. fi
  170. restore_directory_from_usb ${temp_restore_dir}2 mediagoblindata
  171. cp -r ${temp_restore_dir}2/var/lib/mediagoblin/* /var/lib/mediagoblin/
  172. if [ ! "$?" = "0" ]; then
  173. function_check set_user_permissions
  174. set_user_permissions
  175. function_check backup_unmount_drive
  176. backup_unmount_drive
  177. exit 24529
  178. fi
  179. rm -rf ${temp_restore_dir}
  180. rm -rf ${temp_restore_dir}2
  181. chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
  182. chown -hR mediagoblin:www-data /var/lib/mediagoblin
  183. chmod -R g+wx /var/lib/mediagoblin
  184. fi
  185. }
  186. function backup_remote_mediagoblin {
  187. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  188. if [ -d /etc/mediagoblin ]; then
  189. echo $"Backing up mediagoblin"
  190. backup_directory_to_friend $MEDIAGOBLIN_BASE_DIR mediagoblin
  191. backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
  192. fi
  193. }
  194. function restore_remote_mediagoblin {
  195. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  196. if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
  197. function_check get_completion_param
  198. MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
  199. function_check restore_directory_from_friend
  200. restore_directory_from_friend /root/tempmediagoblin mediagoblin
  201. cp -r /root/tempmediagoblin/var/lib/mediagoblin/* /var/lib/mediagoblin/
  202. if [ ! "$?" = "0" ]; then
  203. exit 264824
  204. fi
  205. restore_directory_from_friend /root/tempmediagoblin2 mediagoblindata
  206. cp -r /root/tempmediagoblin/var/lib/mediagoblin/* /var/lib/mediagoblin/
  207. if [ ! "$?" = "0" ]; then
  208. exit 268492
  209. fi
  210. rm -rf /root/tempmediagoblin
  211. rm -rf /root/tempmediagoblin2
  212. chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
  213. chown -hR mediagoblin:www-data /var/lib/mediagoblin
  214. chmod -R g+wx /var/lib/mediagoblin
  215. fi
  216. }
  217. function remove_mediagoblin {
  218. if [ ${#MEDIAGOBLIN_DOMAIN_NAME} -eq 0 ]; then
  219. return
  220. fi
  221. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  222. systemctl stop mediagoblin
  223. systemctl disable mediagoblin
  224. rm /etc/systemd/system/mediagoblin.service
  225. systemctl daemon-reload
  226. function_check remove_onion_service
  227. remove_onion_service mediagoblin ${MEDIAGOBLIN_ONION_PORT}
  228. nginx_dissite $MEDIAGOBLIN_DOMAIN_NAME
  229. remove_certs $MEDIAGOBLIN_DOMAIN_NAME
  230. if [ -d /var/lib/mediagoblin ]; then
  231. rm -rf /var/lib/mediagoblin
  232. fi
  233. if [ -d $MEDIAGOBLIN_BASE_DIR ]; then
  234. rm -rf $MEDIAGOBLIN_BASE_DIR
  235. fi
  236. remove_completion_param "install_mediagoblin"
  237. remove_completion_param "mediagoblin domain"
  238. sed -i '/mediagoblin/d' $COMPLETION_FILE
  239. remove_nodejs mediagoblin
  240. groupdel -f mediagoblin
  241. userdel -r mediagoblin
  242. function_check remove_ddns_domain
  243. remove_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
  244. }
  245. function install_mediagoblin {
  246. if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
  247. return
  248. fi
  249. MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  250. function_check install_nodejs
  251. install_nodejs mediagoblin
  252. apt-get install -yq python python-dev python-lxml python-imaging python-virtualenv
  253. apt-get install -yq automake perl sqlite python-paste python-pastedeploy python-pastescript
  254. apt-get install -yq python3 python3-dev libpython3-dev python3-lxml python3-pil
  255. groupadd mediagoblin
  256. useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
  257. usermod --append -G mediagoblin mediagoblin
  258. mkdir -p /var/lib/mediagoblin
  259. mkdir -p $MEDIAGOBLIN_BASE_DIR
  260. chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
  261. chown -hR mediagoblin:www-data /var/lib/mediagoblin
  262. chmod -R g+wx /var/lib/mediagoblin
  263. if [ -d /repos/mediagoblin ]; then
  264. mkdir -p $MEDIAGOBLIN_BASE_DIR/mediagoblin
  265. cp -r -p /repos/mediagoblin/. $MEDIAGOBLIN_BASE_DIR/mediagoblin
  266. cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
  267. git pull
  268. chown -R mediagoblin:mediagoblin $MEDIAGOBLIN_BASE_DIR/mediagoblin
  269. else
  270. su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
  271. fi
  272. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT" - mediagoblin
  273. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule sync" - mediagoblin
  274. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule update --force --init --recursive" - mediagoblin
  275. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./bootstrap.sh" - mediagoblin
  276. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./configure" - mediagoblin
  277. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && make" - mediagoblin
  278. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
  279. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ln -s /var/lib/mediagoblin user_dev" - mediagoblin
  280. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bash -c 'cp -av mediagoblin.ini mediagoblin_local.ini && cp -av paste.ini paste_local.ini'" - mediagoblin
  281. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && perl -pi -e 's|.*sql_engine = .*|sql_engine = sqlite:////var/lib/mediagoblin/mediagoblin.db|' mediagoblin_local.ini" - mediagoblin
  282. # Video plugin
  283. apt-get install -yq python-gi python3-gi \
  284. gstreamer1.0-tools \
  285. gir1.2-gstreamer-1.0 \
  286. gir1.2-gst-plugins-base-1.0 \
  287. gstreamer1.0-plugins-good \
  288. gstreamer1.0-plugins-bad \
  289. gstreamer1.0-plugins-ugly \
  290. gstreamer1.0-libav \
  291. python-gst-1.0 python3-gst-1.0
  292. cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
  293. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
  294. # Audio plugin
  295. apt-get install -yq python-gst-1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-libav libsndfile1-dev libasound2-dev libgstreamer-plugins-base1.0-dev python-numpy python-scipy
  296. apt-get -yq install libasound2-dev python3-numpy python3-scipy libsndfile-dev
  297. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
  298. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/pip install scikits.audiolab" - mediagoblin
  299. if [ -f $IMAGE_PASSWORD_FILE ]; then
  300. MEDIAGOBLIN_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  301. else
  302. if [ ! $MEDIAGOBLIN_ADMIN_PASSWORD ]; then
  303. MEDIAGOBLIN_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  304. fi
  305. fi
  306. ${PROJECT_NAME}-pass -u $MY_USERNAME -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
  307. MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
  308. set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
  309. set_completion_param "mediagoblin onion domain" "$MEDIAGOBLIN_ONION_HOSTNAME"
  310. set_completion_param "mediagoblin commit" "$MEDIAGOBLIN_COMMIT"
  311. if [[ $ONION_ONLY == "no" ]]; then
  312. function_check nginx_http_redirect
  313. nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
  314. echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  315. echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  316. echo ' listen [::]:443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  317. echo ' include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  318. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  319. echo ' autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  320. echo ' default_type application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  321. echo ' sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  322. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  323. function_check nginx_ssl
  324. nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
  325. function_check nginx_disable_sniffing
  326. nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
  327. function_check nginx_limits
  328. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
  329. nginx_keybase $MEDIAGOBLIN_DOMAIN_NAME
  330. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  331. echo ' client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  332. echo ' client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  333. echo ' send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  334. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  335. echo ' fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  336. echo ' fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  337. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  338. echo ' gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  339. echo ' gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  340. echo ' gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  341. echo ' gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  342. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  343. echo " server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  344. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  345. echo ' error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  346. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  347. echo ' location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  348. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  349. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  350. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  351. echo ' location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  352. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  353. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  354. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  355. echo ' location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  356. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  357. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  358. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  359. echo ' location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  360. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  361. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  362. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  363. echo ' location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  364. echo " fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  365. echo ' include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  366. echo ' fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  367. echo ' fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  368. echo ' fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  369. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  370. echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  371. else
  372. echo -n '' > /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  373. fi
  374. echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  375. echo " listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  376. echo ' include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  377. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  378. echo ' autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  379. echo ' default_type application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  380. echo ' sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  381. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  382. function_check nginx_disable_sniffing
  383. nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
  384. function_check nginx_limits
  385. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
  386. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  387. echo ' client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  388. echo ' client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  389. echo ' send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  390. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  391. echo ' fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  392. echo ' fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  393. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  394. echo ' gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  395. echo ' gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  396. echo ' gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  397. echo ' gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  398. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  399. echo " server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  400. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  401. echo ' error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  402. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  403. echo ' location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  404. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  405. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  406. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  407. echo ' location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  408. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  409. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  410. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  411. echo ' location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  412. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  413. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  414. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  415. echo ' location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  416. echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  417. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  418. echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  419. echo ' location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  420. echo " fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  421. echo ' include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  422. echo ' fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  423. echo ' fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  424. echo ' fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  425. echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  426. echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  427. echo '[Unit]' > /etc/systemd/system/mediagoblin.service
  428. echo 'Description=Media service' >> /etc/systemd/system/mediagoblin.service
  429. echo 'Requires=network.target' >> /etc/systemd/system/mediagoblin.service
  430. echo 'After=network.target' >> /etc/systemd/system/mediagoblin.service
  431. echo '' >> /etc/systemd/system/mediagoblin.service
  432. echo '[Service]' >> /etc/systemd/system/mediagoblin.service
  433. echo 'Type=simple' >> /etc/systemd/system/mediagoblin.service
  434. echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin.service
  435. echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin.service
  436. echo "WorkingDirectory=$MEDIAGOBLIN_BASE_DIR/mediagoblin/" >> /etc/systemd/system/mediagoblin.service
  437. echo "ExecStart=$MEDIAGOBLIN_BASE_DIR/mediagoblin/lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=$MEDIAGOBLIN_PORT" >> /etc/systemd/system/mediagoblin.service
  438. echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini CELERY_ALWAYS_EAGER=true" >> /etc/systemd/system/mediagoblin.service
  439. echo 'Restart=always' >> /etc/systemd/system/mediagoblin.service
  440. echo 'RestartSec=10' >> /etc/systemd/system/mediagoblin.service
  441. echo '' >> /etc/systemd/system/mediagoblin.service
  442. echo '[Install]' >> /etc/systemd/system/mediagoblin.service
  443. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin.service
  444. chmod +x /etc/systemd/system/mediagoblin.service
  445. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
  446. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
  447. su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
  448. sed -i 's|email_debug_mode.*|email_debug_mode = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  449. sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  450. sed -i 's|allow_reporting.*|allow_reporting = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  451. if ! grep -q '[[[skip_transcode]]]' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini; then
  452. echo '[[[skip_transcode]]]' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  453. echo 'mime_types = video/webm, video/ogg, video/mp4, audio/ogg, application/ogg, application/x-annodex' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  454. echo 'container_formats = Matroska, Ogg, ISO MP4/M4A' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  455. echo 'video_codecs = VP8 video, VP9 video, Theora, H.264, H.264 / AVC, MPEG-4 video' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  456. echo 'audio_codecs = Vorbis, MPEG-4 AAC' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  457. echo 'dimensions_match = false' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
  458. fi
  459. systemctl enable mediagoblin
  460. systemctl daemon-reload
  461. systemctl start mediagoblin
  462. mediagoblin_fix_email
  463. if [ -d /var/lib/mediagoblin/media ]; then
  464. chmod -R +x /var/lib/mediagoblin/media
  465. fi
  466. function_check create_site_certificate
  467. create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME 'yes'
  468. function_check configure_php
  469. configure_php
  470. nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
  471. systemctl restart php7.0-fpm
  472. systemctl restart nginx
  473. function_check add_ddns_domain
  474. add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
  475. chown -hR mediagoblin:www-data /var/lib/mediagoblin
  476. chmod -R g+wx /var/lib/mediagoblin
  477. APP_INSTALLED=1
  478. }
  479. # NOTE: deliberately no exit 0