123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- #!/bin/bash
- #
- # .---. . .
- # | | |
- # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
- # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
- # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
- #
- # Freedom in the Cloud
- #
- # Mediagoblin application
- #
- # License
- # =======
- #
- # Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- VARIANTS='full full-vim media'
-
- IN_DEFAULT_INSTALL=0
- SHOW_ON_ABOUT=1
-
- MEDIAGOBLIN_DOMAIN_NAME=
- MEDIAGOBLIN_ADMIN_PASSWORD=
- MEDIAGOBLIN_CODE=
- MEDIAGOBLIN_ONION_PORT=8108
- MEDIAGOBLIN_REPO="http://git.savannah.gnu.org/r/mediagoblin.git"
- MEDIAGOBLIN_COMMIT='c4d3293dfa4076719e60fe9e052add07426f9a9a'
- MEDIAGOBLIN_BASE_DIR=/var/www/mediagoblin.local/htdocs
- MEDIAGOBLIN_PORT=6543
-
- mediagoblin_variables=(ONION_ONLY
- MY_USERNAME
- MEDIAGOBLIN_DOMAIN_NAME
- MEDIAGOBLIN_CODE
- DEFAULT_DOMAIN_NAME
- DDNS_PROVIDER)
-
- function mediagoblin_fix_email {
- # This is a crude hack and there may be a better solution
- # The cause of verification problems might be that the mediagoblin user
- # does not have mail access
- read_config_param 'MEDIAGOBLIN_DOMAIN_NAME'
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- mgfile=$MEDIAGOBLIN_BASE_DIR/mediagoblin/tools/mail.py
- if ! grep 'import os' $mgfile; then
- sed -i '/import sys/a import os' $mgfile
- fi
- replacestr='return mhost.sendmail(from_addr, to_addrs, message.as_string())'
- newstr="return os.system(\"echo '\" + message_body + \"' | mail -s '\" + message['Subject'] + \"' \" + message['To'])"
- sed -i "s|${replacestr}|${newstr}|g" $mgfile
- }
-
- function install_interactive_mediagoblin {
- if [[ $ONION_ONLY != "no" ]]; then
- MEDIAGOBLIN_DOMAIN_NAME='mediagoblin.local'
- write_config_param "MEDIAGOBLIN_DOMAIN_NAME" "$MEDIAGOBLIN_DOMAIN_NAME"
- else
- function_check interactive_site_details
- interactive_site_details "mediagoblin" "MEDIAGOBLIN_DOMAIN_NAME" "MEDIAGOBLIN_CODE"
- fi
- APP_INSTALLED=1
- }
-
- function configure_interactive_mediagoblin {
- read_config_param 'MEDIAGOBLIN_DOMAIN_NAME'
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
-
- dialog --title $"Mediagoblin" \
- --backtitle $"Freedombone Control Panel" \
- --defaultno \
- --yesno $"\nAllow registration of new users?" 10 60
- sel=$?
- case $sel in
- 0)
- sed -i 's|allow_registration.*|allow_registration = true|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- sed -i 's|allow_registration.*|allow_registration = true|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- ;;
- 1)
- sed -i 's|allow_registration.*|allow_registration = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- sed -i 's|allow_registration.*|allow_registration = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- ;;
- 255) return;;
- esac
- systemctl restart mediagoblin
- }
-
- function change_password_mediagoblin {
- curr_username="$1"
- new_user_password="$2"
- }
-
- function add_user_mediagoblin {
- new_username="$1"
- new_user_password="$2"
-
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $new_username --password $new_username $new_user_password" - mediagoblin
- echo "0"
- }
-
- function remove_user_mediagoblin {
- remove_username="$1"
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg deleteuser --username $new_username" - mediagoblin
- echo "0"
- }
-
- function reconfigure_mediagoblin {
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- rm -f /var/lib/mediagoblin/*.db
- rm -rf $MEDIAGOBLIN_BASE_DIR/user_dev
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && ./bin/gmg dbupdate" - mediagoblin
- }
-
- function upgrade_mediagoblin {
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate" - mediagoblin
- mediagoblin_fix_email
- echo "0"
- }
-
- function backup_local_mediagoblin {
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- source_directory=/var/lib/mediagoblin
- if [ -d $source_directory ]; then
- dest_directory=mediagoblin
- function_check backup_directory_to_usb
- backup_directory_to_usb $MEDIAGOBLIN_BASE_DIR $dest_directory
- backup_directory_to_usb /var/lib/mediagoblin mediagoblindata
- fi
- }
-
- function restore_local_mediagoblin {
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- if [ -d /var/lib/mediagoblin ]; then
- echo $"Restoring Mediagoblin installation"
- function_check get_completion_param
- MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
- temp_restore_dir=/root/tempmediagoblin
- function_check restore_directory_from_usb
- restore_directory_from_usb ${temp_restore_dir} mediagoblin
- cp -r ${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR/* $MEDIAGOBLIN_BASE_DIR/
- if [ ! "$?" = "0" ]; then
- function_check restore_directory_from_usb
- set_user_permissions
- function_check backup_unmount_drive
- backup_unmount_drive
- exit 45327
- fi
- restore_directory_from_usb ${temp_restore_dir}2 mediagoblindata
- cp -r ${temp_restore_dir}2/var/lib/mediagoblin/* /var/lib/mediagoblin/
- if [ ! "$?" = "0" ]; then
- function_check set_user_permissions
- set_user_permissions
- function_check backup_unmount_drive
- backup_unmount_drive
- exit 24529
- fi
- rm -rf ${temp_restore_dir}
- rm -rf ${temp_restore_dir}2
- chown -hR mediagoblin:www-data /var/lib/mediagoblin
- chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
- fi
- }
-
- function backup_remote_mediagoblin {
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- if [ -d /etc/mediagoblin ]; then
- echo $"Backing up mediagoblin"
- backup_directory_to_friend $MEDIAGOBLIN_BASE_DIR mediagoblin
- backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
- fi
- }
-
- function restore_remote_mediagoblin {
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
- function_check get_completion_param
- MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
- function_check restore_directory_from_friend
- restore_directory_from_friend /root/tempmediagoblin mediagoblin
- cp -r /root/tempmediagoblin/var/lib/mediagoblin/* /var/lib/mediagoblin/
- if [ ! "$?" = "0" ]; then
- exit 264824
- fi
- restore_directory_from_friend /root/tempmediagoblin2 mediagoblindata
- cp -r /root/tempmediagoblin/var/lib/mediagoblin/* /var/lib/mediagoblin/
- if [ ! "$?" = "0" ]; then
- exit 268492
- fi
- rm -rf /root/tempmediagoblin
- rm -rf /root/tempmediagoblin2
- chown -hR mediagoblin:www-data /var/lib/mediagoblin
- chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
- fi
- }
-
- function remove_mediagoblin {
- if [ ${#MEDIAGOBLIN_DOMAIN_NAME} -eq 0 ]; then
- return
- fi
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
- systemctl stop mediagoblin
- systemctl disable mediagoblin
- rm /etc/systemd/system/mediagoblin.service
-
- function_check remove_onion_service
- remove_onion_service mediagoblin ${MEDIAGOBLIN_ONION_PORT}
- nginx_dissite $MEDIAGOBLIN_DOMAIN_NAME
- remove_certs $MEDIAGOBLIN_DOMAIN_NAME
- if [ -d /var/lib/mediagoblin ]; then
- rm -rf /var/lib/mediagoblin
- fi
- if [ -d $MEDIAGOBLIN_BASE_DIR ]; then
- rm -rf $MEDIAGOBLIN_BASE_DIR
- fi
- remove_completion_param "install_mediagoblin"
- remove_completion_param "mediagoblin domain"
- sed -i '/mediagoblin/d' $COMPLETION_FILE
-
- remove_nodejs mediagoblin
- deluser mediagoblin
- delgroup mediagoblin
-
- function_check remove_ddns_domain
- remove_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
- }
-
- function install_mediagoblin {
- if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
- return
- fi
-
- MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
-
- function_check install_nodejs
- install_nodejs mediagoblin
-
- apt-get install -yq python python-dev python-lxml python-imaging python-virtualenv
- apt-get install -yq automake perl sqlite python-paste python-pastedeploy python-pastescript
- apt-get install -yq python3 python3-dev libpython3-dev python3-lxml python3-pil
- useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
- groupadd mediagoblin
- usermod --append -G mediagoblin mediagoblin
- mkdir -p /var/lib/mediagoblin
- chown -hR mediagoblin:www-data /var/lib/mediagoblin
- mkdir -p $MEDIAGOBLIN_BASE_DIR
- chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
- su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule sync" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule update --force --init --recursive" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./bootstrap.sh" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./configure" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && make" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ln -s /var/lib/mediagoblin user_dev" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bash -c 'cp -av mediagoblin.ini mediagoblin_local.ini && cp -av paste.ini paste_local.ini'" - mediagoblin
- 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
-
- # Video plugin
- apt-get install -yq python-gi python3-gi \
- gstreamer1.0-tools \
- gir1.2-gstreamer-1.0 \
- gir1.2-gst-plugins-base-1.0 \
- gstreamer1.0-plugins-good \
- gstreamer1.0-plugins-bad \
- gstreamer1.0-plugins-ugly \
- gstreamer1.0-libav \
- python-gst-1.0 python3-gst-1.0
- cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
-
- # Audio plugin
- 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
- apt-get -yq install libasound2-dev python3-numpy python3-scipy libsndfile-dev
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/pip install scikits.audiolab" - mediagoblin
-
- if [ -f $IMAGE_PASSWORD_FILE ]; then
- MEDIAGOBLIN_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
- else
- if [ ! $MEDIAGOBLIN_ADMIN_PASSWORD ]; then
- MEDIAGOBLIN_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
- fi
- fi
- ${PROJECT_NAME}-pass -u $MY_USERNAME -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
-
- MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
- set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
-
- if [[ $ONION_ONLY == "no" ]]; then
- function_check nginx_http_redirect
- nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
- echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' listen [::]:443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' default_type application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- function_check nginx_ssl
- nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
- function_check nginx_disable_sniffing
- nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
- function_check nginx_limits
- nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
- nginx_keybase $MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
-
- echo ' location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- else
- echo -n '' > /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- fi
- echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' default_type application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- function_check nginx_disable_sniffing
- nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
- function_check nginx_limits
- nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
-
- echo ' location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo " alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_pass 127.0.0.1:26543;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo ' }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
- echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
-
- echo '[Unit]' > /etc/systemd/system/mediagoblin.service
- echo 'Description=Media service' >> /etc/systemd/system/mediagoblin.service
- echo 'Requires=network.target' >> /etc/systemd/system/mediagoblin.service
- echo 'After=network.target' >> /etc/systemd/system/mediagoblin.service
- echo '' >> /etc/systemd/system/mediagoblin.service
- echo '[Service]' >> /etc/systemd/system/mediagoblin.service
- echo 'Type=simple' >> /etc/systemd/system/mediagoblin.service
- echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin.service
- echo "WorkingDirectory=$MEDIAGOBLIN_BASE_DIR/mediagoblin/" >> /etc/systemd/system/mediagoblin.service
- 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
- echo 'Restart=always' >> /etc/systemd/system/mediagoblin.service
- echo 'RestartSec=10' >> /etc/systemd/system/mediagoblin.service
- echo '' >> /etc/systemd/system/mediagoblin.service
- echo '[Install]' >> /etc/systemd/system/mediagoblin.service
- echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin.service
- chmod +x /etc/systemd/system/mediagoblin.service
-
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
- su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
-
- sed -i 's|email_debug_mode.*|email_debug_mode = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- sed -i 's|email_debug_mode.*|email_debug_mode = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
-
- sed -i 's|allow_reporting.*|allow_reporting = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- sed -i 's|allow_reporting.*|allow_reporting = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
-
- if ! grep 'email_smtp_host' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini; then
- sed -i '/email_sender_address/a email_smtp_host = localhost' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- else
- sed -i 's|email_smtp_host.*|email_smtp_host = localhost|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- fi
-
- if ! grep 'email_smtp_host' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini; then
- sed -i '/email_sender_address/a email_smtp_host = localhost' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
- else
- sed -i 's|email_smtp_host.*|email_smtp_host = localhost|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- fi
-
- if ! grep '[[[skip_transcode]]]' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini; then
- echo '[[[skip_transcode]]]' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- echo 'mime_types = video/webm, video/ogg, video/mp4, audio/ogg, application/ogg, application/x-annodex' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- echo 'container_formats = Matroska, Ogg, ISO MP4/M4A' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- echo 'video_codecs = VP8 video, VP9 video, Theora, H.264, H.264 / AVC, MPEG-4 video' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- echo 'audio_codecs = Vorbis, MPEG-4 AAC' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- echo 'dimensions_match = false' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
- fi
-
- systemctl enable mediagoblin
- systemctl daemon-reload
- systemctl start mediagoblin
-
- mediagoblin_fix_email
-
- function_check create_site_certificate
- create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME
-
- function_check configure_php
- configure_php
-
- nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
-
- systemctl restart php5-fpm
- systemctl restart nginx
-
- function_check add_ddns_domain
- add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
-
- set_completion_param "mediagoblin domain" "$MEDIAGOBLIN_DOMAIN_NAME"
- set_completion_param "mediagoblin commit" "$MEDIAGOBLIN_COMMIT"
-
- APP_INSTALLED=1
- }
-
- # NOTE: deliberately no exit 0
|