freedombone-app-mediagoblin 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # mediagoblin functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  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=''
  31. MEDIAGOBLIN_DOMAIN_NAME=
  32. MEDIAGOBLIN_CODE=
  33. MEDIAGOBLIN_REPO="git://git.savannah.gnu.org/mediagoblin.git"
  34. MEDIAGOBLIN_COMMIT='d1ac2d52fd8859c3f32fa38e4836ffe9615e5bba'
  35. MEDIAGOBLIN_ADMIN_PASSWORD=
  36. MEDIAGOBLIN_ONION_PORT=8096
  37. mediagoblin_variables=(ONION_ONLY
  38. MEDIAGOBLIN_DOMAIN_NAME
  39. MEDIAGOBLIN_CODE
  40. MEDIAGOBLIN_REPO
  41. MEDIAGOBLIN_COMMIT
  42. DDNS_PROVIDER)
  43. function install_interactive_mediagoblin {
  44. if [[ $ONION_ONLY != "no" ]]; then
  45. MEDIAGOBLIN_DOMAIN_NAME='media.local'
  46. else
  47. MEDIAGOBLIN_DETAILS_COMPLETE=
  48. while [ ! $MEDIAGOBLIN_DETAILS_COMPLETE ]
  49. do
  50. data=$(tempfile 2>/dev/null)
  51. trap "rm -f $data" 0 1 2 5 15
  52. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  53. dialog --backtitle $"Freedombone Configuration" \
  54. --title $"Mediagoblin Configuration" \
  55. --form $"\nPlease enter your Mediagoblin details, or just select Ok if you don't need a Mediagoblin site:" 11 55 2 \
  56. $"Domain:" 1 1 "$(grep 'MEDIAGOBLIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
  57. $"Code:" 2 1 "$(grep 'MEDIAGOBLIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 255 \
  58. 2> $data
  59. else
  60. dialog --backtitle $"Freedombone Configuration" \
  61. --title $"Mediagoblin Configuration" \
  62. --form $"\nPlease enter your Mediagoblin details, or just select Ok if you don't need a Mediagoblin site:" 11 55 2 \
  63. $"Domain:" 1 1 "$(grep 'MEDIAGOBLIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
  64. 2> $data
  65. fi
  66. sel=$?
  67. case $sel in
  68. 1) exit 1;;
  69. 255) exit 1;;
  70. esac
  71. MEDIAGOBLIN_DOMAIN_NAME=$(cat $data | sed -n 1p)
  72. if [ $MEDIAGOBLIN_DOMAIN_NAME ]; then
  73. TEST_DOMAIN_NAME=$MEDIAGOBLIN_DOMAIN_NAME
  74. validate_domain_name
  75. if [[ $TEST_DOMAIN_NAME != $MEDIAGOBLIN_DOMAIN_NAME ]]; then
  76. MEDIAGOBLIN_DOMAIN_NAME='invalid'
  77. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  78. else
  79. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  80. MEDIAGOBLIN_CODE=$(cat $data | sed -n 2p)
  81. validate_freedns_code "$MEDIAGOBLIN_CODE"
  82. if [ ! $VALID_CODE ]; then
  83. MEDIAGOBLIN_DOMAIN_NAME='invalid'
  84. fi
  85. fi
  86. fi
  87. fi
  88. if [ $MEDIAGOBLIN_DOMAIN_NAME ]; then
  89. if [[ $MEDIAGOBLIN_DOMAIN_NAME == 'invalid' ]]; then
  90. MEDIAGOBLIN_DOMAIN_NAME=
  91. else
  92. MEDIAGOBLIN_DETAILS_COMPLETE="yes"
  93. fi
  94. fi
  95. done
  96. # save the results in the config file
  97. write_config_param "MEDIAGOBLIN_CODE" "$MEDIAGOBLIN_CODE"
  98. fi
  99. write_config_param "MEDIAGOBLIN_DOMAIN_NAME" "$MEDIAGOBLIN_DOMAIN_NAME"
  100. APP_INSTALLED=1
  101. }
  102. function change_password_mediagoblin {
  103. echo -n ''
  104. }
  105. function reconfigure_mediagoblin {
  106. echo -n ''
  107. }
  108. function upgrade_mediagoblin {
  109. if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
  110. return
  111. fi
  112. MEDIAGOBLIN_WORKING_DIRECTORY=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  113. # update to a new commit if needed
  114. function_check set_repo_commit
  115. set_repo_commit $MEDIAGOBLIN_WORKING_DIRECTORY "Mediagoblin commit" "$MEDIAGOBLIN_COMMIT" $MEDIAGOBLIN_REPO
  116. if [ -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
  117. chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
  118. fi
  119. }
  120. function backup_local_mediagoblin {
  121. echo -n ''
  122. }
  123. function restore_local_mediagoblin {
  124. echo -n ''
  125. }
  126. function backup_remote_mediagoblin {
  127. function_check suspend_site
  128. suspend_site ${MEDIAGOBLIN_DOMAIN_NAME}
  129. echo $"Backing up Mediagoblin"
  130. backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin
  131. function_check restart_site
  132. restart_site
  133. echo $"Backup of Mediagoblin complete"
  134. }
  135. function restore_remote_mediagoblin {
  136. if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
  137. echo $"Restoring Mediagoblin installation"
  138. temp_restore_dir=/root/tempmediagoblin
  139. function_check restore_directory_from_friend
  140. restore_directory_from_friend $temp_restore_dir mediagoblin
  141. cp -r $temp_restore_dir/* /
  142. if [ ! "$?" = "0" ]; then
  143. exit 5626
  144. fi
  145. rm -rf $temp_restore_dir
  146. echo $"Restore of Mediagoblin complete"
  147. fi
  148. chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  149. }
  150. function remove_mediagoblin {
  151. echo -n ''
  152. }
  153. function install_mediagoblin {
  154. if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
  155. return
  156. fi
  157. MEDIAGOBLIN_WORKING_DIRECTORY=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  158. # update to a new commit if needed
  159. function_check set_repo_commit
  160. set_repo_commit $MEDIAGOBLIN_WORKING_DIRECTORY "Mediagoblin commit" "$MEDIAGOBLIN_COMMIT" $MEDIAGOBLIN_REPO
  161. if [ -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
  162. chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
  163. fi
  164. apt-get -y install git-core python python-dev python-lxml python-pil
  165. apt-get -y install python-virtualenv npm nodejs-legacy automake
  166. apt-get -y install fcgiwrap
  167. #apt-get -y install postgresql postgresql-client python-psycopg2
  168. #apt-get -y install python-gst-1.0 libjpeg62-turbo-dev gstreamer1.0-plugins-base python-gobject
  169. #apt-get -y install gstreamer1.0-plugins-good gstreamer1.0-libav libav-tools gstreamer0.10-tools
  170. #apt-get -y install python-numpy python-scipy libsndfile1-dev python-gst0.10-dev
  171. #apt-get -y install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer1.0-tools
  172. #su -c "createuser -A -D mediagoblin" - postgres
  173. #su -c "createdb -E UNICODE -O mediagoblin mediagoblin" - postgres
  174. useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
  175. groupadd mediagoblin
  176. usermod --append -G mediagoblin mediagoblin
  177. if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
  178. mkdir -p $MEDIAGOBLIN_WORKING_DIRECTORY
  179. fi
  180. function_check git_clone
  181. git_clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_WORKING_DIRECTORY
  182. cd $MEDIAGOBLIN_WORKING_DIRECTORY
  183. git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT
  184. git submodule init
  185. git submodule update
  186. if ! grep -q "Mediagoblin commit" $COMPLETION_FILE; then
  187. echo "Mediagoblin commit:$MEDIAGOBLIN_COMMIT" >> $COMPLETION_FILE
  188. else
  189. sed -i "s/Mediagoblin commit.*/Mediagoblin commit:$MEDIAGOBLIN_COMMIT/g" $COMPLETION_FILE
  190. fi
  191. chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
  192. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bootstrap.sh" - mediagoblin
  193. if [ ! "$?" = "0" ]; then
  194. exit 278826
  195. fi
  196. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./configure" - mediagoblin
  197. if [ ! "$?" = "0" ]; then
  198. exit 462826
  199. fi
  200. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && make" - mediagoblin
  201. if [ ! "$?" = "0" ]; then
  202. exit 738229
  203. fi
  204. if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev ]; then
  205. mkdir $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
  206. fi
  207. chmod 750 $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
  208. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
  209. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade billiard" - mediagoblin
  210. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Paste" - mediagoblin
  211. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade amqp" - mediagoblin
  212. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade anyjson" - mediagoblin
  213. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py-bcrypt" - mediagoblin
  214. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade wtforms" - mediagoblin
  215. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade python-dateutil" - mediagoblin
  216. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alembic" - mediagoblin
  217. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade waitress" - mediagoblin
  218. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade imagesize" - mediagoblin
  219. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alabaster" - mediagoblin
  220. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade snowballstemmer" - mediagoblin
  221. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade docutils" - mediagoblin
  222. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Pygments" - mediagoblin
  223. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade beautifulsoup4" - mediagoblin
  224. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade WebOb" - mediagoblin
  225. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py" - mediagoblin
  226. su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade execnet" - mediagoblin
  227. # create some directories
  228. mkdir /var/log/mediagoblin
  229. chown -hR mediagoblin:www-data /var/log/mediagoblin
  230. mkdir /var/run/mediagoblin
  231. chown -hR mediagoblin:www-data /var/run/mediagoblin
  232. if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin.ini ]; then
  233. echo $'mediagoblin.ini not found'
  234. exit 737529
  235. fi
  236. if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/paste.ini ]; then
  237. echo $'paste.ini not found'
  238. exit 52762
  239. fi
  240. cp -av mediagoblin.ini mediagoblin_local.ini
  241. cp -av paste.ini paste_local.ini
  242. chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
  243. # init with systemd
  244. echo '[Unit]' > /etc/systemd/system/mediagoblin-celeryd.service
  245. echo 'Description=Mediagoblin Celeryd' >> /etc/systemd/system/mediagoblin-celeryd.service
  246. echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-celeryd.service
  247. echo 'After=network.target' >> /etc/systemd/system/mediagoblin-celeryd.service
  248. echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
  249. echo '[Service]' >> /etc/systemd/system/mediagoblin-celeryd.service
  250. echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
  251. echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
  252. echo 'Type=simple' >> /etc/systemd/system/mediagoblin-celeryd.service
  253. echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-celeryd.service
  254. echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin_local.ini \\" >> /etc/systemd/system/mediagoblin-celeryd.service
  255. echo ' CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery' >> /etc/systemd/system/mediagoblin-celeryd.service
  256. echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/celery worker \\" >> /etc/systemd/system/mediagoblin-celeryd.service
  257. echo ' --logfile=/var/log/mediagoblin/celery.log \' >> /etc/systemd/system/mediagoblin-celeryd.service
  258. echo ' --loglevel=INFO' >> /etc/systemd/system/mediagoblin-celeryd.service
  259. echo 'PIDFile=/var/run/mediagoblin/mediagoblin-celeryd.pid' >> /etc/systemd/system/mediagoblin-celeryd.service
  260. echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
  261. echo '[Install]' >> /etc/systemd/system/mediagoblin-celeryd.service
  262. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-celeryd.service
  263. echo '[Unit]' > /etc/systemd/system/mediagoblin-paster.service
  264. echo 'Description=Mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
  265. echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-paster.service
  266. echo 'After=network.target' >> /etc/systemd/system/mediagoblin-paster.service
  267. echo '' >> /etc/systemd/system/mediagoblin-paster.service
  268. echo '[Service]' >> /etc/systemd/system/mediagoblin-paster.service
  269. echo 'Type=forking' >> /etc/systemd/system/mediagoblin-paster.service
  270. echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
  271. echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
  272. echo 'Environment=CELERY_ALWAYS_EAGER=false' >> /etc/systemd/system/mediagoblin-paster.service
  273. echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-paster.service
  274. echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
  275. echo " $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini \\" >> /etc/systemd/system/mediagoblin-paster.service
  276. echo ' --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
  277. echo ' --log-file=/var/log/mediagoblin/mediagoblin.log \' >> /etc/systemd/system/mediagoblin-paster.service
  278. echo ' --daemon \' >> /etc/systemd/system/mediagoblin-paster.service
  279. echo ' --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543' >> /etc/systemd/system/mediagoblin-paster.service
  280. echo "ExecStop=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
  281. echo ' --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
  282. echo " $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini stop" >> /etc/systemd/system/mediagoblin-paster.service
  283. echo 'PIDFile=/var/run/mediagoblin/mediagoblin.pid' >> /etc/systemd/system/mediagoblin-paster.service
  284. echo '' >> /etc/systemd/system/mediagoblin-paster.service
  285. echo '[Install]' >> /etc/systemd/system/mediagoblin-paster.service
  286. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-paster.service
  287. systemctl daemon-reload
  288. systemctl enable mediagoblin-celeryd
  289. systemctl enable mediagoblin-paster
  290. systemctl daemon-reload
  291. systemctl start mediagoblin-celeryd
  292. systemctl start mediagoblin-paster
  293. MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
  294. if [[ $MEDIAGOBLIN_ONION_HOSTNAME == *"not found"* ]]; then
  295. echo $'Problem creating onion address for mediagoblin'
  296. exit 672652
  297. fi
  298. # web config
  299. MEDIAGOBLIN_VIRTUAL_HOST=/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
  300. function_check nginx_http_redirect
  301. nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
  302. if [[ $ONION_ONLY == 'no' ]]; then
  303. echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  304. echo ' listen 443 ssl;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  305. echo ' #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  306. echo ' # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  307. echo ' #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  308. echo ' include /etc/nginx/mime.types;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  309. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  310. echo ' autoindex off;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  311. echo ' default_type application/octet-stream;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  312. echo ' sendfile on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  313. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  314. function_check nginx_ssl
  315. nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
  316. function_check nginx_disable_sniffing
  317. nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
  318. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  319. echo ' # Gzip' >> $MEDIAGOBLIN_VIRTUAL_HOST
  320. echo ' gzip on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  321. echo ' gzip_min_length 1024;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  322. echo ' gzip_buffers 4 32k;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  323. echo ' gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  324. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  325. echo ' #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  326. echo ' # Mounting MediaGoblin stuff' >> $MEDIAGOBLIN_VIRTUAL_HOST
  327. echo ' # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
  328. echo ' #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  329. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  330. echo " server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  331. echo ' access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  332. echo ' error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  333. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  334. echo ' # MediaGoblins stock static files: CSS, JS, etc.' >> $MEDIAGOBLIN_VIRTUAL_HOST
  335. echo ' location /mgoblin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  336. function_check nginx_limits
  337. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  338. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin/static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  339. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  340. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  341. echo ' # Instance specific media:' >> $MEDIAGOBLIN_VIRTUAL_HOST
  342. echo ' location /mgoblin_media/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  343. function_check nginx_limits
  344. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  345. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/media/public/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  346. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  347. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  348. echo ' # Theme static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  349. echo ' location /theme_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  350. function_check nginx_limits
  351. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  352. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/theme_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  353. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  354. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  355. echo ' # Plugin static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  356. echo ' location /plugin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  357. function_check nginx_limits
  358. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  359. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/plugin_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  360. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  361. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  362. echo ' # Mounting MediaGoblin itself via FastCGI.' >> $MEDIAGOBLIN_VIRTUAL_HOST
  363. echo ' location / {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  364. function_check nginx_limits
  365. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  366. echo ' fastcgi_pass 127.0.0.1:26543;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  367. echo ' include /etc/nginx/fastcgi_params;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  368. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  369. echo ' # our understanding vs nginxs handling of script_name vs' >> $MEDIAGOBLIN_VIRTUAL_HOST
  370. echo ' # path_info dont match :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  371. echo ' fastcgi_param PATH_INFO $fastcgi_script_name;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  372. echo ' fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
  373. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  374. echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
  375. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  376. else
  377. echo -n '' > $MEDIAGOBLIN_VIRTUAL_HOST
  378. fi
  379. echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  380. echo " listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  381. echo ' #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  382. echo ' # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  383. echo ' #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  384. echo ' include /etc/nginx/mime.types;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  385. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  386. echo ' autoindex off;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  387. echo ' default_type application/octet-stream;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  388. echo ' sendfile on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  389. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  390. function_check nginx_disable_sniffing
  391. nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
  392. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  393. echo ' # Gzip' >> $MEDIAGOBLIN_VIRTUAL_HOST
  394. echo ' gzip on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  395. echo ' gzip_min_length 1024;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  396. echo ' gzip_buffers 4 32k;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  397. echo ' gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  398. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  399. echo ' #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  400. echo ' # Mounting MediaGoblin stuff' >> $MEDIAGOBLIN_VIRTUAL_HOST
  401. echo ' # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
  402. echo ' #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
  403. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  404. echo " server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  405. echo ' access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  406. echo ' error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  407. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  408. echo ' # MediaGoblins stock static files: CSS, JS, etc.' >> $MEDIAGOBLIN_VIRTUAL_HOST
  409. echo ' location /mgoblin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  410. function_check nginx_limits
  411. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  412. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin/static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  413. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  414. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  415. echo ' # Instance specific media:' >> $MEDIAGOBLIN_VIRTUAL_HOST
  416. echo ' location /mgoblin_media/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  417. function_check nginx_limits
  418. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  419. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/media/public/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  420. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  421. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  422. echo ' # Theme static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  423. echo ' location /theme_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  424. function_check nginx_limits
  425. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  426. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/theme_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  427. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  428. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  429. echo ' # Plugin static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  430. echo ' location /plugin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  431. function_check nginx_limits
  432. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  433. echo " alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/plugin_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
  434. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  435. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  436. echo ' # Mounting MediaGoblin itself via FastCGI.' >> $MEDIAGOBLIN_VIRTUAL_HOST
  437. echo ' location / {' >> $MEDIAGOBLIN_VIRTUAL_HOST
  438. function_check nginx_limits
  439. nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
  440. echo ' fastcgi_pass 127.0.0.1:26543;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  441. echo ' include /etc/nginx/fastcgi_params;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  442. echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
  443. echo ' # our understanding vs nginxs handling of script_name vs' >> $MEDIAGOBLIN_VIRTUAL_HOST
  444. echo ' # path_info dont match :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
  445. echo ' fastcgi_param PATH_INFO $fastcgi_script_name;' >> $MEDIAGOBLIN_VIRTUAL_HOST
  446. echo ' fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
  447. echo ' }' >> $MEDIAGOBLIN_VIRTUAL_HOST
  448. echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
  449. function_check create_site_certificate
  450. create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME
  451. nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
  452. systemctl restart php5-fpm
  453. systemctl restart nginx
  454. add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
  455. if ! grep -q "Mediagoblin domain" $COMPLETION_FILE; then
  456. echo "Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME" >> $COMPLETION_FILE
  457. else
  458. sed -i "s/Mediagoblin domain.*/Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME/g" $COMPLETION_FILE
  459. fi
  460. APP_INSTALLED=1
  461. }
  462. # NOTE: deliberately no exit 0