freedombone/src/freedombone-app-radicale

590 lines
21 KiB
Plaintext
Raw Normal View History

2016-11-08 23:13:50 +01:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-11-08 23:13:50 +01:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-11-08 23:13:50 +01:00
#
# Radicale calendar system
#
# Configuration based upon:
# https://gigacog.com/blog/2016/01/radicale-and-uwsgi-on-nginx-with-systemd
#
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net>
2016-11-08 23:13:50 +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/>.
2017-06-25 22:58:21 +02:00
VARIANTS=''
2016-11-08 23:13:50 +01:00
IN_DEFAULT_INSTALL=0
2016-11-08 23:13:50 +01:00
SHOW_ON_ABOUT=1
2017-05-11 17:07:52 +02:00
RADICALE_DOWNLOAD_URL='https://files.pythonhosted.org/packages/source/R/Radicale/Radicale-'
RADICALE_VERSION='1.1.2'
RADICALE_HASH='ebe22afb7fdcac45a5722a5b3037cc4bf261fc059beba31af7863894d2b840bc'
2016-11-08 23:13:50 +01:00
RADICALE_PASSWORD=
RADICALE_ONION_PORT=8106
RADICALE_PORT=5232
RADICALE_DIRECTORY='/etc/radicale'
2016-11-16 19:56:37 +01:00
RADICALE_USERS=/var/www/radicale/users
2016-11-08 23:13:50 +01:00
radicale_variables=(ONION_ONLY
MY_USERNAME
RADICALE_PASSWORD
DEFAULT_DOMAIN_NAME)
function logging_on_radicale {
echo -n ''
}
function logging_off_radicale {
echo -n ''
}
2016-11-08 23:13:50 +01:00
function remove_user_radicale {
remove_username="$1"
2016-11-19 20:17:33 +01:00
2018-03-01 00:17:49 +01:00
"${PROJECT_NAME}-pass" -u "$remove_username" --rmapp radicale
2016-11-19 20:17:33 +01:00
2017-05-11 17:19:41 +02:00
if grep -q "${remove_username}:" ${RADICALE_USERS}; then
2016-11-17 10:46:37 +01:00
sed -i "/${remove_username}:/d" ${RADICALE_USERS}
2018-03-01 00:17:49 +01:00
if [ -d "/var/www/radicale/collections/${remove_username}" ]; then
rm -rf "/var/www/radicale/collections/${remove_username}"
2016-11-17 00:55:51 +01:00
fi
2018-03-01 00:17:49 +01:00
if [ -f "/var/www/radicale/collections/${remove_username}.props" ]; then
rm "/var/www/radicale/collections/${remove_username}.props"
2016-11-17 00:55:51 +01:00
fi
2016-11-17 16:15:10 +01:00
systemctl restart radicale
2016-11-08 23:13:50 +01:00
fi
}
function add_user_radicale {
new_username="$1"
new_user_password="$2"
2018-03-01 00:17:49 +01:00
"${PROJECT_NAME}-pass" -u "$new_username" -a radicale -p "$new_user_password"
2016-11-19 20:17:33 +01:00
2016-11-16 19:56:37 +01:00
if [ ! -f ${RADICALE_USERS} ]; then
touch ${RADICALE_USERS}
2016-11-16 12:39:26 +01:00
fi
2017-05-11 17:19:41 +02:00
if ! grep -q "$new_username:" ${RADICALE_USERS}; then
2016-11-16 19:56:37 +01:00
htpasswd -bd ${RADICALE_USERS} "$new_username" "$new_user_password"
2016-11-17 00:55:51 +01:00
2018-03-01 00:17:49 +01:00
echo '{"ICAL:calendar-color": "#9e50df"}' > "/var/www/radicale/collections/${new_username}.props"
mkdir "/var/www/radicale/collections/${new_username}"
echo '{"ICAL:calendar-color": "#de631a", "tag": "VCALENDAR"}' > "/var/www/radicale/collections/${new_username}/calendar.props"
{ echo 'BEGIN:VCALENDAR';
echo 'PRODID:-//Radicale//NONSGML Radicale Server//EN';
echo 'VERSION:2.0';
echo 'END:VCALENDAR'; } >> "/var/www/radicale/collections/${new_username}/calendar"
2016-11-17 16:15:10 +01:00
2016-11-17 00:55:51 +01:00
chown -R www-data:www-data /var/www/radicale
2016-11-17 16:15:10 +01:00
chmod -R 755 /var/www/radicale/*
systemctl restart radicale
2016-11-08 23:13:50 +01:00
fi
echo '0'
}
2016-11-17 10:46:37 +01:00
function change_password_radicale {
existing_username="$1"
new_user_password="$2"
2018-03-01 00:17:49 +01:00
"${PROJECT_NAME}-pass" -u "$existing_username" -a radicale -p "$new_user_password"
2016-11-19 20:17:33 +01:00
2017-05-11 17:19:41 +02:00
if grep -q "${existing_username}:" ${RADICALE_USERS}; then
2016-11-17 10:46:37 +01:00
sed -i "/${existing_username}:/d" ${RADICALE_USERS}
htpasswd -bd ${RADICALE_USERS} "$existing_username" "$new_user_password"
systemctl reload radicale
fi
2016-11-08 23:13:50 +01:00
}
2016-11-17 10:46:37 +01:00
function install_interactive_radicale {
2016-11-08 23:13:50 +01:00
echo -n ''
2016-11-17 10:46:37 +01:00
APP_INSTALLED=1
2016-11-08 23:13:50 +01:00
}
function reconfigure_radicale {
2016-11-17 11:47:20 +01:00
rm $RADICALE_USERS
rm -rf /var/www/radicale/collections/*
rm -rf /var/log/radicale/*
# create an admin password
2018-03-01 00:17:49 +01:00
if [ -f "$IMAGE_PASSWORD_FILE" ]; then
RADICALE_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
2016-11-17 11:47:20 +01:00
else
2018-03-01 00:17:49 +01:00
RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
2016-11-17 11:47:20 +01:00
fi
add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
2016-11-19 20:17:33 +01:00
2018-03-01 00:17:49 +01:00
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a radicale -p "$RADICALE_PASSWORD"
2016-11-17 11:47:20 +01:00
touch /var/log/radicale/radicale.log
chown -R www-data:www-data /var/log/radicale
2016-11-08 23:13:50 +01:00
}
function upgrade_radicale {
2016-11-17 11:20:17 +01:00
if [ ! -f /usr/local/bin/radicale ]; then
return
fi
2018-03-01 00:17:49 +01:00
if ! grep -q "radicale version:" "$COMPLETION_FILE"; then
2016-11-17 11:20:17 +01:00
return
fi
CURR_RADICALE_VERSION=$(get_completion_param "radicale version")
if [[ "${CURR_RADICALE_VERSION}" == "${RADICALE_VERSION}" ]]; then
return
fi
# get the source
2018-03-01 00:17:49 +01:00
cd /var/www/radicale || exit 62784628468
2016-11-17 11:20:17 +01:00
wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
# check the hash
hash=$(sha256sum Radicale-${RADICALE_VERSION}.tar.gz | awk -F ' ' '{print $1}')
if [[ "$hash" != "$RADICALE_HASH" ]]; then
echo $'radicale hash does not match'
exit 638532
fi
tar -xzf Radicale-${RADICALE_VERSION}.tar.gz
if [ ! -d Radicale-${RADICALE_VERSION} ]; then
exit 73529
fi
rm Radicale-${RADICALE_VERSION}.tar.gz
2018-03-01 00:17:49 +01:00
cd "Radicale-${RADICALE_VERSION}" || exit 264824684
2016-11-17 11:20:17 +01:00
# move the old command
mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
# do the install
python setup.py install
# check for install success
if [ ! -f /usr/local/bin/radicale ]; then
mv /usr/local/bin/radicale_previous /usr/local/bin/radicale
echo $'Radicale did not upgrade'
exit 692353
fi
# remove the old source
2018-03-01 00:17:49 +01:00
rm -rf "Radicale-${CURR_RADICALE_VERSION}" || exit 6842684282
2016-11-17 11:20:17 +01:00
2018-03-01 00:17:49 +01:00
sed -i "s|radicale version.*|radicale version:$RADICALE_VERSION|g" "${COMPLETION_FILE}"
2016-11-17 11:20:17 +01:00
chown -R www-data:www-data /var/www/radicale
systemctl restart radicale
2016-11-17 13:54:35 +01:00
systemctl restart nginx
2016-11-08 23:13:50 +01:00
}
function backup_local_radicale {
source_directory=${RADICALE_DIRECTORY}
if [ -d $source_directory ]; then
dest_directory=radicale
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
fi
2016-11-16 22:16:36 +01:00
source_directory=/var/www/radicale
2016-11-16 17:07:49 +01:00
if [ -d $source_directory ]; then
2016-11-16 22:17:23 +01:00
dest_directory=radicalewww
2016-11-16 17:07:49 +01:00
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
fi
2016-11-08 23:13:50 +01:00
}
function restore_local_radicale {
if [ -d ${RADICALE_DIRECTORY} ]; then
temp_restore_dir=/root/tempradicale
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir radicale
if [ -d $temp_restore_dir${RADICALE_DIRECTORY} ]; then
cp -r $temp_restore_dir${RADICALE_DIRECTORY}/* ${RADICALE_DIRECTORY}
else
cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2016-11-08 23:13:50 +01:00
if [ ! "$?" = "0" ]; then
function_check backup_unmount_drive
backup_unmount_drive
exit 46872
fi
rm -rf $temp_restore_dir
2016-11-16 17:07:49 +01:00
2016-11-16 22:17:23 +01:00
temp_restore_dir=/root/tempradicalewww
restore_directory_from_usb $temp_restore_dir radicalewww
if [ -d $temp_restore_dir/var/www/radicale ]; then
cp -r $temp_restore_dir/var/www/radicale/* /var/www/radicale
else
cp -r $temp_restore_dir/* /var/www/radicale/*
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2016-11-16 17:07:49 +01:00
if [ ! "$?" = "0" ]; then
function_check backup_unmount_drive
backup_unmount_drive
exit 367363
fi
rm -rf $temp_restore_dir
chown -R www-data:www-data /var/www/radicale
2016-11-08 23:13:50 +01:00
systemctl restart radicale
fi
}
function backup_remote_radicale {
if [ -d ${RADICALE_DIRECTORY} ]; then
echo $"Backing up the radicale settings"
backup_directory_to_friend ${RADICALE_DIRECTORY} radicale
2016-11-16 22:17:23 +01:00
backup_directory_to_friend /var/www/radicale radicalewww
2016-11-08 23:13:50 +01:00
echo $"Backup of radicale settings complete"
fi
}
function restore_remote_radicale {
if [ -d ${RADICALE_DIRECTORY} ]; then
temp_restore_dir=/root/tempradicale
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir radicale
if [ -d $temp_restore_dir${RADICALE_DIRECTORY} ]; then
cp -r $temp_restore_dir${RADICALE_DIRECTORY}/* ${RADICALE_DIRECTORY}
else
cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2016-11-08 23:13:50 +01:00
if [ ! "$?" = "0" ]; then
2016-11-16 17:07:49 +01:00
exit 236746
2016-11-08 23:13:50 +01:00
fi
rm -rf $temp_restore_dir
2016-11-16 22:17:23 +01:00
temp_restore_dir=/root/tempradicalewww
restore_directory_from_friend $temp_restore_dir radicalewww
if [ -d $temp_restore_dir/var/www/radicale ]; then
cp -r $temp_restore_dir/var/www/radicale/* /var/www/radicale
else
cp -r $temp_restore_dir/* /var/www/radicale
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2016-11-16 17:07:49 +01:00
if [ ! "$?" = "0" ]; then
exit 3674284
fi
rm -rf $temp_restore_dir
chown -R www-data:www-data /var/www/radicale
systemctl restart radicale
2016-11-08 23:13:50 +01:00
fi
}
function remove_radicale {
nginx_dissite radicale
systemctl stop radicale
systemctl stop uwsgi_rundir
systemctl disable radicale
systemctl disable uwsgi_rundir
if [ -f /etc/systemd/system/uwsgi_rundir.service ]; then
rm /etc/systemd/system/uwsgi_rundir.service
fi
if [ -f /etc/systemd/system/radicale.service ]; then
rm /etc/systemd/system/radicale.service
fi
2017-06-10 22:37:50 +02:00
systemctl daemon-reload
2016-11-08 23:13:50 +01:00
if [ -f /etc/nginx/sites-available/radicale ]; then
rm /etc/nginx/sites-available/radicale
fi
2016-11-08 23:15:32 +01:00
if [ -f /usr/local/bin/uwsgi_rundir.sh ]; then
rm /usr/local/bin/uwsgi_rundir.sh
fi
2016-11-08 23:13:50 +01:00
firewall_remove ${RADICALE_PORT} tcp
2017-06-12 12:33:54 +02:00
groupdel -f radicale
userdel -r radicale
2016-11-08 23:13:50 +01:00
function_check remove_onion_service
remove_onion_service radicale ${RADICALE_ONION_PORT}
apt-get -yq remove --purge radicale python-radicale
if [ -d ${RADICALE_DIRECTORY} ]; then
rm -rf ${RADICALE_DIRECTORY}
fi
if [ -d /var/www/radicale ]; then
rm -rf /var/www/radicale
fi
2016-11-17 13:38:46 +01:00
if [ -f /var/log/radicale/radicale.log ]; then
2016-11-15 21:02:39 +01:00
rm -rf /var/log/radicale
fi
2016-11-16 14:06:24 +01:00
if [ -d /var/log/radicale ]; then
rm -rf /var/log/radicale
fi
2016-11-30 11:23:58 +01:00
if [ -d /var/lib/radicale ]; then
rm -rf /var/lib/radicale
fi
2016-11-08 23:13:50 +01:00
remove_completion_param install_radicale
2018-03-01 00:17:49 +01:00
sed -i '/radicale/d' "$COMPLETION_FILE"
sed -i '/# Start radicale/,/# End radicale/d' "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
2016-11-16 20:44:19 +01:00
systemctl restart nginx
2016-11-08 23:13:50 +01:00
}
function install_radicale {
if [[ $ONION_ONLY == 'no' ]]; then
# obtain a cert for the default domain
2018-03-01 00:17:49 +01:00
if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "0" ]]; then
2016-11-08 23:13:50 +01:00
echo $'Obtaining certificate for the main domain'
2018-03-01 00:17:49 +01:00
create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
2016-11-08 23:13:50 +01:00
fi
fi
2016-11-16 17:07:49 +01:00
apt-get -yq remove --purge radicale python-radicale
2017-05-11 18:21:37 +02:00
useradd -c "Radicale system account" -d /var/www/radicale -m -r -g radicale radicale
usermod -a -G www-data radicale
2017-06-10 15:57:42 +02:00
groupadd radicale
2017-05-11 18:21:37 +02:00
2016-11-16 17:07:49 +01:00
# create directories
2016-11-15 21:02:39 +01:00
if [ ! -d /var/log/radicale ]; then
mkdir /var/log/radicale
fi
if [ ! -f /var/log/radicale/radicale.log ]; then
touch /var/log/radicale/radicale.log
fi
2016-11-15 21:08:19 +01:00
chown -R www-data:www-data /var/log/radicale
2016-11-15 21:02:39 +01:00
2016-11-16 19:56:37 +01:00
apt-get -yq install python-setuptools apache2-utils
2016-11-08 23:13:50 +01:00
2016-11-16 17:07:49 +01:00
if [ ! -d /var/www/radicale ]; then
mkdir -p /var/www/radicale
2016-11-08 23:13:50 +01:00
fi
2016-11-16 17:07:49 +01:00
# get the source
2018-03-01 00:17:49 +01:00
cd /var/www/radicale || exit 462874628
2016-11-17 11:20:17 +01:00
wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
2016-11-16 17:07:49 +01:00
# check the hash
hash=$(sha256sum Radicale-${RADICALE_VERSION}.tar.gz | awk -F ' ' '{print $1}')
if [[ "$hash" != "$RADICALE_HASH" ]]; then
echo $'radicale hash does not match'
exit 638532
fi
tar -xzf Radicale-${RADICALE_VERSION}.tar.gz
if [ ! -d Radicale-${RADICALE_VERSION} ]; then
exit 623252
fi
rm Radicale-${RADICALE_VERSION}.tar.gz
2018-03-01 00:17:49 +01:00
cd "Radicale-${RADICALE_VERSION}" || exit 872462842
2016-11-16 17:07:49 +01:00
python setup.py install
if [ ! -f /usr/local/bin/radicale ]; then
echo $'Radicale did not install'
exit 7283554
2016-11-08 23:13:50 +01:00
fi
2016-11-16 17:07:49 +01:00
if [ ! -d ${RADICALE_DIRECTORY} ]; then
mkdir ${RADICALE_DIRECTORY}
fi
if [ ! -d /var/www/radicale/collections ]; then
mkdir -p /var/www/radicale/collections
2016-11-08 23:13:50 +01:00
fi
2016-11-16 17:07:49 +01:00
# create the configuration
2018-03-01 00:17:49 +01:00
{ echo '[server]';
echo 'hosts=localhost:52322';
echo 'ssl = False';
echo 'daemon = False';
echo 'base_prefix=/radicale/';
echo '';
echo '[storage]';
echo 'type = filesystem';
echo "filesystem_folder = /var/www/radicale/collections";
echo '';
echo '[well-known]';
echo "caldav = '/%(user)s/caldav/'";
echo "carddav = '/%(user)s/carddav/'";
echo '';
echo '#[auth]';
echo '#imap_hostname = localhost';
echo '#imap_port = 143';
echo '#imap_ssl = False';
echo '';
echo '[logging]';
echo 'debug = False'; } > "${RADICALE_DIRECTORY}/config"
2016-11-08 23:13:50 +01:00
2016-11-16 17:07:49 +01:00
# create an admin password
2016-11-08 23:13:50 +01:00
if [ ${#RADICALE_PASSWORD} -lt 8 ]; then
2018-03-01 00:17:49 +01:00
if [ -f "$IMAGE_PASSWORD_FILE" ]; then
RADICALE_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
2016-11-08 23:13:50 +01:00
else
2018-03-01 00:17:49 +01:00
RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
2016-11-08 23:13:50 +01:00
fi
fi
add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
2018-03-01 00:17:49 +01:00
{ echo '[Unit]';
echo 'Description=Radicale CalDAV Server';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=www-data';
echo 'Group=www-data';
echo "ExecStart=/usr/local/bin/radicale --config ${RADICALE_DIRECTORY}/config";
echo 'Restart=on-failure';
echo 'RestartSec=10';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/radicale.service
2016-11-17 16:19:48 +01:00
addresses_str=$"Addresses"
echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
touch /var/www/radicale/collections/addresses
2016-11-30 11:23:58 +01:00
if [ ! -d /var/lib/radicale ]; then
mkdir /var/lib/radicale
fi
chown radicale:radicale /var/lib/radicale
2016-11-17 16:19:48 +01:00
chown -R www-data:www-data /var/www/radicale
chmod -R 755 /var/www/radicale
chown -R www-data:www-data ${RADICALE_DIRECTORY}
2016-11-08 23:13:50 +01:00
systemctl enable radicale
systemctl start radicale
2018-03-01 00:17:49 +01:00
if [ ! -f "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}" ]; then
2016-11-16 20:44:19 +01:00
# create a new site config
RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
if [[ $ONION_ONLY == 'no' ]]; then
2018-03-01 00:17:49 +01:00
{ echo 'server {';
echo " listen 443 ssl;";
echo " #listen [::]:443 ssl;";
echo ''; } > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
2016-11-16 20:44:19 +01:00
function_check nginx_ssl
2018-03-01 00:17:49 +01:00
nginx_ssl "${DEFAULT_DOMAIN_NAME}" mobile
2018-03-05 19:15:29 +01:00
function_check nginx_security_options
nginx_security_options "${DEFAULT_DOMAIN_NAME}"
2018-03-01 00:17:49 +01:00
{ echo '';
echo " server_name ${DEFAULT_DOMAIN_NAME};";
echo '';
echo ' access_log /dev/null;';
echo ' error_log /dev/null;';
echo '';
echo ' # Start radicale';
echo ' location @radicale {';
echo ' auth_basic "Radicale";';
echo ' auth_basic_user_file /var/www/radicale/users;';
echo ' proxy_pass http://localhost:52322;';
echo ' proxy_buffering off;';
echo " proxy_set_header Host \$host;";
echo " proxy_set_header X-Real-IP \$remote_addr;";
echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
echo " proxy_set_header X-Forwarded-Proto \$scheme;";
echo ' }';
echo '';
echo ' location /radicale {';
echo " try_files \$uri @radicale;";
echo ' }';
echo '';
echo ' location /.well-known/carddav {';
echo " try_files \$uri @radicale;";
echo ' }';
echo '';
echo ' location /.well-known/caldav {';
echo " try_files \$uri @radicale;";
echo ' }';
echo ' # End radicale';
echo '}';
echo ''; } >> "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
2016-11-16 20:44:19 +01:00
else
2018-03-01 00:17:49 +01:00
echo -n '' > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
2016-11-16 20:44:19 +01:00
fi
2018-03-01 00:17:49 +01:00
{ echo 'server {';
echo " listen localhost:${RADICALE_ONION_PORT} default_server;";
echo '';
echo " server_name ${RADICALE_ONION_HOSTNAME};";
echo '';
echo ' access_log /dev/null;';
echo ' error_log /dev/null;';
echo '';
echo ' # Start radicale';
echo ' location @radicale {';
echo ' auth_basic "Radicale";';
echo ' auth_basic_user_file /var/www/radicale/users;';
echo ' proxy_pass http://localhost:52322;';
echo ' proxy_buffering off;';
echo " proxy_set_header Host \$host;";
echo " proxy_set_header X-Real-IP \$remote_addr;";
echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
echo " proxy_set_header X-Forwarded-Proto \$scheme;";
echo ' }';
echo '';
echo ' location /radicale {';
echo " try_files \$uri @radicale;";
echo ' }';
echo '';
echo ' location /.well-known/carddav {';
echo " try_files \$uri @radicale;";
echo ' }';
echo '';
echo ' location /.well-known/caldav {';
echo " try_files \$uri @radicale;";
echo ' }';
echo ' # End radicale';
echo '}'; } >> "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
2016-11-16 20:44:19 +01:00
set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
2016-11-08 23:13:50 +01:00
else
2016-11-16 20:44:19 +01:00
# alter the existing site config
2018-03-01 00:17:49 +01:00
if ! grep -q "# Start radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"; then
2018-03-02 21:15:39 +01:00
sed -i "/]:443/a # Start radicale\\n location @radicale {\\n auth_basic \"Radicale\";\\n auth_basic_user_file \\/var\\/www\\/radicale\\/users;\\n proxy_pass http:\\/\\/localhost:52322;\\n proxy_buffering off;\\n proxy_set_header Host \$host;\\n proxy_set_header X-Real-IP \$remote_addr;\\n proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;\\n proxy_set_header X-Forwarded-Proto \$scheme;\\n }\\n\\n location \\/radicale {\\n try_files \$uri @radicale;\\n }\\n\\n location \\/.well-known\\/carddav {\\n try_files \$uri @radicale;\\n }\\n\\n location \\/.well-known\\/caldav {\\n try_files \$uri @radicale;\\n }\\n # End radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
sed -i "/listen localhost/a # Start radicale\\n location @radicale {\\n auth_basic \"Radicale\";\\n auth_basic_user_file \\/var\\/www\\/radicale\\/users;\\n proxy_pass http:\\/\\/localhost:52322;\\n proxy_buffering off;\\n proxy_set_header Host \$host;\\n proxy_set_header X-Real-IP \$remote_addr;\\n proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;\\n proxy_set_header X-Forwarded-Proto \$scheme;\\n }\\n\\n location \\/radicale {\\n try_files \$uri @radicale;\\n }\\n\\n location \\/.well-known\\/carddav {\\n try_files \$uri @radicale;\\n }\\n\\n location \\/.well-known\\/caldav {\\n try_files \$uri @radicale;\\n }\\n # End radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
2016-11-16 20:44:19 +01:00
fi
2016-11-08 23:13:50 +01:00
fi
2016-11-16 17:07:49 +01:00
# create a certificate
2018-03-01 00:17:49 +01:00
if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
"${PROJECT_NAME}-addcert" -h "$DEFAULT_DOMAIN_NAME" --dhkey "${DH_KEYLENGTH}"
check_certificates "$DEFAULT_DOMAIN_NAME"
2016-11-16 17:07:49 +01:00
fi
fi
2018-03-01 00:17:49 +01:00
if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
2016-11-15 21:33:00 +01:00
sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
fi
sed -i "s|radicale.key|${DEFAULT_DOMAIN_NAME}.key|g" /etc/nginx/sites-available/radicale
2016-11-15 21:28:34 +01:00
sed -i "s|radicale.dhparam|${DEFAULT_DOMAIN_NAME}.dhparam|g" /etc/nginx/sites-available/radicale
2016-11-08 23:13:50 +01:00
update_default_domain
2016-11-17 13:54:35 +01:00
systemctl restart nginx
2016-11-08 23:13:50 +01:00
2018-03-01 00:17:49 +01:00
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a radicale -p "$RADICALE_PASSWORD"
2016-11-08 23:13:50 +01:00
2016-11-17 11:20:17 +01:00
# keep track of the version so we can check for upgrades
2018-03-01 00:17:49 +01:00
if ! grep -q "radicale version:" "${COMPLETION_FILE}"; then
echo "radicale version:${RADICALE_VERSION}" >> "${COMPLETION_FILE}"
2016-11-17 11:20:17 +01:00
else
2018-03-01 00:17:49 +01:00
sed -i "s|radicale version.*|radicale version:${RADICALE_VERSION}|g" "${COMPLETION_FILE}"
2016-11-17 11:20:17 +01:00
fi
2016-11-08 23:13:50 +01:00
APP_INSTALLED=1
}
# NOTE: deliberately no exit 0