seafile_ynh/scripts/upgrade
2017-05-05 15:43:32 +02:00

143 lines
No EOL
4.6 KiB
Bash

#!/bin/bash
# Import common cmd
source ./_common.sh
# Init script
init_script
# Retrieve settings
installed_version=$(ynh_app_setting_get $app installed_version)
architecture=$(ynh_app_setting_get $app architecture)
path=$(ynh_app_setting_get $app path)
root_pwd=$(sudo cat /etc/yunohost/mysql)
# Set configuration for user and final path
set_configuration
# Download new version from sources
get_source $architecture $seafile_version
# stop seafile server
sudo service seafile-server stop
# extract new version
test -e $final_path/seafile-server-$seafile_version && sudo rm -rf "$final_path/seafile-server-$seafile_version"
sudo mkdir -p $final_path/seafile-server-$seafile_version
sudo tar xzf '/tmp/seafile_src.tar.gz'
sudo mv seafile-server-$seafile_version/* $final_path/seafile-server-$seafile_version
sudo mv '/tmp/seafile_src.tar.gz' $final_path/installed/seafile-server_${seafile_version}.tar.gz
# permission to execute update script and expect helper
sudo chmod +x ../conf/upgrade_*.exp
sudo chmod +x ../conf/minor-upgrade.exp
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_*.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/minor-upgrade.sh
# do the upgrade ( the ";&" syntax mean when it go in the frist cas how are true it do the next case)
case $installed_version in
"4.0."* )
# Update seafile by script
sudo ../conf/upgrade_4.1.1.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
"4.1."* )
# Update seafile by script
sudo ../conf/upgrade_4.2.1.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
"4.3."* )
# Update seafile by script
sudo ../conf/upgrade_4.4.3.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
"4.4."* )
# Update seafile by script
sudo ../conf/upgrade_5.0.3.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
"5.0."* )
# Update seafile by script
sudo ../conf/upgrade_5.1.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
"5.1."* )
# Update seafile by script
sudo ../conf/upgrade_6.0.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
esac
sudo ../conf/minor-upgrade.exp $final_path/seafile-server-$seafile_version $root_pwd
## Install webdav and logrotate if not installed
if [[ $installed_version = "4.0."* ]] || [[ $installed_version = "4.1."* ]]
then
# findPort
findPort () {
port=$1
sudo yunohost app checkport $port
while [[ ! $? -eq 0 ]]
do
port=$(($port + 1))
sudo yunohost app checkport $port
done
return $port
}
findPort 8080
webdav_port=$port
ynh_app_setting_set seafile webdav_port $webdav_port
# Disallow port that was used by old seafile client
ccnet_port=$(ynh_app_setting_get $app ccnet_port)
seafile_port=$(ynh_app_setting_get $app seafile_port)
sudo yunohost firewall disallow Both $ccnet_port
sudo yunohost firewall disallow Both $seafile_port
# Add webdav to nginx config
sed -i "s@WEBDAV_PORT@$webdav_port@g" ../conf/nginx_add_webdav
domain=$(ynh_app_setting_get seafile domain)
echo $(cat ../conf/nginx_add_webdav) | sudo tee -a /etc/nginx/conf.d/$domain.d/seafile.conf
# Add webdav config
sudo cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
sudo sed -i "s@WEBDAV_PORT@$webdav_port@g" $final_path/conf/seafdav.conf
# Add sso config to unprotect domain.tld/seafdav in /etc/ssowat/conf.json.persistent
sudo cp ../conf/add_sso_conf.py $final_path
sudo cp ../conf/add_sso_conf_webdav.py $final_path
sudo cp ../conf/remove_sso_conf.py $final_path
sudo python $final_path/add_sso_conf_webdav.py
# Update seafile config
echo 'COMPRESS_URL = MEDIA_URL' | sudo tee -a $final_path/conf/seahub_settings.py
echo "STATIC_URL = MEDIA_URL + 'assets/'" | sudo tee -a $final_path/conf/seahub_settings.py
# Add logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/seafile
sudo sed -i "s@SEAFILE_DIR@$final_path@g" /etc/logrotate.d/seafile
sudo service rsyslog restart
fi
# Update seahub config for old version to version 5.0.4
if [[ $(sudo grep -c "LOGIN_URL" $final_path/conf/seahub_settings.py) == 0 ]]
then
echo "LOGIN_URL = '"$path"/accounts/login/'" | sudo tee -a $final_path/conf/seahub_settings.py
fi
# restore correct permissions
sudo chown -R $seafile_user:$seafile_user $final_path
# delete seafile cache
sudo rm -rf /tmp/seahub_cache
# restart seafile server
sudo service seafile-server start
# remove old version files
sudo rm -f $final_path/installed/seafile-server_${installed_version}*.tar*
sudo rm -f $final_path/seafile-server_${installed_version}_$architecture
# store new installed version
ynh_app_setting_set $app installed_version $seafile_version
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app ssowatconf