| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010 | 
							- #!/bin/bash
 - #
 - # .---.                  .              .
 - # |                      |              |
 - # |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
 - # |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
 - # '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
 - #
 - #                    Freedom in the Cloud
 - #
 - # gnusocial application
 - #
 - # License
 - # =======
 - #
 - # Copyright (C) 2014-2017 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
 - 
 - GNUSOCIAL_DOMAIN_NAME=
 - GNUSOCIAL_CODE=
 - GNUSOCIAL_ONION_PORT=8087
 - GNUSOCIAL_REPO="https://git.gnu.io/gnu/gnu-social.git"
 - GNUSOCIAL_COMMIT='57f78dc61ccaaf4676cb0d6db452c1dadfc4b81e'
 - GNUSOCIAL_ADMIN_PASSWORD=
 - 
 - GNUSOCIAL_BACKGROUND_IMAGE_URL=
 - GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
 - GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
 - 
 - # Sharings plugin for gnusocial
 - SHARINGS_REPO="http://git.lasindias.club/bashrc/Sharings"
 - SHARINGS_COMMIT='d5c6c7f855d9afff9086c09ea706f38c859bc0d4'
 - SHARINGS_THEME_REPO="http://git.lasindias.club/manuel/SharingsTheme"
 - SHARINGS_THEME_COMMIT='7106c7ef03'
 - 
 - # NSFW plugin
 - GNUSOCIAL_NSFW_REPO="https://gitgud.io/ShitposterClub/SensitiveContent"
 - GNUSOCIAL_NSFW_COMMIT='a096bbe0cfae9a9b177682920ffb58d32a48e136'
 - 
 - GNUSOCIAL_TITLE='Pleroma FE'
 - 
 - # Number of months after which posts expire
 - GNUSOCIAL_EXPIRE_MONTHS=3
 - 
 - gnusocial_variables=(ONION_ONLY
 -                      GNUSOCIAL_DOMAIN_NAME
 -                      GNUSOCIAL_CODE
 -                      GNUSOCIAL_WELCOME_MESSAGE
 -                      GNUSOCIAL_BACKGROUND_IMAGE_URL
 -                      DDNS_PROVIDER
 -                      GNUSOCIAL_MARKDOWN_REPO
 -                      GNUSOCIAL_MARKDOWN_COMMIT
 -                      SHARINGS_REPO
 -                      SHARINGS_COMMIT
 -                      SHARINGS_THEME_REPO
 -                      SHARINGS_THEME_COMMIT
 -                      GNUSOCIAL_TITLE
 -                      GNUSOCIAL_EXPIRE_MONTHS
 -                      MY_USERNAME)
 - 
 - function gnusocial_fix_endless_reloads {
 -     # This fixes a bug introduced with commit 5f7032dfee1fd202c14e76a9f8b37af35d584901
 -     # and which causes OrFox to endlessly reload the page
 -     sed -i 's| && common_local_referer()||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/lib/apiauthaction.php
 - }
 - 
 - function remove_user_gnusocial {
 -     remove_username="$1"
 - 
 -     ${PROJECT_NAME}-pass -u $remove_username --rmapp gnusocial
 - 
 -     function_check get_completion_param
 -     GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -     if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
 -         cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -         php scripts/deleteprofile.php -n $remove_username -y
 -     fi
 - }
 - 
 - function add_user_gnusocial {
 -     new_username="$1"
 -     new_user_password="$2"
 - 
 -     ${PROJECT_NAME}-pass -u $new_username -a gnusocial -p "$new_user_password"
 - 
 -     GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -     if [ -d /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs ]; then
 -         cd /var/www/$GNUSOCIAL_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@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
 -         echo '0'
 -     else
 -         echo '1'
 -     fi
 - }
 - 
 - function install_interactive_gnusocial {
 -     if [ ! $ONION_ONLY ]; then
 -         ONION_ONLY='no'
 -     fi
 - 
 -     if [[ $ONION_ONLY != "no" ]]; then
 -         GNUSOCIAL_DOMAIN_NAME='gnusocial.local'
 -     else
 -         GNUSOCIAL_DETAILS_COMPLETE=
 -         while [ ! $GNUSOCIAL_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 $"GNU Social Configuration" \
 -                        --form $"\nPlease enter your GNU Social 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 \
 -                        $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
 -                        $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
 -                        $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
 -                        $"Code:" 4 1 "$(grep 'GNUSOCIAL_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
 -                        2> $data
 -             else
 -                 dialog --backtitle $"Freedombone Configuration" \
 -                        --title $"GNU Social Configuration" \
 -                        --form $"\nPlease enter your GNU Social 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 \
 -                        $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
 -                        $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
 -                        $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
 -                        2> $data
 -             fi
 -             sel=$?
 -             case $sel in
 -                 1) exit 1;;
 -                 255) exit 1;;
 -             esac
 -             GNUSOCIAL_DOMAIN_NAME=$(cat $data | sed -n 1p)
 -             title=$(cat $data | sed -n 2p)
 -             if [ ${#title} -gt 1 ]; then
 -                 GNUSOCIAL_TITLE=$welcome_msg
 -             fi
 -             img_url=$(cat $data | sed -n 3p)
 -             if [ ${#img_url} -gt 1 ]; then
 -                 GNUSOCIAL_BACKGROUND_IMAGE_URL=$img_url
 -             fi
 -             if [ $GNUSOCIAL_DOMAIN_NAME ]; then
 -                 if [[ $GNUSOCIAL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
 -                     GNUSOCIAL_DOMAIN_NAME=""
 -                 fi
 -                 TEST_DOMAIN_NAME=$GNUSOCIAL_DOMAIN_NAME
 -                 validate_domain_name
 -                 if [[ $TEST_DOMAIN_NAME != $GNUSOCIAL_DOMAIN_NAME ]]; then
 -                     GNUSOCIAL_DOMAIN_NAME=
 -                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
 -                 else
 -                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
 -                         GNUSOCIAL_CODE=$(cat $data | sed -n 4p)
 -                         validate_freedns_code "$GNUSOCIAL_CODE"
 -                         if [ ! $VALID_CODE ]; then
 -                             GNUSOCIAL_DOMAIN_NAME=
 -                         fi
 -                     fi
 -                 fi
 -             fi
 -             if [ $GNUSOCIAL_DOMAIN_NAME ]; then
 -                 GNUSOCIAL_DETAILS_COMPLETE="yes"
 -             fi
 -         done
 - 
 -         # remove any invalid characters
 -         if [ ${#GNUSOCIAL_TITLE} -gt 0 ]; then
 -             new_title=$(echo "$GNUSOCIAL_TITLE" | sed "s|'||g")
 -             GNUSOCIAL_TITLE="$new_title"
 -         fi
 - 
 -         # save the results in the config file
 -         write_config_param "GNUSOCIAL_CODE" "$GNUSOCIAL_CODE"
 -         write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
 -         write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
 -     fi
 -     write_config_param "GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_DOMAIN_NAME"
 -     APP_INSTALLED=1
 - }
 - 
 - function change_password_gnusocial {
 -     curr_username="$1"
 -     new_user_password="$2"
 - 
 -     read_config_param ${GNUSOCIAL_DOMAIN_NAME}
 - 
 -     cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts
 -     php setpassword.php "$curr_username" "$new_user_password"
 - 
 -     ${PROJECT_NAME}-pass -u "$curr_username" -a gnusocial -p "$new_user_password"
 - }
 - 
 - function gnusocial_create_database {
 -     if [ -f $IMAGE_PASSWORD_FILE ]; then
 -         GNUSOCIAL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
 -     else
 -         if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
 -             GNUSOCIAL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
 -         fi
 -     fi
 -     if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
 -         return
 -     fi
 - 
 -     function_check create_database
 -     create_database gnusocial "$GNUSOCIAL_ADMIN_PASSWORD" $MY_USERNAME
 - }
 - 
 - function reconfigure_gnusocial {
 -     echo -n ''
 - }
 - 
 - function gnusocial_set_background_image {
 -     GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 - 
 -     data=$(tempfile 2>/dev/null)
 -     trap "rm -f $data" 0 1 2 5 15
 -     dialog --title $"GNU Social" \
 -            --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
 -                 GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
 -                 write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
 -                 if [[ $(pleroma_set_background_image_from_url "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE" | tail -n 1) == "0" ]]; then
 -                     dialog --title $"Set GNU Social login background" \
 -                            --msgbox $"The background image has been set" 6 60
 -                 fi
 -             fi
 -            ;;
 -     esac
 - }
 - 
 - function gnusocial_set_title {
 -     data=$(tempfile 2>/dev/null)
 -     trap "rm -f $data" 0 1 2 5 15
 -     dialog --title $"GNU Social" \
 -            --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
 -                 GNUSOCIAL_TITLE="$new_title"
 -                 GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -                 write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
 -                 cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/static
 -                 sed -i "s|\"name\":.*|\"name\": \"${GNUSOCIAL_TITLE}\",|g" config.json
 -                 dialog --title $"Set GNU Social title" \
 -                        --msgbox $"The title has been set" 6 60
 -             fi
 -            ;;
 -     esac
 - }
 - 
 - function gnusocial_set_expire_months {
 -     GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -     read_config_param "GNUSOCIAL_EXPIRE_MONTHS"
 - 
 -     data=$(tempfile 2>/dev/null)
 -     trap "rm -f $data" 0 1 2 5 15
 -     dialog --title $"GNU Social" \
 -            --backtitle $"Freedombone Control Panel" \
 -            --inputbox $'Set an expiry period for posts in months. Anything older will be deleted. Lower values help to keep the database size small and as fast as possible.' 12 60 "$GNUSOCIAL_EXPIRE_MONTHS" 2>$data
 -     sel=$?
 -     case $sel in
 -         0)
 -             new_expiry_months=$(<$data)
 -             if [ ${#new_expiry_months} -gt 0 ]; then
 -                 # should contain no spaces
 -                 if [[ "$new_expiry_months" == *" "* ]]; then
 -                     return
 -                 fi
 -                 # should be a number
 -                 re='^[0-9]+$'
 -                 if ! [[ $new_expiry_months =~ $re ]] ; then
 -                     return
 -                 fi
 -                 # set the new value
 -                 GNUSOCIAL_EXPIRE_MONTHS=$new_expiry_months
 -                 write_config_param "GNUSOCIAL_EXPIRE_MONTHS" "$GNUSOCIAL_EXPIRE_MONTHS"
 -                 expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
 -                 dialog --title $"Set GNU Social post expiry period" \
 -                        --msgbox $"Expiry period set to $GNUSOCIAL_EXPIRE_MONTHS months" 6 60
 -             fi
 -            ;;
 -     esac
 - }
 - 
 - function configure_interactive_gnusocial {
 -     while true
 -     do
 -         data=$(tempfile 2>/dev/null)
 -         trap "rm -f $data" 0 1 2 5 15
 -         dialog --backtitle $"Freedombone Control Panel" \
 -                --title $"GNU Social" \
 -                --radiolist $"Choose an operation:" 15 70 6 \
 -                1 $"Set a background image" off \
 -                2 $"Set the title" off \
 -                3 $"Set post expiry period (currently $GNUSOCIAL_EXPIRE_MONTHS months)" off \
 -                4 $"Select Qvitter user interface" off \
 -                5 $"Select Pleroma user interface" off \
 -                6 $"Exit" on 2> $data
 -         sel=$?
 -         case $sel in
 -             1) return;;
 -             255) return;;
 -         esac
 -         case $(cat $data) in
 -             1) gnusocial_set_background_image;;
 -             2) gnusocial_set_title;;
 -             3) gnusocial_set_expire_months;;
 -             4) gnusocial_use_qvitter gnusocial;;
 -             5) gnusocial_use_pleroma gnusocial;;
 -             6) break;;
 -         esac
 -     done
 - }
 - 
 - function upgrade_gnusocial {
 -     if grep -q "gnusocial domain" $COMPLETION_FILE; then
 -         GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -     fi
 - 
 -     # update to the next commit
 -     function_check set_repo_commit
 -     set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs "gnusocial commit" "$GNUSOCIAL_COMMIT" $GNUSOCIAL_REPO
 - 
 -     gnusocial_fix_endless_reloads
 - 
 -     # Ensure that installation script is removed
 -     if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/install.php ]; then
 -         rm /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/install.php
 -     fi
 - 
 -     if [ -d $INSTALL_DIR/pleroma ]; then
 -         if [ -f /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index.php ]; then
 -             mv /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index.php /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index_qvitter.php
 -         fi
 -     fi
 - 
 -     gnusocial_block_user_script
 -     gnusocial_block_domain_script gnusocial
 - 
 -     gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
 -     upgrade_pleroma "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
 -     install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
 -     chown -R www-data:www-data /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
 - }
 - 
 - 
 - function backup_local_gnusocial {
 -     GNUSOCIAL_DOMAIN_NAME='gnusocial'
 -     if grep -q "gnusocial domain" $COMPLETION_FILE; then
 -         GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -     fi
 - 
 -     source_directory=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
 -     if [ -d $source_directory ]; then
 -         dest_directory=gnusocial
 -         function_check suspend_site
 -         suspend_site ${GNUSOCIAL_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 gnusocial
 - 
 -         function_check restart_site
 -         restart_site
 -     fi
 - }
 - 
 - function restore_local_gnusocial {
 -     if ! grep -q "gnusocial domain" $COMPLETION_FILE; then
 -         return
 -     fi
 -     GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -     if [ $GNUSOCIAL_DOMAIN_NAME ]; then
 -         echo $"Restoring gnusocial"
 -         temp_restore_dir=/root/tempgnusocial
 -         gnusocial_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
 -         # stop the daemons
 -         cd $gnusocial_dir
 -         scripts/stopdaemons.sh
 - 
 -         function_check gnusocial_create_database
 -         gnusocial_create_database
 - 
 -         restore_database gnusocial ${GNUSOCIAL_DOMAIN_NAME}
 -         if [ -d $temp_restore_dir ]; then
 -             rm -rf $temp_restore_dir
 -         fi
 - 
 -         # start the daemons
 -         cd $gnusocial_dir
 -         scripts/startdaemons.sh
 -         echo $"Restore of gnusocial complete"
 -     fi
 - }
 - 
 - function backup_remote_gnusocial {
 -     if grep -q "gnusocial domain" $COMPLETION_FILE; then
 -         GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 -         temp_backup_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
 -         if [ -d $temp_backup_dir ]; then
 -             function_check suspend_site
 -             suspend_site ${GNUSOCIAL_DOMAIN_NAME}
 - 
 -             function_check backup_database_to_friend
 -             backup_database_to_friend gnusocial
 - 
 -             echo $"Backing up GNU social installation"
 - 
 -             function_check backup_directory_to_friend
 -             backup_directory_to_friend $temp_backup_dir gnusocial
 - 
 -             function_check restart_site
 -             restart_site
 -         else
 -             echo $"gnusocial domain specified but not found in ${temp_backup_dir}"
 -         fi
 -     fi
 - }
 - 
 - function restore_remote_gnusocial {
 -     if grep -q "gnusocial domain" $COMPLETION_FILE; then
 -         echo $"Restoring gnusocial"
 -         GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
 - 
 -         # stop the daemons
 -         cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
 -         ./scripts/stopdaemons.sh
 - 
 -         function_check gnusocial_create_database
 -         gnusocial_create_database
 - 
 -         function_check restore_database_from_friend
 -         restore_database_from_friend gnusocial ${GNUSOCIAL_DOMAIN_NAME}
 -         if [ -d /root/tempgnusocial ]; then
 -             rm -rf /root/tempgnusocial
 -         fi
 - 
 -         # start the daemons
 -         cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
 -         ./scripts/startdaemons.sh
 -         echo $"Restore of gnusocial complete"
 -     fi
 - }
 - 
 - function remove_gnusocial {
 -     if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
 -         return
 -     fi
 -     function_check remove_nodejs
 -     remove_nodejs pleroma-gnusocial
 - 
 -     read_config_param "GNUSOCIAL_DOMAIN_NAME"
 -     read_config_param "MY_USERNAME"
 -     echo "Removing $GNUSOCIAL_DOMAIN_NAME"
 -     nginx_dissite $GNUSOCIAL_DOMAIN_NAME
 -     remove_certs $GNUSOCIAL_DOMAIN_NAME
 -     if [ -f /etc/cron.hourly/gnusocial-daemons ]; then
 -         rm /etc/cron.hourly/gnusocial-daemons
 -     fi
 -     if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
 -         cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts
 -         ./scripts/stopdaemons.sh
 -     fi
 -     kill_pid=$(ps aux | grep /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/queuedaemon.php | awk -F ' ' '{print $2}' | head -n 1)
 -     kill -9 $kill_pid
 - 
 -     if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
 -         rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
 -     fi
 -     if [ -f /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME ]; then
 -         rm /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
 -     fi
 -     function_check drop_database
 -     drop_database gnusocial
 -     function_check remove_onion_service
 -     remove_onion_service gnusocial ${GNUSOCIAL_ONION_PORT}
 -     if grep -q "gnusocial" /etc/crontab; then
 -         sed -i "/gnusocial/d" /etc/crontab
 -     fi
 -     remove_app gnusocial
 -     remove_completion_param install_gnusocial
 -     sed -i '/gnusocial/d' $COMPLETION_FILE
 -     remove_backup_database_local gnusocial
 - 
 -     sed -i '/gnusocial-firewall/d' /etc/crontab
 - 
 -     function_check remove_ddns_domain
 -     remove_ddns_domain $GNUSOCIAL_DOMAIN_NAME
 - }
 - 
 - function install_gnusocial_main {
 -     if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
 -         echo $'No domain name was given for gnusocial'
 -         exit 7359
 -     fi
 - 
 -     if [[ $(app_is_installed gnusocial_main) == "1" ]]; then
 -         return
 -     fi
 - 
 -     gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
 - 
 -     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/$GNUSOCIAL_DOMAIN_NAME ]; then
 -         mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME
 -     fi
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
 -         function_check git_clone
 -         git_clone $GNUSOCIAL_REPO /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -         if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
 -             echo $'Unable to clone gnusocial repo'
 -             exit 87525
 -         fi
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     git checkout $GNUSOCIAL_COMMIT -b $GNUSOCIAL_COMMIT
 -     set_completion_param "gnusocial commit" "$GNUSOCIAL_COMMIT"
 - 
 -     gnusocial_fix_endless_reloads
 - 
 -     chmod g+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/avatar
 -     chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/file
 -     chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     chmod +x /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php
 - 
 -     function_check gnusocial_create_database
 -     gnusocial_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/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
 -         echo "*: /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
 -     fi
 - 
 -     function_check add_ddns_domain
 -     add_ddns_domain $GNUSOCIAL_DOMAIN_NAME
 - 
 -     gnusocial_nginx_site=/etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
 -     if [[ $ONION_ONLY == "no" ]]; then
 -         function_check nginx_http_redirect
 -         nginx_http_redirect $GNUSOCIAL_DOMAIN_NAME "index index.php"
 -         echo 'server {' >> $gnusocial_nginx_site
 -         echo '  listen 443 ssl;' >> $gnusocial_nginx_site
 -         echo '  listen [::]:443 ssl;' >> $gnusocial_nginx_site
 -         echo "  server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Security' >> $gnusocial_nginx_site
 -         function_check nginx_ssl
 -         nginx_ssl $GNUSOCIAL_DOMAIN_NAME
 - 
 -         function_check nginx_disable_sniffing
 -         nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
 - 
 -         echo '  add_header Strict-Transport-Security max-age=15768000;' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Logs' >> $gnusocial_nginx_site
 -         echo '  access_log /dev/null;' >> $gnusocial_nginx_site
 -         echo '  error_log /dev/null;' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Root' >> $gnusocial_nginx_site
 -         echo "  root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Index' >> $gnusocial_nginx_site
 -         echo '  index index.php;' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # PHP' >> $gnusocial_nginx_site
 -         echo '  location ~ \.php {' >> $gnusocial_nginx_site
 -         echo '    include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
 -         echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
 -         echo '  }' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Location' >> $gnusocial_nginx_site
 -         echo '  location / {' >> $gnusocial_nginx_site
 -         function_check nginx_limits
 -         nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
 -         echo '    try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
 -         echo '  }' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Fancy URLs' >> $gnusocial_nginx_site
 -         echo '  location @gnusocial {' >> $gnusocial_nginx_site
 -         echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
 -         echo '  }' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         echo '  # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
 -         echo '  location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
 -         echo '    deny all;' >> $gnusocial_nginx_site
 -         echo '  }' >> $gnusocial_nginx_site
 -         echo '' >> $gnusocial_nginx_site
 -         # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
 -         echo '}' >> $gnusocial_nginx_site
 -     else
 -         echo -n '' > $gnusocial_nginx_site
 -     fi
 -     echo 'server {' >> $gnusocial_nginx_site
 -     echo "    listen 127.0.0.1:$GNUSOCIAL_ONION_PORT default_server;" >> $gnusocial_nginx_site
 -     echo "    server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     function_check nginx_disable_sniffing
 -     nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # Logs' >> $gnusocial_nginx_site
 -     echo '  access_log /dev/null;' >> $gnusocial_nginx_site
 -     echo '  error_log /dev/null;' >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # Root' >> $gnusocial_nginx_site
 -     echo "  root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # Index' >> $gnusocial_nginx_site
 -     echo '  index index.php;' >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # PHP' >> $gnusocial_nginx_site
 -     echo '  location ~ \.php {' >> $gnusocial_nginx_site
 -     echo '    include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
 -     echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
 -     echo '  }' >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # Location' >> $gnusocial_nginx_site
 -     echo '  location / {' >> $gnusocial_nginx_site
 -     function_check nginx_limits
 -     nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
 -     echo '    try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
 -     echo '  }' >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # Fancy URLs' >> $gnusocial_nginx_site
 -     echo '  location @gnusocial {' >> $gnusocial_nginx_site
 -     echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
 -     echo '  }' >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     echo '  # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
 -     echo '  location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
 -     echo '    deny all;' >> $gnusocial_nginx_site
 -     echo '  }' >> $gnusocial_nginx_site
 -     echo '' >> $gnusocial_nginx_site
 -     # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
 -     echo '}' >> $gnusocial_nginx_site
 - 
 -     function_check configure_php
 -     configure_php
 - 
 -     function_check create_site_certificate
 -     create_site_certificate $GNUSOCIAL_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 gnusocial
 - 
 -     function_check nginx_ensite
 -     nginx_ensite $GNUSOCIAL_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 gnusocial
 -     gnusocial_ssl='always'
 -     if [[ $ONION_ONLY != 'no' ]]; then
 -         gnusocial_ssl='never'
 -     fi
 - 
 -     GNUSOCIAL_ONION_HOSTNAME=$(add_onion_service gnusocial 80 ${GNUSOCIAL_ONION_PORT})
 - 
 -     GNUSOCIAL_SERVER=${GNUSOCIAL_DOMAIN_NAME}
 -     if [[ $ONION_ONLY != 'no' ]]; then
 -         GNUSOCIAL_SERVER=${GNUSOCIAL_ONION_HOSTNAME}
 -     fi
 - 
 -     # Create the configuration
 -     gnusocial_installer=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts/install_cli.php
 -     if [ ! -f $gnusocial_installer ]; then
 -         rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
 -         echo $'No gnusocial commandline installer found'
 -         exit 53026
 -     fi
 -     ${gnusocial_installer} --server "${GNUSOCIAL_SERVER}" \
 -                            --host="localhost" --database="gnusocial" \
 -                            --dbtype=mysql --username="root" -v \
 -                            --password="$MARIADB_PASSWORD" \
 -                            --sitename=$"GNU Social" --fancy='yes' \
 -                            --admin-nick="$MY_USERNAME" \
 -                            --admin-pass="$GNUSOCIAL_ADMIN_PASSWORD" \
 -                            --site-profile="community" \
 -                            --ssl=${gnusocial_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 GNU Social'
 -     #    exit 72357
 -     #fi
 - 
 -     # check gnusocial has a config file
 -     gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
 -     if [ ! -f $gnusocial_config_file ]; then
 -         drop_database gnusocial
 -         rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
 -         echo $'Gnusocial config.php not found'
 -         exit 87586
 -     fi
 - 
 -     # Some useful settings
 -     if ! grep -q "Recommended GNU social settings" $gnusocial_config_file; then
 -         echo "" >> $gnusocial_config_file
 -         echo "// Recommended GNU social settings" >> $gnusocial_config_file
 -         echo "\$config['thumbnail']['maxsize'] = 3000;" >> $gnusocial_config_file
 -         echo "\$config['profile']['delete'] = true;" >> $gnusocial_config_file
 -         echo "\$config['profile']['changenick'] = true;" >> $gnusocial_config_file
 -         echo "\$config['public']['localonly'] = false;" >> $gnusocial_config_file
 -         echo "addPlugin('StoreRemoteMedia');" >> $gnusocial_config_file
 -         echo "\$config['queue']['enabled'] = true;" >> $gnusocial_config_file
 -         echo "\$config['queue']['daemon'] = true;" >> $gnusocial_config_file
 -         echo "\$config['ostatus']['hub_retries'] = 3;" >> $gnusocial_config_file
 -     fi
 - 
 -     # turn off logging
 -     echo "\$config['site']['logfile'] = '/dev/null';" >> $gnusocial_config_file
 -     echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $gnusocial_config_file
 - 
 -     # This improves performance
 -     sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $gnusocial_config_file
 - 
 -     systemctl restart php5-fpm
 -     systemctl restart nginx
 - 
 -     ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
 - 
 -     ${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
 -     gnusocial_block_user_script
 -     gnusocial_block_domain_script gnusocial
 - 
 -     set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"
 - 
 -     install_completed gnusocial_main
 - }
 - 
 - function install_gnusocial_plugin_sharings {
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
 -         echo $'No local/plugins directory found for the gnusocial'
 -         exit 72945
 -     fi
 - 
 -     apt-get -yq install liblocale-msgfmt-perl gettext
 - 
 -     # update to the next commit
 -     function_check set_repo_commit
 -     set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
 - 
 -     if [[ $(app_is_installed gnusocial_plugin_sharings) == "1" ]]; then
 -         return
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
 -     function_check git_clone
 -     git_clone $SHARINGS_REPO Sharings
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
 -         echo $'Unable to clone gnusocial sharings plugin'
 -         exit 36738
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
 -     git stash
 -     git checkout master
 -     git branch -D $SHARINGS_COMMIT
 -     git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
 - 
 -     # enable the plugin
 -     if ! grep -q "addPlugin('Sharings');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
 -         echo "addPlugin('Sharings');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     php scripts/checkschema.php
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
 -     php scripts/seedsharings.php
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     php scripts/upgrade.php
 -     php scripts/checkschema.php
 - 
 -     # Languages
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
 -     msgfmt -o Sharings.mo Sharings.po
 -     if [ ! -f Sharings.po ]; then
 -         echo $'English translations for gnusocial sharings plugin were not created'
 -         exit 84352
 -     fi
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
 -     msgfmt -o Sharings.mo Sharings.po
 -     if [ ! -f Sharings.po ]; then
 -         echo $'English (GB) translations for gnusocial sharings plugin were not created'
 -         exit 84352
 -     fi
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
 -     msgfmt -o Sharings.mo Sharings.po
 -     if [ ! -f Sharings.po ]; then
 -         echo $'English (US) translations for gnusocial sharings plugin were not created'
 -         exit 84352
 -     fi
 - 
 -     # Looks like this update function isn't supported by the current php version
 -     sed -i 's|ActivityVerb::UPDATE, ||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/SharingsPlugin.php
 - 
 -     chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 - 
 -     set_completion_param gnusocial "sharings plugin commit" "$SHARINGS_COMMIT"
 -     install_completed gnusocial_plugin_sharings
 - }
 - 
 - function install_gnusocial_plugin_sharings_theme {
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
 -         echo $'No local/plugins directory found for the gnusocial'
 -         exit 74458
 -     fi
 - 
 -     # update to the next commit
 -     function_check set_repo_commit
 -     set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
 - 
 -     if [[ $(app_is_installed gnusocial_plugin_sharings_theme) == "1" ]]; then
 -         return
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
 -     function_check git_clone
 -     git_clone $SHARINGS_THEME_REPO SharingsTheme
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
 -         echo $'Unable to clone gnusocial sharings plugin theme'
 -         exit 639253
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
 -     git stash
 -     git checkout master
 -     git branch -D $SHARINGS_THEME_COMMIT
 -     git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
 - 
 -     # enable the plugin
 -     if ! grep -q "addPlugin('SharingsTheme');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
 -         echo "addPlugin('SharingsTheme');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     php scripts/checkschema.php
 - 
 -     chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 - 
 -     set_completion_param "gnusocial sharings plugin theme commit" "$SHARINGS_THEME_COMMIT"
 -     install_completed gnusocial_plugin_sharings_theme
 - }
 - 
 - function install_gnusocial_markdown {
 -     GNUSOCIAL_PATH=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 - 
 -     # update to the next commit
 -     function_check set_repo_commit
 -     set_repo_commit $GNUSOCIAL_PATH/local/plugins/Markdown "gnusocial Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" $GNUSOCIAL_MARKDOWN_REPO
 - 
 -     if [[ $(app_is_installed gnusocial_markdown) == "1" ]]; then
 -         return
 -     fi
 - 
 -     if [ -d $GNUSOCIAL_PATH/local/plugins/Markdown ]; then
 -         rm -rf $GNUSOCIAL_PATH/local/plugins/Markdown
 -     fi
 - 
 -     if [ ! -d $GNUSOCIAL_PATH/local/plugins ]; then
 -         mkdir -p $GNUSOCIAL_PATH/local/plugins
 -     fi
 - 
 -     cd $GNUSOCIAL_PATH/local/plugins
 -     function_check git_clone
 -     git_clone $GNUSOCIAL_MARKDOWN_REPO Markdown
 -     cd $GNUSOCIAL_PATH/local/plugins/Markdown
 -     git checkout $GNUSOCIAL_MARKDOWN_COMMIT -b $GNUSOCIAL_MARKDOWN_COMMIT
 - 
 -     gnusocial_config_file=$GNUSOCIAL_PATH/config.php
 -     if ! grep -q "addPlugin('Markdown'" $gnusocial_config_file; then
 -         echo "" >> $gnusocial_config_file
 -         echo "// Markdown settings" >> $gnusocial_config_file
 -         echo "addPlugin('Markdown');" >> $gnusocial_config_file
 -     fi
 - 
 -     set_completion_param "gnusocial markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT"
 - 
 -     chown -R www-data:www-data $GNUSOCIAL_PATH
 - 
 -     install_completed gnusocial_markdown
 - }
 - 
 - function install_gnusocial_plugin_nsfw {
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
 -         echo $'No local/plugins directory found for the gnusocial'
 -         exit 37252
 -     fi
 - 
 -     # update to the next commit
 -     function_check set_repo_commit
 -     set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT" $GNUSOCIAL_NSFW_REPO
 - 
 -     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
 -         return
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
 -     function_check git_clone
 -     git_clone $GNUSOCIAL_NSFW_REPO SensitiveContent
 -     if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent ]; then
 -         echo $'Unable to clone gnusocial NSFW plugin'
 -         exit 36738
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent
 -     git stash
 -     git checkout master
 -     git branch -D $GNUSOCIAL_NSFW_COMMIT
 -     git checkout $GNUSOCIAL_NSFW_COMMIT -b $GNUSOCIAL_NSFW_COMMIT
 - 
 -     # enable the plugin
 -     if ! grep -q "addPlugin('SensitiveContent');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
 -         echo "addPlugin('SensitiveContent');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
 -     fi
 - 
 -     cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 -     php scripts/checkschema.php
 - 
 -     chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
 - 
 -     set_completion_param "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT"
 -     install_completed gnusocial_plugin_nsfw
 - }
 - 
 - function install_gnusocial {
 -     if [ ! $ONION_ONLY ]; then
 -         ONION_ONLY='no'
 -     fi
 - 
 -     install_gnusocial_main
 -     expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
 -     install_qvitter "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
 -     install_gnusocial_markdown
 -     #install_gnusocial_plugin_sharings
 -     #install_gnusocial_plugin_sharings_theme
 -     #install_gnusocial_plugin_nsfw
 - 
 -     # 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_front_end "gnusocial" "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
 -         install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
 -         sed -i 's|"theme":.*|"theme": "base16-apathy.css",|g' /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/static/config.json
 -     fi
 - 
 -     # unleash the daemons!
 -     /etc/cron.hourly/gnusocial-daemons
 - 
 -     systemctl restart nginx
 - 
 -     APP_INSTALLED=1
 - }
 - 
 - # NOTE: deliberately there is no "exit 0"
 
 
  |