#!/bin/bash # # _____ _ _ # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___ # | __| _| -_| -_| . | . | | . | . | | -_| # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___| # # Freedom in the Cloud # # License # ======= # # Copyright (C) 2018 Bob Mottram # # 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 . VARIANTS='full full-vim' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 SHOW_ICANN_ADDRESS_ON_ABOUT=0 SMOLRSS_DOMAIN_NAME= SMOLRSS_CODE= SMOLRSS_ONION_PORT=8751 SMOLRSS_REPO="https://code.freedombone.net/bashrc/smolrss" SMOLRSS_COMMIT='a0e80ab89098028bc5ac77466b46ab8491ef0773' smolrss_variables=(ONION_ONLY SMOLRSS_DOMAIN_NAME SMOLRSS_CODE DDNS_PROVIDER MY_USERNAME) function logging_on_smolrss { echo -n '' } function logging_off_smolrss { echo -n '' } function remove_user_smolrss { #remove_username="$1" echo -n '' } function add_user_smolrss { #new_username="$1" #new_user_password="$2" echo '0' } function install_interactive_smolrss { echo -n '' APP_INSTALLED=1 } function change_password_smolrss { #curr_username="$1" #new_user_password="$2" echo -n '' } function reconfigure_smolrss { # This is used if you need to switch identity. Dump old keys and generate new ones echo -n '' } function smolrss_add_feed { data=$(mktemp 2>/dev/null) dialog --backtitle $"Smol RSS" \ --title $"Add an RSS feed" \ --form "\\n" 8 60 3 \ $"Title:" 1 1 "" 1 12 40 256 \ $"Feed URL:" 2 1 "" 2 12 40 10000 \ 2> "$data" sel=$? case $sel in 1) rm -f "$data" return;; 255) rm -f "$data" return;; esac title=$(sed -n 1p < "$data") url=$(sed -n 2p < "$data") rm -f "$data" if [ ! "$title" ]; then return fi if [ ! "$url" ]; then return fi if [[ "$url" == *','* ]]; then return fi if [[ "$url" != *'.'* ]]; then return fi cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || return if grep -q "${title}," feeds.txt; then sed -i "s|${title},.*|${title},${url}|g" feeds.txt else echo "${title},${url}" >> feeds.txt fi ./create_feeds feeds.txt > feeds.xml chown www-data:www-data feeds.txt dialog --title $"Add an RSS feed" \ --msgbox $"${title} has been added" 6 70 } function smolrss_remove_feed { data=$(mktemp 2>/dev/null) dialog --title $"Remove an RSS feed" \ --backtitle $"Smol RSS" \ --inputbox $"Enter the title of the feed to remove" 8 60 2>"$data" sel=$? case $sel in 0) title=$(<"$data") if [ "$title" ]; then cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || return if grep -q "${title}," feeds.txt; then sed -i "/${title},/d" feeds.xml ./create_feeds feeds.txt > feeds.xml chown www-data:www-data feeds.txt dialog --title $"Remove an RSS feed" \ --msgbox $"${title} has been removed" 6 70 fi fi ;; esac rm -f "$data" } function configure_interactive_smolrss { W=(1 $"Add an RSS feed" 2 $"Remove an RSS feed" 3 $'Edit all feeds' 4 $'Light theme' 5 $'Dark theme') read_config_param SMOLRSS_DOMAIN_NAME while true do # shellcheck disable=SC2068 selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Smol RSS" --menu $"Choose an operation, or ESC for main menu:" 14 70 5 "${W[@]}" 3>&2 2>&1 1>&3) if [ ! "$selection" ]; then break fi case $selection in 1) smolrss_add_feed ;; 2) smolrss_remove_feed ;; 3) editor "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs/feeds.txt" cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || break ./create_feeds feeds.txt > feeds.xml chown www-data:www-data feeds.txt ;; 4) cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || break cp style.light.css style.css chown www-data:www-data style.css dialog --title $"Smol RSS theme" \ --msgbox $"Switched theme to light" 6 50 ;; 5) cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || break cp style.dark.css style.css chown www-data:www-data style.css dialog --title $"Smol RSS theme" \ --msgbox $"Switched theme to dark" 6 50 ;; esac done } function upgrade_smolrss { CURR_SMOLRSS_COMMIT=$(get_completion_param "smolrss commit") if [[ "$CURR_SMOLRSS_COMMIT" == "$SMOLRSS_COMMIT" ]]; then return fi if grep -q "smolrss domain" "$COMPLETION_FILE"; then SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain") fi # update to the next commit set_repo_commit "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" "smolrss commit" "$SMOLRSS_COMMIT" "$SMOLRSS_REPO" cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || return ./create_feeds feeds.txt > feeds.xml chown -R www-data:www-data "/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs" } function backup_local_smolrss { SMOLRSS_DOMAIN_NAME='smolrss' if grep -q "smolrss domain" "$COMPLETION_FILE"; then SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain") fi source_directory=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs suspend_site "${SMOLRSS_DOMAIN_NAME}" dest_directory=smolrss backup_directory_to_usb "$source_directory" $dest_directory restart_site } function restore_local_smolrss { if ! grep -q "smolrss domain" "$COMPLETION_FILE"; then return fi SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain") if [ ! "$SMOLRSS_DOMAIN_NAME" ]; then return fi suspend_site "${SMOLRSS_DOMAIN_NAME}" temp_restore_dir=/root/tempsmolrss smolrss_dir=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs restore_directory_from_usb $temp_restore_dir smolrss if [ -d $temp_restore_dir ]; then if [ -d "$temp_restore_dir$smolrss_dir" ]; then cp -rp "$temp_restore_dir$smolrss_dir"/* "$smolrss_dir"/ else if [ ! -d "$smolrss_dir" ]; then mkdir "$smolrss_dir" fi cp -rp "$temp_restore_dir"/* "$smolrss_dir"/ fi chown -R www-data:www-data "$smolrss_dir" rm -rf $temp_restore_dir fi restart_site } function backup_remote_smolrss { SMOLRSS_DOMAIN_NAME='smolrss' if grep -q "smolrss domain" "$COMPLETION_FILE"; then SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain") fi source_directory=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs suspend_site "${SMOLRSS_DOMAIN_NAME}" dest_directory=smolrss backup_directory_to_friend "$source_directory" $dest_directory restart_site } function restore_remote_smolrss { if ! grep -q "smolrss domain" "$COMPLETION_FILE"; then return fi SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain") if [ ! "$SMOLRSS_DOMAIN_NAME" ]; then return fi suspend_site "${SMOLRSS_DOMAIN_NAME}" temp_restore_dir=/root/tempsmolrss smolrss_dir=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs restore_directory_from_friend $temp_restore_dir smolrss if [ -d $temp_restore_dir ]; then if [ -d "$temp_restore_dir$smolrss_dir" ]; then cp -rp "$temp_restore_dir$smolrss_dir"/* "$smolrss_dir"/ else if [ ! -d "$smolrss_dir" ]; then mkdir "$smolrss_dir" fi cp -rp $temp_restore_dir/* "$smolrss_dir"/ fi chown -R www-data:www-data "$smolrss_dir" rm -rf $temp_restore_dir fi restart_site } function remove_smolrss { nginx_dissite "$SMOLRSS_DOMAIN_NAME" remove_certs "$SMOLRSS_DOMAIN_NAME" if [ -d "/var/www/$SMOLRSS_DOMAIN_NAME" ]; then rm -rf "/var/www/$SMOLRSS_DOMAIN_NAME" fi if [ -f "/etc/nginx/sites-available/$SMOLRSS_DOMAIN_NAME" ]; then rm "/etc/nginx/sites-available/$SMOLRSS_DOMAIN_NAME" fi remove_onion_service smolrss "${SMOLRSS_ONION_PORT}" if grep -q "smolrss" /etc/crontab; then sed -i "/smolrss/d" /etc/crontab fi remove_app smolrss remove_completion_param install_smolrss sed -i '/smolrss/d' "$COMPLETION_FILE" remove_ddns_domain "$SMOLRSS_DOMAIN_NAME" } function install_smolrss { apt-get -yq install php-gettext php-curl php-gd php-mysql git curl apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl SMOLRSS_DOMAIN_NAME='smolrss.local' if [ -d "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" ]; then rm -rf "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" fi if [ -d /repos/smolrss ]; then mkdir "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" cp -r -p /repos/smolrss/. "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || exit 324687356 git pull else git_clone "$SMOLRSS_REPO" "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" fi if [ ! -d "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" ]; then echo $'Unable to clone smolrss repo' exit 87525 fi cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || exit 36587356 git checkout "$SMOLRSS_COMMIT" -b "$SMOLRSS_COMMIT" set_completion_param "smolrss commit" "$SMOLRSS_COMMIT" cp feeds.example.txt feeds.txt ./create_feeds feeds.txt > feeds.xml chmod g+w "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" chown -R www-data:www-data "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" add_ddns_domain "$SMOLRSS_DOMAIN_NAME" SMOLRSS_ONION_HOSTNAME=$(add_onion_service smolrss 80 "${SMOLRSS_ONION_PORT}") smolrss_nginx_site=/etc/nginx/sites-available/$SMOLRSS_DOMAIN_NAME echo -n '' > "$smolrss_nginx_site" { echo 'server {'; echo " listen 127.0.0.1:$SMOLRSS_ONION_PORT default_server;"; echo " server_name $SMOLRSS_ONION_HOSTNAME;"; echo ''; } >> "$smolrss_nginx_site" nginx_compress "$SMOLRSS_DOMAIN_NAME" echo '' >> "$smolrss_nginx_site" nginx_security_options "$SMOLRSS_DOMAIN_NAME" { echo ''; echo ' access_log /dev/null;'; echo ' error_log /dev/null;'; echo ''; echo " root /var/www/$SMOLRSS_DOMAIN_NAME/htdocs;"; echo ''; echo ' index index.php;'; echo ' location ~ \.php {'; echo ' include snippets/fastcgi-php.conf;'; echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;'; echo ' fastcgi_read_timeout 30;'; echo ' fastcgi_param HTTPS off;'; echo ' }'; echo ''; echo ' # Location'; echo ' location / {'; } >> "$smolrss_nginx_site" nginx_limits "$SMOLRSS_DOMAIN_NAME" '15m' { echo " try_files \$uri \$uri/ index.php?\$args;"; echo ' }'; echo '}'; } >> "$smolrss_nginx_site" configure_php nginx_ensite "$SMOLRSS_DOMAIN_NAME" systemctl restart php7.0-fpm systemctl restart nginx "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a smolrss -p "$SMOLRSS_ADMIN_PASSWORD" set_completion_param "smolrss domain" "$SMOLRSS_DOMAIN_NAME" APP_INSTALLED=1 } # NOTE: deliberately there is no "exit 0"