2015-12-26 14:14:31 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-01-28 18:51:23 +01:00
|
|
|
######## Actually we cant use common script in backup / restore script see this issue for more informations : https://dev.yunohost.org/issues/621
|
|
|
|
# # Import common cmd
|
|
|
|
# source ./_common.sh
|
|
|
|
#
|
|
|
|
|
|
|
|
######## We implement manually this fonctions
|
|
|
|
|
2017-04-26 18:22:10 +02:00
|
|
|
seafile_version=6.0.9
|
2017-02-28 13:24:18 +01:00
|
|
|
|
|
|
|
## Adapt md5sum while you update app
|
2017-04-26 18:22:10 +02:00
|
|
|
x86_64sum="8d1547c51feecaff757eb64381ce154c"
|
|
|
|
i386sum="8a0b9e08d9c80790752b435c3e148328"
|
|
|
|
armsum="15ca4b69585a990e00474e4cfc4be9eb"
|
2017-02-28 13:24:18 +01:00
|
|
|
|
2017-01-28 18:51:23 +01:00
|
|
|
init_script() {
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
}
|
|
|
|
|
2017-02-28 13:24:18 +01:00
|
|
|
set_configuration() {
|
|
|
|
if [[ -e /var/www/$app ]]
|
|
|
|
then
|
|
|
|
final_path=/var/www/$app
|
|
|
|
seafile_user=www-data
|
|
|
|
elif [[ -e /opt/yunohost/$app ]]
|
|
|
|
then
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
seafile_user=seafile
|
|
|
|
else
|
|
|
|
ynh_die "Error : can't find seafile path"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_source() {
|
2017-04-26 18:22:10 +02:00
|
|
|
if [[ $1 == 'rpi' ]]
|
2017-03-07 16:13:38 +01:00
|
|
|
then
|
2017-02-28 13:24:18 +01:00
|
|
|
wget -q -O '/tmp/seafile_src.tar.gz' 'https://github.com/haiwen/seafile-rpi/releases/download/v'$2'/seafile-server_'$2'_stable_pi.tar.gz'
|
|
|
|
md5sum=$armsum
|
|
|
|
elif [[ $1 == 'x86-64' ]]
|
|
|
|
then
|
|
|
|
wget -q -O '/tmp/seafile_src.tar.gz' 'https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_'$2'_x86-64.tar.gz'
|
|
|
|
md5sum=$x86_64sum
|
|
|
|
else
|
|
|
|
wget -q -O '/tmp/seafile_src.tar.gz' 'https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_'$2'_i386.tar.gz'
|
|
|
|
md5sum=$i386sum
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -e '/tmp/seafile_src.tar.gz' ]] || [[ $(md5sum '/tmp/seafile_src.tar.gz' | cut -d' ' -f1) != $md5sum ]]
|
|
|
|
then
|
|
|
|
ynh_die "Error : can't get seafile source"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
|
|
|
# $1 = Variable à vérifier
|
|
|
|
# $2 = Texte à afficher en cas d'erreur
|
|
|
|
test -n "$1" || (echo "$2" >&2 && false)
|
|
|
|
}
|
|
|
|
|
2017-01-31 23:25:17 +01:00
|
|
|
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
|
|
|
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
|
|
|
path="/$path" # Ajoute un / en début de path
|
|
|
|
fi
|
|
|
|
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère.
|
|
|
|
path="${path:0:${#path}-1}" # Supprime le dernier caractère
|
|
|
|
fi
|
2017-01-28 18:51:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
######## End of common fonctions
|
2016-12-27 10:44:40 +01:00
|
|
|
|
2017-01-05 23:24:32 +01:00
|
|
|
# Init script
|
|
|
|
init_script
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
final_path=/var/www/$app
|
|
|
|
seafile_user=www-data
|
2016-12-27 10:44:40 +01:00
|
|
|
|
2015-12-26 14:14:31 +01:00
|
|
|
# The parameter $1 is the backup directory location dedicated to the app
|
|
|
|
BACKUP_DIR=$1
|
|
|
|
|
2016-02-08 02:06:58 +01:00
|
|
|
# retrieve useful param
|
2017-01-31 23:25:17 +01:00
|
|
|
domain=$(ynh_app_setting_get ${app} domain)
|
|
|
|
db_pwd=$(ynh_app_setting_get ${app} mysqlpwd)
|
|
|
|
path=$(ynh_app_setting_get ${app} path)
|
2015-12-26 14:14:31 +01:00
|
|
|
|
2017-01-05 23:24:32 +01:00
|
|
|
# Correct path if it is not correct
|
2017-01-31 23:25:17 +01:00
|
|
|
CHECK_PATH
|
2017-01-05 23:24:32 +01:00
|
|
|
|
2015-12-26 14:14:31 +01:00
|
|
|
# Check domain/path availability
|
2017-01-31 23:25:17 +01:00
|
|
|
sudo yunohost app checkurl $domain$path -a ${app} \
|
2016-12-27 10:44:40 +01:00
|
|
|
|| (echo "Path not available: $domain$path" && ynh_die "Error : path not available")
|
2017-01-05 23:24:32 +01:00
|
|
|
|
2015-12-26 14:14:31 +01:00
|
|
|
# Restore dependencies
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
|
|
|
|
|
|
|
|
# Restore app files
|
2016-12-27 10:44:40 +01:00
|
|
|
final_path=$final_path
|
2015-12-26 14:14:31 +01:00
|
|
|
sudo mkdir -p $final_path
|
|
|
|
sudo cp -a "${BACKUP_DIR}/www/." $final_path
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo chown -R $seafile_user:$seafile_user $final_path
|
2015-12-26 14:14:31 +01:00
|
|
|
|
|
|
|
# Restore conf files
|
2017-01-31 23:25:17 +01:00
|
|
|
sudo cp -a "${BACKUP_DIR}/conf/${app}.conf" /etc/nginx/conf.d/$domain.d/${app}.conf
|
|
|
|
sudo cp -a "${BACKUP_DIR}/conf/${app}" /etc/logrotate.d/${app}
|
2015-12-26 14:14:31 +01:00
|
|
|
sudo cp -a "${BACKUP_DIR}/conf/seafile-server" /etc/init.d/seafile-server
|
|
|
|
sudo chmod +x /etc/init.d/seafile-server
|
|
|
|
|
|
|
|
# Restore data
|
|
|
|
seafile_data=/home/yunohost.app/seafile-data
|
2017-01-31 23:25:17 +01:00
|
|
|
sudo mkdir -p $seafile_data
|
2015-12-26 14:14:31 +01:00
|
|
|
sudo cp -a "${BACKUP_DIR}/data/." /home/yunohost.app/seafile-data/.
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo chown -R $seafile_user:$seafile_user $seafile_data
|
2015-12-26 14:14:31 +01:00
|
|
|
|
|
|
|
# Restore mysql dump
|
2017-01-31 23:25:17 +01:00
|
|
|
dbuser=seafile
|
|
|
|
ynh_mysql_create_db ccnetdb "$dbuser" "$db_pwd"
|
|
|
|
ynh_mysql_create_db seafiledb "$dbuser" "$db_pwd"
|
|
|
|
ynh_mysql_create_db seahubdb "$dbuser" "$db_pwd"
|
|
|
|
sudo su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${BACKUP_DIR}/ccnetdb.dmp"
|
|
|
|
sudo su -c "mysql -u ${app} -p$db_pwd seafiledb < ${BACKUP_DIR}/seafiledb.dmp"
|
|
|
|
sudo su -c "mysql -u ${app} -p$db_pwd seahubdb < ${BACKUP_DIR}/seahubdb.dmp"
|
2016-02-08 02:06:58 +01:00
|
|
|
|
|
|
|
# Restore sso persistent config
|
|
|
|
sudo python $final_path/add_sso_conf.py
|
2015-12-26 14:14:31 +01:00
|
|
|
|
|
|
|
# Add Seafile to YunoHost's monitored services
|
|
|
|
sudo yunohost service add seafile-server
|
|
|
|
|
|
|
|
# Reload/restart services
|
|
|
|
sudo update-rc.d seafile-server defaults
|
|
|
|
sudo service rsyslog restart
|
|
|
|
sudo yunohost app ssowatconf
|
2017-01-31 23:25:17 +01:00
|
|
|
sudo service nginx reload
|
2015-12-26 14:14:31 +01:00
|
|
|
|
|
|
|
# start seafile
|
2016-02-08 02:06:58 +01:00
|
|
|
sudo service seafile-server start
|