freedombone/src/freedombone-app-postactiv

788 lines
30 KiB
Plaintext
Raw Normal View History

2016-11-02 14:01:59 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# postactiv application
#
# License
# =======
#
2016-11-02 14:03:57 +01:00
# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
2016-11-02 14:01:59 +01:00
#
# 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
POSTACTIV_DOMAIN_NAME=
POSTACTIV_CODE=
POSTACTIV_ONION_PORT=8100
2016-11-22 22:52:17 +01:00
POSTACTIV_REPO="https://git.postactiv.com/postActiv/postActiv.git"
2017-04-04 21:07:50 +02:00
POSTACTIV_COMMIT='432cbbd4c15e0dd6b0dd38d2d76cda14a53add3b'
2016-11-02 14:01:59 +01:00
POSTACTIV_ADMIN_PASSWORD=
2017-02-22 22:00:27 +01:00
POSTACTIV_BACKGROUND_IMAGE_URL=
POSTACTIV_TITLE='PostActiv'
2016-11-02 14:01:59 +01:00
# script which causes old posts to expire
postactiv_expire_script=/usr/bin/postactiv-expire
postactiv_variables=(ONION_ONLY
2016-11-02 14:01:59 +01:00
POSTACTIV_DOMAIN_NAME
POSTACTIV_CODE
DDNS_PROVIDER
2017-02-22 22:00:27 +01:00
MY_USERNAME
POSTACTIV_BACKGROUND_IMAGE_URL
POSTACTIV_TITLE)
2016-11-02 14:01:59 +01:00
function remove_user_postactiv {
remove_username="$1"
2016-11-19 20:17:33 +01:00
${PROJECT_NAME}-pass -u $remove_username --rmapp postactiv
2016-11-02 14:01:59 +01:00
function_check get_completion_param
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
if [ -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
php scripts/deleteprofile.php -n $remove_username -y
fi
}
function add_user_postactiv {
new_username="$1"
new_user_password="$2"
2016-11-19 20:17:33 +01:00
${PROJECT_NAME}-pass -u $new_username -a postactiv -p "$new_user_password"
2016-11-02 14:01:59 +01:00
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
if [ -d /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs ]; then
cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
php scripts/registeruser.php -n $new_username -w "$new_user_password" -e "$new_username@$HOSTNAME"
${PROJECT_NAME}-addemail -u $new_username -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
echo '0'
else
echo '1'
fi
}
function install_interactive_postactiv {
if [ ! $ONION_ONLY ]; then
ONION_ONLY='no'
fi
if [[ $ONION_ONLY != "no" ]]; then
POSTACTIV_DOMAIN_NAME='postactiv.local'
else
POSTACTIV_DETAILS_COMPLETE=
while [ ! $POSTACTIV_DETAILS_COMPLETE ]
do
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
dialog --backtitle $"Freedombone Configuration" \
--title $"PostActiv Configuration" \
--form $"\nPlease enter your PostActiv details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
2016-11-02 14:01:59 +01:00
$"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
2017-02-22 22:31:57 +01:00
$"Title:" 2 1 "$(grep '$POSTACTIV_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
$"Background image URL:" 3 1 "$(grep '$POSTACTIV_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
$"Code:" 4 1 "$(grep 'POSTACTIV_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
2016-11-02 14:01:59 +01:00
2> $data
else
dialog --backtitle $"Freedombone Configuration" \
--title $"PostActiv Configuration" \
--form $"\nPlease enter your PostActiv details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
2016-11-02 14:01:59 +01:00
$"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
$"Title:" 2 1 "$(grep '$POSTACTIV_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
$"Background image URL:" 3 1 "$(grep '$POSTACTIV_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
2016-11-02 14:01:59 +01:00
2> $data
fi
sel=$?
case $sel in
1) exit 1;;
255) exit 1;;
esac
POSTACTIV_DOMAIN_NAME=$(cat $data | sed -n 1p)
title=$(cat $data | sed -n 2p)
if [ ${#title} -gt 1 ]; then
POSTACTIV_TITLE=$welcome_msg
fi
2016-11-02 14:01:59 +01:00
img_url=$(cat $data | sed -n 3p)
if [ ${#img_url} -gt 1 ]; then
POSTACTIV_BACKGROUND_IMAGE_URL=$img_url
fi
2016-11-02 14:01:59 +01:00
if [ $POSTACTIV_DOMAIN_NAME ]; then
if [[ $POSTACTIV_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
POSTACTIV_DOMAIN_NAME=""
fi
TEST_DOMAIN_NAME=$POSTACTIV_DOMAIN_NAME
validate_domain_name
if [[ $TEST_DOMAIN_NAME != $POSTACTIV_DOMAIN_NAME ]]; then
POSTACTIV_DOMAIN_NAME=
dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
POSTACTIV_CODE=$(cat $data | sed -n 4p)
2016-11-02 14:01:59 +01:00
validate_freedns_code "$POSTACTIV_CODE"
if [ ! $VALID_CODE ]; then
POSTACTIV_DOMAIN_NAME=
fi
fi
fi
fi
if [ $POSTACTIV_DOMAIN_NAME ]; then
POSTACTIV_DETAILS_COMPLETE="yes"
fi
done
# remove any invalid characters
if [ ${#POSTACTIV_TITLE} -gt 0 ]; then
new_title=$(echo "$POSTACTIV_TITLE" | sed "s|'||g")
POSTACTIV_TITLE="$new_title"
fi
2016-11-02 14:01:59 +01:00
# save the results in the config file
write_config_param "POSTACTIV_CODE" "$POSTACTIV_CODE"
write_config_param "POSTACTIV_TITLE" "$POSTACTIV_TITLE"
write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
2016-11-02 14:01:59 +01:00
fi
write_config_param "POSTACTIV_DOMAIN_NAME" "$POSTACTIV_DOMAIN_NAME"
APP_INSTALLED=1
}
function change_password_postactiv {
2016-11-20 13:37:13 +01:00
curr_username="$1"
new_user_password="$2"
read_config_param ${POSTACTIV_DOMAIN_NAME}
2016-12-04 13:28:45 +01:00
cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts
php setpassword.php "$curr_username" "$new_user_password"
2016-11-20 13:37:13 +01:00
${PROJECT_NAME}-pass -u "$curr_username" -a postactiv -p "$new_user_password"
2016-11-02 14:01:59 +01:00
}
function postactiv_create_database {
2016-11-19 10:37:35 +01:00
if [ -f $IMAGE_PASSWORD_FILE ]; then
POSTACTIV_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else
if [ ! $POSTACTIV_ADMIN_PASSWORD ]; then
2016-11-02 14:01:59 +01:00
POSTACTIV_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi
fi
if [ ! $POSTACTIV_ADMIN_PASSWORD ]; then
return
fi
function_check create_database
create_database postactiv "$POSTACTIV_ADMIN_PASSWORD" $MY_USERNAME
}
function postactiv_running_script {
2017-04-04 12:11:19 +02:00
gnusocial_hourly_script postactiv $POSTACTIV_DOMAIN_NAME
2017-04-04 12:11:19 +02:00
# This was a hack to fix a bug in master, but may no longer be needed
echo "if ! grep -q \"//define('POSTACTIV',true);\" scripts/commandline.inc; then" >> /etc/cron.hourly/postactiv-daemons
echo " sed -i \"s|define('POSTACTIV',true);|//define('POSTACTIV',true);|g\" scripts/commandline.inc" >> /etc/cron.hourly/postactiv-daemons
echo 'fi' >> /etc/cron.hourly/postactiv-daemons
2016-11-02 14:01:59 +01:00
}
function reconfigure_postactiv {
echo -n ''
}
2017-02-22 22:14:56 +01:00
function postactiv_set_background_image {
2017-04-04 00:27:10 +02:00
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
2017-02-22 22:14:56 +01:00
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"PostActiv" \
--backtitle $"Freedombone Control Panel" \
--inputbox $'Set a background image URL' 10 60 2>$data
sel=$?
case $sel in
0)
temp_background=$(<$data)
if [ ${#temp_background} -gt 0 ]; then
POSTACTIV_BACKGROUND_IMAGE_URL="$temp_background"
write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
2017-04-04 00:27:10 +02:00
if [[ $(pleroma_set_background_image_from_url "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE" | tail -n 1) == "0" ]]; then
dialog --title $"Set PostActiv background" \
--msgbox $"The background image has been set" 6 60
fi
2017-02-22 22:14:56 +01:00
fi
;;
esac
}
function postactiv_set_title {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"PostActiv" \
--backtitle $"Freedombone Control Panel" \
--inputbox $'Set a title' 10 60 2>$data
sel=$?
case $sel in
0)
new_title=$(<$data)
if [ ${#new_title} -gt 0 ]; then
POSTACTIV_TITLE="$new_title"
2017-04-04 11:47:06 +02:00
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
2017-02-22 22:14:56 +01:00
write_config_param "POSTACTIV_TITLE" "$POSTACTIV_TITLE"
cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/static
sed -i "s|\"name\":.*|\"name\": \"${POSTACTIV_TITLE}\",|g" config.json
dialog --title $"Set PostActiv title" \
--msgbox $"The title has been set" 6 60
fi
;;
esac
}
function configure_interactive_postactiv {
while true
do
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"PostActiv" \
--radiolist $"Choose an operation:" 12 70 3 \
1 $"Set a background image" off \
2 $"Set the title" off \
3 $"Exit" on 2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
case $(cat $data) in
1) postactiv_set_background_image;;
2) postactiv_set_title;;
3) break;;
esac
done
}
2016-11-02 14:01:59 +01:00
function upgrade_postactiv {
if grep -q "postactiv domain" $COMPLETION_FILE; then
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
fi
# update to the next commit
function_check set_repo_commit
set_repo_commit /var/www/$POSTACTIV_DOMAIN_NAME/htdocs "postactiv commit" "$POSTACTIV_COMMIT" $POSTACTIV_REPO
# Ensure that installation script is removed
if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php ]; then
rm /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php
fi
2017-02-18 13:05:58 +01:00
function_check postactiv_running_script
postactiv_running_script
2017-02-22 22:00:27 +01:00
upgrade_pleroma "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
2016-11-02 14:01:59 +01:00
}
function backup_local_postactiv {
POSTACTIV_DOMAIN_NAME='postactiv'
if grep -q "postactiv domain" $COMPLETION_FILE; then
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
fi
source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
if [ -d $source_directory ]; then
dest_directory=postactiv
function_check suspend_site
suspend_site ${POSTACTIV_DOMAIN_NAME}
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
function_check backup_database_to_usb
backup_database_to_usb postactiv
function_check restart_site
restart_site
fi
}
function restore_local_postactiv {
if ! grep -q "postactiv domain" $COMPLETION_FILE; then
return
fi
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
if [ $POSTACTIV_DOMAIN_NAME ]; then
temp_restore_dir=/root/temppostactiv
postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
# stop the daemons
cd $postactiv_dir
scripts/stopdaemons.sh
function_check postactiv_create_database
postactiv_create_database
restore_database postactiv ${POSTACTIV_DOMAIN_NAME}
if [ -d $temp_restore_dir ]; then
rm -rf $temp_restore_dir
fi
# start the daemons
cd $postactiv_dir
scripts/startdaemons.sh
fi
}
function backup_remote_postactiv {
if grep -q "postactiv domain" $COMPLETION_FILE; then
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
temp_backup_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
if [ -d $temp_backup_dir ]; then
function_check suspend_site
suspend_site ${POSTACTIV_DOMAIN_NAME}
function_check backup_database_to_friend
backup_database_to_friend postactiv
function_check backup_directory_to_friend
backup_directory_to_friend $temp_backup_dir postactiv
function_check restart_site
restart_site
else
echo $"postactiv domain specified but not found in ${temp_backup_dir}"
fi
fi
}
function restore_remote_postactiv {
if grep -q "postactiv domain" $COMPLETION_FILE; then
POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
# stop the daemons
cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
./scripts/stopdaemons.sh
function_check postactiv_create_database
postactiv_create_database
function_check restore_database_from_friend
restore_database_from_friend postactiv ${POSTACTIV_DOMAIN_NAME}
if [ -d /root/temppostactiv ]; then
rm -rf /root/temppostactiv
fi
# start the daemons
cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
./scripts/startdaemons.sh
fi
}
function remove_postactiv {
if [ ${#POSTACTIV_DOMAIN_NAME} -eq 0 ]; then
return
fi
2017-02-22 22:35:34 +01:00
function_check remove_nodejs
remove_nodejs pleroma-postactiv
2016-11-02 14:01:59 +01:00
read_config_param "POSTACTIV_DOMAIN_NAME"
read_config_param "MY_USERNAME"
echo "Removing $POSTACTIV_DOMAIN_NAME"
nginx_dissite $POSTACTIV_DOMAIN_NAME
remove_certs $POSTACTIV_DOMAIN_NAME
if [ -f /etc/cron.hourly/postactiv-daemons ]; then
rm /etc/cron.hourly/postactiv-daemons
fi
2016-11-02 14:01:59 +01:00
if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts
./scripts/stopdaemons.sh
fi
2016-11-02 14:01:59 +01:00
if [ -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
fi
if [ -f /etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME ]; then
rm /etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
fi
function_check drop_database
drop_database postactiv
function_check remove_onion_service
remove_onion_service postactiv ${POSTACTIV_ONION_PORT}
if grep -q "postactiv" /etc/crontab; then
sed -i "/postactiv/d" /etc/crontab
fi
remove_app postactiv
remove_completion_param install_postactiv
sed -i '/postactiv/d' $COMPLETION_FILE
2016-11-02 18:49:21 +01:00
remove_backup_database_local postactiv
function_check remove_ddns_domain
remove_ddns_domain $POSTACTIV_DOMAIN_NAME
2016-11-02 14:01:59 +01:00
}
function install_postactiv_main {
if [ ! $POSTACTIV_DOMAIN_NAME ]; then
echo $'No domain name was given for postactiv'
exit 7359
fi
if [[ $(app_is_installed postactiv_main) == "1" ]]; then
return
fi
2017-02-22 22:47:40 +01:00
function_check postactiv_running_script
postactiv_running_script
2016-11-02 14:01:59 +01:00
function_check install_mariadb
install_mariadb
function_check get_mariadb_password
get_mariadb_password
function_check repair_databases_script
repair_databases_script
apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
apt-get -yq install php5-memcached php5-intl
if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
mkdir /var/www/$POSTACTIV_DOMAIN_NAME
fi
if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
function_check git_clone
git_clone $POSTACTIV_REPO /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
echo $'Unable to clone postactiv repo'
exit 87525
fi
fi
cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
git checkout $POSTACTIV_COMMIT -b $POSTACTIV_COMMIT
set_completion_param "postactiv commit" "$POSTACTIV_COMMIT"
2016-12-04 13:42:36 +01:00
chmod g+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
chmod a+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/avatar
chmod a+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/file
2016-12-04 14:51:25 +01:00
chown -R www-data:www-data /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
2016-11-02 14:01:59 +01:00
chmod +x /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php
2016-12-04 17:23:21 +01:00
chmod 777 /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php
2016-11-02 14:01:59 +01:00
function_check postactiv_create_database
postactiv_create_database
if [ ! -f "/etc/aliases" ]; then
touch /etc/aliases
fi
if ! grep -q "www-data: root" /etc/aliases; then
echo 'www-data: root' >> /etc/aliases
fi
if ! grep -q "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
echo "*: /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
fi
function_check add_ddns_domain
add_ddns_domain $POSTACTIV_DOMAIN_NAME
postactiv_nginx_site=/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
if [[ $ONION_ONLY == "no" ]]; then
function_check nginx_http_redirect
2017-04-03 22:13:16 +02:00
nginx_http_redirect $POSTACTIV_DOMAIN_NAME "index index.php"
2016-11-02 14:01:59 +01:00
echo 'server {' >> $postactiv_nginx_site
echo ' listen 443 ssl;' >> $postactiv_nginx_site
2016-11-17 23:45:20 +01:00
echo ' listen [::]:443 ssl;' >> $postactiv_nginx_site
2016-11-02 14:01:59 +01:00
echo " server_name $POSTACTIV_DOMAIN_NAME;" >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Security' >> $postactiv_nginx_site
function_check nginx_ssl
nginx_ssl $POSTACTIV_DOMAIN_NAME
function_check nginx_disable_sniffing
nginx_disable_sniffing $POSTACTIV_DOMAIN_NAME
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Logs' >> $postactiv_nginx_site
2016-11-10 14:26:31 +01:00
echo ' access_log /dev/null;' >> $postactiv_nginx_site
echo ' error_log /dev/null;' >> $postactiv_nginx_site
2016-11-02 14:01:59 +01:00
echo '' >> $postactiv_nginx_site
echo ' # Root' >> $postactiv_nginx_site
echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;" >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Index' >> $postactiv_nginx_site
echo ' index index.php;' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # PHP' >> $postactiv_nginx_site
echo ' location ~ \.php {' >> $postactiv_nginx_site
echo ' include snippets/fastcgi-php.conf;' >> $postactiv_nginx_site
echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Location' >> $postactiv_nginx_site
echo ' location / {' >> $postactiv_nginx_site
function_check nginx_limits
nginx_limits $POSTACTIV_DOMAIN_NAME '15m'
echo ' try_files $uri $uri/ @postactiv;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Fancy URLs' >> $postactiv_nginx_site
echo ' location @postactiv {' >> $postactiv_nginx_site
echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Restrict access that is unnecessary anyway' >> $postactiv_nginx_site
echo ' location ~ /\.(ht|git) {' >> $postactiv_nginx_site
echo ' deny all;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
# DO NOT ENABLE KEYBASE. postactiv really doesn't like having a .well-known directory
2016-11-02 14:01:59 +01:00
echo '}' >> $postactiv_nginx_site
else
echo -n '' > $postactiv_nginx_site
fi
echo 'server {' >> $postactiv_nginx_site
echo " listen 127.0.0.1:$POSTACTIV_ONION_PORT default_server;" >> $postactiv_nginx_site
echo " server_name $POSTACTIV_DOMAIN_NAME;" >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
function_check nginx_disable_sniffing
nginx_disable_sniffing $POSTACTIV_DOMAIN_NAME
echo '' >> $postactiv_nginx_site
echo ' # Logs' >> $postactiv_nginx_site
2016-11-10 14:26:31 +01:00
echo ' access_log /dev/null;' >> $postactiv_nginx_site
echo ' error_log /dev/null;' >> $postactiv_nginx_site
2016-11-02 14:01:59 +01:00
echo '' >> $postactiv_nginx_site
echo ' # Root' >> $postactiv_nginx_site
echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;" >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Index' >> $postactiv_nginx_site
echo ' index index.php;' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # PHP' >> $postactiv_nginx_site
echo ' location ~ \.php {' >> $postactiv_nginx_site
echo ' include snippets/fastcgi-php.conf;' >> $postactiv_nginx_site
echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Location' >> $postactiv_nginx_site
echo ' location / {' >> $postactiv_nginx_site
function_check nginx_limits
nginx_limits $POSTACTIV_DOMAIN_NAME '15m'
echo ' try_files $uri $uri/ @postactiv;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Fancy URLs' >> $postactiv_nginx_site
echo ' location @postactiv {' >> $postactiv_nginx_site
echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
echo ' # Restrict access that is unnecessary anyway' >> $postactiv_nginx_site
echo ' location ~ /\.(ht|git) {' >> $postactiv_nginx_site
echo ' deny all;' >> $postactiv_nginx_site
echo ' }' >> $postactiv_nginx_site
echo '' >> $postactiv_nginx_site
# DO NOT ENABLE KEYBASE. postactiv really doesn't like having a .well-known directory
2016-11-02 14:01:59 +01:00
echo '}' >> $postactiv_nginx_site
function_check configure_php
configure_php
function_check create_site_certificate
create_site_certificate $POSTACTIV_DOMAIN_NAME 'yes'
# Ensure that the database gets backed up locally, if remote
# backups are not being used
function_check backup_databases_script_header
backup_databases_script_header
function_check backup_database_local
backup_database_local postactiv
function_check nginx_ensite
nginx_ensite $POSTACTIV_DOMAIN_NAME
# NOTE: For the typical case always enable SSL and only
# disable it if in onion only mode. This is due to complexities
# with the way URLs are generated by postactiv
postactiv_ssl='always'
if [[ $ONION_ONLY != 'no' ]]; then
postactiv_ssl='never'
fi
POSTACTIV_ONION_HOSTNAME=$(add_onion_service postactiv 80 ${POSTACTIV_ONION_PORT})
POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME}
if [[ $ONION_ONLY != 'no' ]]; then
POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME}
fi
# Create the configuration
postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php
if [ ! -f $postactiv_installer ]; then
2016-11-24 16:43:35 +01:00
rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
2016-11-02 14:01:59 +01:00
echo $'No postactiv commandline installer found'
exit 53026
fi
${postactiv_installer} --server "${POSTACTIV_SERVER}" \
--host="localhost" --database="postactiv" \
--dbtype=mysql --username="root" -v \
--password="$MARIADB_PASSWORD" \
--sitename=$"postactiv" --fancy='yes' \
--admin-nick="$MY_USERNAME" \
--admin-pass="$POSTACTIV_ADMIN_PASSWORD" \
--site-profile="community" \
--ssl=${postactiv_ssl}
# There can be a lot of warnings here so the return value check is disabled
#if [ ! "$?" = "0" ]; then
# # failed to install
# echo $'Could not install postactiv'
# exit 72357
#fi
# check postactiv has a config file
postactiv_config_file=/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/config.php
if [ ! -f $postactiv_config_file ]; then
2016-12-01 12:17:33 +01:00
drop_database postactiv
2016-11-24 16:43:35 +01:00
rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
2016-11-02 14:01:59 +01:00
echo $'Postactiv config.php not found'
exit 87586
fi
# Some useful settings
if ! grep -q "Recommended postactiv settings" $postactiv_config_file; then
echo "" >> $postactiv_config_file
echo "// Recommended postactiv settings" >> $postactiv_config_file
echo "\$config['thumbnail']['maxsize'] = 3000;" >> $postactiv_config_file
echo "\$config['profile']['delete'] = true;" >> $postactiv_config_file
echo "\$config['profile']['changenick'] = true;" >> $postactiv_config_file
echo "\$config['public']['localonly'] = false;" >> $postactiv_config_file
echo "addPlugin('StoreRemoteMedia');" >> $postactiv_config_file
echo "\$config['queue']['enabled'] = true;" >> $postactiv_config_file
echo "\$config['queue']['daemon'] = true;" >> $postactiv_config_file
echo "\$config['ostatus']['hub_retries'] = 3;" >> $postactiv_config_file
fi
2016-12-04 19:05:33 +01:00
echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $postactiv_config_file
2016-11-02 14:01:59 +01:00
# This improves performance
sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $postactiv_config_file
2016-11-02 17:13:42 +01:00
# remove the install script
if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php ]; then
rm /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php
fi
2016-11-02 14:01:59 +01:00
systemctl restart php5-fpm
systemctl restart nginx
${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
2016-11-19 20:17:33 +01:00
${PROJECT_NAME}-pass -u $MY_USERNAME -a postactiv -p "$POSTACTIV_ADMIN_PASSWORD"
2016-11-02 14:01:59 +01:00
set_completion_param "postactiv domain" "$POSTACTIV_DOMAIN_NAME"
install_completed postactiv_main
}
function expire_postactiv_posts {
# To prevent the database size from growing endlessly this script expires posts
# after a number of months
if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
return
fi
echo '<?php' > $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo '// postactiv post expiry script, based on StatExpire by Tony Baldwin' >> $postactiv_expire_script
echo '// https://github.com/tonybaldwin/statexpire' >> $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $postactiv_expire_script
echo '$username="root";' >> $postactiv_expire_script
echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $postactiv_expire_script
2016-11-02 14:01:59 +01:00
echo '$database="postactiv";' >> $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $postactiv_expire_script
echo ' echo "Could not connect to mariadb";' >> $postactiv_expire_script
echo ' exit;' >> $postactiv_expire_script
echo '}' >> $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo 'if (!mysql_select_db($database, $link)) {' >> $postactiv_expire_script
echo ' echo "Could not select postactiv database";' >> $postactiv_expire_script
echo ' exit;' >> $postactiv_expire_script
echo '}' >> $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $postactiv_expire_script
echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $postactiv_expire_script
echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo 'mysql_query($notice_query);' >> $postactiv_expire_script
echo '$rowaff1=mysql_affected_rows();' >> $postactiv_expire_script
echo 'mysql_query($conversation_query);' >> $postactiv_expire_script
echo '$rowaff2=mysql_affected_rows();' >> $postactiv_expire_script
echo 'mysql_query($reply_query);' >> $postactiv_expire_script
echo '$rowaff3=mysql_affected_rows();' >> $postactiv_expire_script
echo 'mysql_close();' >> $postactiv_expire_script
echo '' >> $postactiv_expire_script
echo 'echo "Expire postactiv posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $postactiv_expire_script
chmod +x $postactiv_expire_script
# Add a cron job
if ! grep -q "$postactiv_expire_script" /etc/crontab; then
echo "10 3 5 * * root /usr/bin/timeout 500 /usr/bin/php $postactiv_expire_script" >> /etc/crontab
fi
# remove old expire script
if [ -f /etc/cron.weekly/clear-postactiv-database ]; then
rm /etc/cron.weekly/clear-postactiv-database
fi
}
function install_postactiv {
if [ ! $ONION_ONLY ]; then
ONION_ONLY='no'
fi
install_postactiv_main
install_qvitter "$POSTACTIV_DOMAIN_NAME" "postactiv"
2017-02-22 22:00:27 +01:00
#function_check install_nodejs
#install_nodejs pleroma-postactiv
# Currently Pleroma won't install on ARM systems
# because it uses node-sass which doesn't support ARM
if [[ "$(arch)" == "arm"* ]]; then
echo -m $'WARNING: Pleroma currently does not support ARM '
echo $'architecture, so it will not be installed'
else
function_check install_nodejs
install_nodejs pleroma-gnusocial
install_pleroma "postactiv" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
fi
2017-02-22 22:00:27 +01:00
2016-11-02 14:01:59 +01:00
expire_postactiv_posts
# unleash the daemons!
/etc/cron.hourly/postactiv-daemons
APP_INSTALLED=1
}
# NOTE: deliberately there is no "exit 0"