freedombone-app-mediagoblin 26KB

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