This commit is contained in:
Josue 2016-12-27 10:44:40 +01:00
parent abdf449994
commit 37da57a94d
13 changed files with 210 additions and 65 deletions

View file

@ -27,7 +27,7 @@ From command line:
Infos
-----
Seafile server v5.0.3
Seafile server v6.0.6
Available for x64, i386, and Raspberry Pi architecture but only tested for x64 (feedback are welcome)
@ -52,6 +52,31 @@ TODO
- Auto login/logout, see #1
- Test of backup/restore script
Use a spial user and put seafile binary in /opt dir :
--------------------------------------
With this new package for a better security, it's possible to run seafile with a special user (seafile) put all seafile file in /opt/yunohost dir.
To do this open a console and do this command :
```
# stop seafile server
sudo service seafile-server stop
# Move all data to opt and change user
sudo mv /var/www/seafile /opt/yunohost/seafile
sudo addgroup seafile --system --quiet
sudo adduser seafile --disabled-login --ingroup seafile --system --quiet --shell /bin/bash --home /opt/yunohost/seafile
# Adapt configuration
sudo sed -i "s@user=www-data@user=seafile@g" /etc/init.d/seafile-server
sudo sed -i "s@seafile_dir=/var/www/seafile@seafile_dir=/opt/yunohost/seafile@g" /etc/init.d/seafile-server
sudo sed -i "s@alias /var/www/seafile/@alias /opt/yunohost/seafile/@g" /etc/nginx/conf.d/$domain.d/seafile.conf
# Restart services
sudo service nginx reload
sudo service seafile-server start
```
Developper infos
----------------

12
conf/upgrade_5.1.exp Normal file
View file

@ -0,0 +1,12 @@
#!/usr/bin/expect
set timeout 5
set seafile_dir [lindex $argv 0]
set mysql_password [lindex $argv 1]
spawn $seafile_dir/upgrade/upgrade_5.0_5.1.sh
expect "to contiune"
send "\r";
interact

12
conf/upgrade_6.0.exp Normal file
View file

@ -0,0 +1,12 @@
#!/usr/bin/expect
set timeout 5
set seafile_dir [lindex $argv 0]
set mysql_password [lindex $argv 1]
spawn $seafile_dir/upgrade/upgrade_5.1_6.0.sh
expect "to contiune"
send "\r";
interact

View file

@ -1,23 +1,30 @@
{
"name": "Seafile",
"id": "seafile",
"packaging_format": 1,
"license": "free",
"url": "https://www.seafile.com",
"description": {
"en": "Open Source Cloud Storage",
"fr": "Stockage Cloud Open Source"
},
"developer": {
"maintainer": {
"name": "mbugeia",
"email": "maxime@max.privy.place"
},
"multi_instance": "false",
"multi_instance": false,
"services": [
"nginx",
"mysql"
],
"requirements": {
"yunohost": ">= 2.4.0"
},
"arguments": {
"install": [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for Seafile",
"fr": "Choisissez un domaine pour Seafile"
@ -26,6 +33,7 @@
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Seafile",
"fr": "Choisissez un chemin pour Seafile"
@ -44,6 +52,7 @@
},
{
"name": "admin",
"type": "user",
"ask": {
"en": "Choose the admin user for Seafile",
"fr": "Choisissez l'administrateur de Seafile"
@ -52,6 +61,7 @@
},
{
"name": "admin_password",
"type": "password",
"ask": {
"en": "Enter a password for the administrator",
"fr": "Entrez un mot de passe pour l'administrateur"
@ -60,12 +70,12 @@
},
{
"name": "public_site",
"type": "boolean",
"ask": {
"en": "Is it a public site ? If you want to use a desktop client or the smartphone app, make Seafile public.",
"fr": "Est-ce un site public ? Pour utiliser un client sur PC ou l'application mobile, Seafile doit être public"
},
"choices": ["Yes", "No"],
"default": "Yes"
"default": "1"
},
{
"name": "architecture",
@ -78,4 +88,4 @@
}
]
}
}
}

29
scripts/_common.sh Normal file
View file

@ -0,0 +1,29 @@
#!/bin/bash
set_configuration() {
if [[ -e /var/www/$app ]]
then
final_path=/var/www/$app
seafile_user=www-data
elif [[ -e /opt/yunohost/$app ]]
final_path=/opt/yunohost/$app
seafile_user=seafile
else
ynh_die "Error : can't find seafile path"
fi
}
get_source() {
if [[ $1 == 'arm' ]]
then
wget -O '/tmp/seafile_src.tar.gz' 'https://github.com/haiwen/seafile-rpi/releases/download/v'$2'/seafile-server'$1'_stable_pi.tar.gz'
else
wget -O '/tmp/seafile_src.tar.gz' 'https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_'$1'_'$2'.tar.gz'
fi
if [[ ! -e '/tmp/seafile_src.tar.gz' ]]
then
ynh_die "Error : can't get seafile source"
fi
}

View file

@ -2,6 +2,12 @@
set -e
# Import common cmd
source ./_common.sh
# Set configuration for user and final path
set_configuration
# The parameter $1 is the backup directory location dedicated to the app
BACKUP_DIR=$1
@ -9,12 +15,12 @@ BACKUP_DIR=$1
APP=$2
# retrieve useful param
domain=$(sudo yunohost app setting ${APP} domain)
db_pwd=$(sudo yunohost app setting ${APP} db_pwd)
domain=$(ynh_app_setting_get ${APP} domain)
db_pwd=$(ynh_app_setting_get ${APP} db_pwd)
# Backup app files
sudo mkdir -p "${BACKUP_DIR}/www"
sudo cp -a /var/www/${APP}/. "${BACKUP_DIR}/www"
sudo cp -a $final_path/. "${BACKUP_DIR}/www"
# Backup conf files
sudo mkdir -p "${BACKUP_DIR}/conf"
@ -29,6 +35,4 @@ sudo cp -a /home/yunohost.app/seafile-data/. "${BACKUP_DIR}/data"
# Backup mysql
mysqldump -u ${APP} -p$db_pwd ccnetdb | sudo dd of=${BACKUP_DIR}/ccnetdb.dmp
mysqldump -u ${APP} -p$db_pwd seafiledb | sudo dd of=${BACKUP_DIR}/seafiledb.dmp
mysqldump -u ${APP} -p$db_pwd seahubdb | sudo dd of=${BACKUP_DIR}/seahubdb.dmp
exit 0
mysqldump -u ${APP} -p$db_pwd seahubdb | sudo dd of=${BACKUP_DIR}/seahubdb.dmp

View file

@ -10,9 +10,24 @@ admin=$4
admin_password=$5
is_public=$6
architecture=$7
final_path=/var/www/$app
seafile_data=/home/yunohost.app/seafile-data
seafile_version=5.0.3
seafile_version=6.0.4
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Import common cmd
source ./_common.sh
# Set configuration for user and final path
set_configuration
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && ynh_die "Error : path not available")
# Download new version from sources
get_source $architecture $seafile_version
# Retrieve admin email
admin_email=$(sudo yunohost user info $admin | grep mail: | sed "s/mail: //g")
@ -31,10 +46,6 @@ findPort () {
return $port
}
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && exit 1)
# Check dependencies
sudo apt-get update
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
@ -45,7 +56,7 @@ sudo mkdir -p $final_path/installed
sudo mkdir -p $final_path/logs
sudo mkdir -p $final_path/seafile-data
sudo mkdir -p $final_path/seafile-server-$seafile_version
sudo tar xzf ../sources/'seafile-server_'$seafile_version'_'$architecture'.tar.gz'
sudo tar xzf '/tmp/seafile_src.tar.gz'
sudo mv seafile-server-$seafile_version/* $final_path/seafile-server-$seafile_version
sudo mv ../sources/'seafile-server_'$seafile_version'_'$architecture'.tar.gz' $final_path/installed
@ -58,20 +69,20 @@ findPort 8080
webdav_port=$port
# store config in yunohost
sudo yunohost app setting $app seahub_port -v $seahub_port
sudo yunohost app setting $app fileserver_port -v $fileserver_port
sudo yunohost app setting $app webdav_port -v $webdav_port
sudo yunohost app setting $app is_public -v $is_public
sudo yunohost app setting $app architecture -v $architecture
sudo yunohost app setting $app installed_version -v $seafile_version
ynh_app_setting_set $app seahub_port $seahub_port
ynh_app_setting_set $app fileserver_port $fileserver_port
ynh_app_setting_set $app webdav_port $webdav_port
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app architecture $architecture
ynh_app_setting_set $app installed_version $seafile_version
# init databases
db_user=$app
db_pwd=$(openssl rand -hex 15)
sudo yunohost app initdb -d ccnetdb -p $db_pwd $db_user
sudo yunohost app initdb -d seafiledb -p $db_pwd $db_user
sudo yunohost app initdb -d seahubdb -p $db_pwd $db_user
sudo yunohost app setting seafile db_pwd -v $db_pwd
dbuser=seafile
db_pwd=$(ynh_string_random 15)
ynh_app_setting_set "$app" mysqlpwd "$db_pwd"
ynh_mysql_create_db ccnetdb "$dbuser" "$db_pwd"
ynh_mysql_create_db seafiledb "$dbuser" "$db_pwd"
ynh_mysql_create_db seahubdb "$dbuser" "$db_pwd"
# Run install script
sudo chmod +x ../conf/install.exp
@ -127,12 +138,12 @@ sudo cp ../conf/first_launch.exp $final_path
sudo chmod +x $final_path/first_launch.exp
# Set permissions to seafile directory
sudo chown -R www-data:www-data $final_path
sudo chown -R www-data:www-data $seafile_data
sudo chown -R $seafile_user:$seafile_user $final_path
sudo chown -R $seafile_user:$seafile_user $seafile_data
# Start seafile, seahub and populate admin account
sudo su - www-data -s /bin/bash -c "/var/www/seafile/seafile-server-$seafile_version/seafile.sh start"
sudo su - www-data -s /bin/bash -c "$final_path/first_launch.exp $final_path/seafile-server-$seafile_version $admin_email $admin_password"
sudo su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-$seafile_version/seafile.sh start"
sudo su - $seafile_user -s /bin/bash -c "$final_path/first_launch.exp $final_path/seafile-server-$seafile_version $admin_email $admin_password"
# Add sso config to unprotect domain.tld/seafhttp + domain.tld/seafdav do in /etc/ssowat/conf.json.persistent
sudo cp ../conf/add_sso_conf.py $final_path
@ -140,13 +151,13 @@ sudo cp ../conf/remove_sso_conf.py $final_path
sudo python $final_path/add_sso_conf.py
# unprotect media
sudo yunohost app setting seafile unprotected_uris -v "/media"
ynh_app_setting_set seafile unprotected_uris "/media"
if [ "$is_public" = "No" ]
if [ "$is_public" = "0" ]
then
sudo yunohost app setting seafile unprotected_uris -d
ynh_app_setting_delete seafile unprotected_uris
else
sudo yunohost app setting seafile unprotected_uris -v "/"
ynh_app_setting_set seafile unprotected_uris "/"
fi
# Add logrotate
@ -162,6 +173,6 @@ sudo service nginx reload
sudo yunohost app ssowatconf
# Restart seafile
sudo su - www-data -s /bin/bash -c "/var/www/seafile/seafile-server-latest/seahub.sh stop"
sudo su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-latest/seahub.sh stop"
sudo service seafile-server stop
sudo service seafile-server start
sudo service seafile-server start

View file

@ -1,13 +1,19 @@
#!/bin/bash
domain=$(sudo yunohost app setting seafile domain)
domain=$(ynh_app_setting_get seafile domain)
root_pwd=$(sudo cat /etc/yunohost/mysql)
# Import common cmd
source ./_common.sh
# Set configuration for user and final path
set_configuration
sudo service seafile-server stop
# remove sso config to unprotect domain.tld/seafhttp in /etc/ssowat/conf.json.persistent
sudo python /var/www/seafile/remove_sso_conf.py
sudo python $final_path/remove_sso_conf.py
sudo rm -rf /var/www/seafile
sudo rm -rf $final_path
sudo rm -f /etc/nginx/conf.d/$domain.d/seafile.conf
sudo rm -f /etc/init.d/seafile-server
sudo rm -rf /home/yunohost.app/seafile-data

View file

@ -2,6 +2,12 @@
set -e
# Import common cmd
source ./_common.sh
# Set configuration for user and final path
set_configuration
# The parameter $1 is the backup directory location dedicated to the app
BACKUP_DIR=$1
@ -9,23 +15,23 @@ BACKUP_DIR=$1
APP=$2
# retrieve useful param
domain=$(sudo yunohost app setting ${APP} domain)
db_pwd=$(sudo yunohost app setting ${APP} db_pwd)
path=$(sudo yunohost app setting ${APP} path)
domain=$(ynh_app_setting_get ${APP} domain)
db_pwd=$(ynh_app_setting_get ${APP} db_pwd)
path=$(ynh_app_setting_get ${APP} path)
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a ${APP} \
|| (echo "Path not available: $domain$path" && exit 1)
|| (echo "Path not available: $domain$path" && ynh_die "Error : path not available")
# 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
final_path=/var/www/${APP}
final_path=$final_path
sudo mkdir -p $final_path
sudo cp -a "${BACKUP_DIR}/www/." $final_path
sudo chown -R www-data:www-data $final_path
sudo chown -R $seafile_user:$seafile_user $final_path
# Restore conf files
sudo cp -a "${BACKUP_DIR}/conf/${APP}.conf" /etc/nginx/conf.d/$domain.d/${APP}.conf
@ -37,7 +43,7 @@ sudo chmod +x /etc/init.d/seafile-server
seafile_data=/home/yunohost.app/seafile-data
mkdir -p $seafile_data
sudo cp -a "${BACKUP_DIR}/data/." /home/yunohost.app/seafile-data/.
sudo chown -R www-data:www-data $seafile_data
sudo chown -R $seafile_user:$seafile_user $seafile_data
# Restore mysql dump
sudo su -c "mysql -u ${APP} -p$db_pwd ccnetdb < ${BACKUP_DIR}/ccnetdb.dmp"
@ -58,5 +64,3 @@ sudo yunohost app ssowatconf
# start seafile
sudo service seafile-server start
exit 0

View file

@ -3,15 +3,26 @@
app=seafile
# Retrieve settings
installed_version=$(sudo yunohost app setting $app installed_version)
architecture=$(sudo yunohost app setting $app architecture)
installed_version=$(ynh_app_setting_get $app installed_version)
architecture=$(ynh_app_setting_get $app architecture)
root_pwd=$(sudo cat /etc/yunohost/mysql)
seafile_version=5.0.3
final_path=/var/www/$app
seafile_version=6.0.6
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Import common cmd
source ./_common.sh
# Set configuration for user and final path
set_configuration
# Download new version from sources
get_source $architecture $seafile_version
# extract new version
sudo mkdir -p $final_path/seafile-server-$seafile_version
sudo tar xzf ../sources/'seafile-server_'$seafile_version'_'$architecture'.tar.gz'
sudo tar xzf '/tmp/seafile_src.tar.gz'
sudo mv seafile-server-$seafile_version/* $final_path/seafile-server-$seafile_version
sudo mv ../sources/'seafile-server_'$seafile_version'_'$architecture'.tar.gz' $final_path/installed
@ -24,12 +35,15 @@ sudo chmod +x ../conf/upgrade_4.2.1.exp
sudo chmod +x ../conf/upgrade_4.3.2.exp
sudo chmod +x ../conf/upgrade_4.4.3.exp
sudo chmod +x ../conf/upgrade_5.0.3.exp
sudo chmod +x ../conf/upgrade_5.1.exp
sudo chmod +x ../conf/upgrade_6.0.exp
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_4.0_4.1.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_4.1_4.2.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_4.2_4.3.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_4.3_4.4.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_4.4_5.0.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_5.0_5.1.sh
sudo chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_5.1_6.0.sh
# do the upgrade
case $installed_version in
"4.0."* )
@ -39,6 +53,8 @@ case $installed_version in
sudo ../conf/upgrade_4.3.2.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_4.4.3.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_5.0.3.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_5.1.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_6.0.exp $final_path/seafile-server-$seafile_version $root_pwd
;;
"4.1."* )
# Update seafile by script
@ -46,15 +62,31 @@ case $installed_version in
sudo ../conf/upgrade_4.3.2.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_4.4.3.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_5.0.3.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_5.1.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_6.0.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
sudo ../conf/upgrade_5.0.3.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_5.1.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_6.0.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
sudo ../conf/upgrade_5.1.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_6.0.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
sudo ../conf/upgrade_6.0.exp $final_path/seafile-server-$seafile_version $root_pwd
;;
"5.1."* )
# Update seafile by script
sudo ../conf/upgrade_5.1.exp $final_path/seafile-server-$seafile_version $root_pwd
sudo ../conf/upgrade_6.0.exp $final_path/seafile-server-$seafile_version $root_pwd
;;
esac
@ -77,17 +109,17 @@ then
findPort 8080
webdav_port=$port
sudo yunohost app setting seafile webdav_port -v $webdav_port
ynh_app_setting_set seafile webdav_port $webdav_port
# Disallow port that was used by old seafile client
ccnet_port=$(sudo yunohost app setting $app ccnet_port)
seafile_port=$(sudo yunohost app setting $app seafile_port)
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=$(sudo yunohost app setting seafile domain)
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
@ -111,7 +143,7 @@ then
fi
# restore correct permissions
sudo chown -R www-data:www-data $final_path
sudo chown -R $seafile_user:$seafile_user $final_path
# delete seafile cache
sudo rm -r /tmp/seahub_cache
@ -124,7 +156,7 @@ sudo rm -f $final_path/installed/seafile-server_$installed_version_$architecture
sudo rm -f $final_path/seafile-server_$installed_version_$architecture
# store new installed version
sudo yunohost app setting seafile installed_version -v $seafile_version
ynh_app_setting_set seafile installed_version -v $seafile_version
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload