2016-12-23 16:36:57 +01:00
|
|
|
#!/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"
|
2016-12-24 12:36:37 +01:00
|
|
|
MEDIAGOBLIN_COMMIT='c4d3293dfa4076719e60fe9e052add07426f9a9a'
|
2016-12-23 16:36:57 +01:00
|
|
|
MEDIAGOBLIN_BASE_DIR=/var/www/mediagoblin.local/htdocs
|
2016-12-23 20:08:53 +01:00
|
|
|
MEDIAGOBLIN_PORT=6543
|
2016-12-23 16:36:57 +01:00
|
|
|
|
|
|
|
mediagoblin_variables=(ONION_ONLY
|
|
|
|
MY_USERNAME
|
|
|
|
MEDIAGOBLIN_DOMAIN_NAME
|
|
|
|
MEDIAGOBLIN_CODE
|
2016-12-23 23:19:21 +01:00
|
|
|
DEFAULT_DOMAIN_NAME
|
2016-12-23 16:36:57 +01:00
|
|
|
DDNS_PROVIDER)
|
|
|
|
|
2016-12-24 12:33:35 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-12-23 23:19:21 +01:00
|
|
|
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
|
2016-12-23 23:26:09 +01:00
|
|
|
sed -i 's|allow_registration.*|allow_registration = true|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
|
2016-12-23 23:19:21 +01:00
|
|
|
;;
|
|
|
|
1)
|
|
|
|
sed -i 's|allow_registration.*|allow_registration = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin.ini
|
2016-12-23 23:26:09 +01:00
|
|
|
sed -i 's|allow_registration.*|allow_registration = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
|
2016-12-23 23:19:21 +01:00
|
|
|
;;
|
|
|
|
255) return;;
|
|
|
|
esac
|
|
|
|
systemctl restart mediagoblin
|
|
|
|
}
|
|
|
|
|
2016-12-23 16:36:57 +01:00
|
|
|
function change_password_mediagoblin {
|
|
|
|
curr_username="$1"
|
|
|
|
new_user_password="$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_user_mediagoblin {
|
|
|
|
new_username="$1"
|
|
|
|
new_user_password="$2"
|
2016-12-23 17:11:57 +01:00
|
|
|
|
|
|
|
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"
|
2016-12-23 16:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_user_mediagoblin {
|
|
|
|
remove_username="$1"
|
2016-12-23 17:11:57 +01:00
|
|
|
MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
|
2016-12-23 20:08:53 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg deleteuser --username $new_username" - mediagoblin
|
2016-12-23 17:11:57 +01:00
|
|
|
echo "0"
|
2016-12-23 16:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function reconfigure_mediagoblin {
|
2016-12-23 20:08:53 +01:00
|
|
|
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
|
2016-12-23 16:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_mediagoblin {
|
2016-12-23 20:08:53 +01:00
|
|
|
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
|
2016-12-24 12:33:35 +01:00
|
|
|
mediagoblin_fix_email
|
2016-12-23 20:08:53 +01:00
|
|
|
echo "0"
|
2016-12-23 16:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-12-24 16:17:07 +01:00
|
|
|
chown -hR mediagoblin:www-data /var/lib/mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-24 16:17:07 +01:00
|
|
|
chown -hR mediagoblin:www-data /var/lib/mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-23 17:06:41 +01:00
|
|
|
systemctl stop mediagoblin
|
|
|
|
systemctl disable mediagoblin
|
|
|
|
rm /etc/systemd/system/mediagoblin.service
|
|
|
|
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-23 22:45:12 +01:00
|
|
|
apt-get install -yq automake perl sqlite python-paste python-pastedeploy python-pastescript
|
2016-12-24 15:09:20 +01:00
|
|
|
apt-get install -yq python3 python3-dev libpython3-dev python3-lxml python3-pil
|
2016-12-23 16:36:57 +01:00
|
|
|
groupadd mediagoblin
|
2016-12-24 18:48:44 +01:00
|
|
|
useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
usermod --append -G mediagoblin mediagoblin
|
2016-12-24 13:48:28 +01:00
|
|
|
mkdir -p /var/lib/mediagoblin
|
2016-12-24 16:17:07 +01:00
|
|
|
chown -hR mediagoblin:www-data /var/lib/mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-24 12:36:37 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT" - mediagoblin
|
2016-12-23 22:47:59 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule sync" - mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && git submodule update --force --init --recursive" - mediagoblin
|
2016-12-23 22:49:29 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./bootstrap.sh" - mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && ./configure" - mediagoblin
|
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && make" - mediagoblin
|
2016-12-23 22:45:12 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
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 \
|
2016-12-24 13:31:29 +01:00
|
|
|
gstreamer1.0-plugins-bad \
|
|
|
|
gstreamer1.0-plugins-ugly \
|
2016-12-23 16:36:57 +01:00
|
|
|
gstreamer1.0-libav \
|
2016-12-24 15:09:20 +01:00
|
|
|
python-gst-1.0 python3-gst-1.0
|
2016-12-23 16:36:57 +01:00
|
|
|
cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
|
2016-12-23 20:08:53 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
|
2016-12-23 16:36:57 +01:00
|
|
|
|
|
|
|
# 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
|
2016-12-24 15:09:20 +01:00
|
|
|
apt-get -yq install libasound2-dev python3-numpy python3-scipy libsndfile-dev
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-23 22:45:12 +01:00
|
|
|
${PROJECT_NAME}-pass -u $MY_USERNAME -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
|
2016-12-23 16:36:57 +01:00
|
|
|
|
|
|
|
MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
|
|
|
|
set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
|
2016-12-24 16:28:18 +01:00
|
|
|
set_completion_param "mediagoblin onion domain" "$MEDIAGOBLIN_ONION_HOSTNAME"
|
|
|
|
set_completion_param "mediagoblin commit" "$MEDIAGOBLIN_COMMIT"
|
2016-12-23 16:36:57 +01:00
|
|
|
|
|
|
|
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
|
2016-12-23 16:39:13 +01:00
|
|
|
nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
|
2016-12-23 16:36:57 +01:00
|
|
|
nginx_keybase $MEDIAGOBLIN_DOMAIN_NAME
|
|
|
|
echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
|
2016-12-24 12:52:25 +01:00
|
|
|
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
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-23 17:06:41 +01:00
|
|
|
echo " fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-23 16:39:13 +01:00
|
|
|
nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
|
2016-12-23 16:36:57 +01:00
|
|
|
echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
|
2016-12-24 12:52:25 +01:00
|
|
|
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
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
2016-12-24 16:45:21 +01:00
|
|
|
echo " fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
|
|
|
|
2016-12-23 17:06:41 +01:00
|
|
|
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
|
2016-12-24 18:48:44 +01:00
|
|
|
echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin.service
|
2016-12-23 17:06:41 +01:00
|
|
|
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
|
2016-12-24 18:48:44 +01:00
|
|
|
echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini CELERY_ALWAYS_EAGER=true" >> /etc/systemd/system/mediagoblin.service
|
2016-12-23 17:06:41 +01:00
|
|
|
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
|
|
|
|
|
2016-12-23 17:08:36 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
|
2016-12-23 17:11:57 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
|
2016-12-23 17:08:36 +01:00
|
|
|
su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
|
|
|
|
|
2016-12-23 23:26:09 +01:00
|
|
|
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_local.ini
|
2016-12-23 23:14:18 +01:00
|
|
|
|
2016-12-24 12:33:35 +01:00
|
|
|
sed -i 's|allow_reporting.*|allow_reporting = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
|
|
|
|
|
2016-12-24 13:31:29 +01:00
|
|
|
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
|
|
|
|
|
2016-12-23 20:08:53 +01:00
|
|
|
systemctl enable mediagoblin
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start mediagoblin
|
|
|
|
|
2016-12-24 12:33:35 +01:00
|
|
|
mediagoblin_fix_email
|
|
|
|
|
2016-12-23 16:36:57 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: deliberately no exit 0
|