Full app Update

This commit is contained in:
Josué Tille 2017-07-21 14:56:41 +02:00
parent d20de21fd4
commit 9380ee33c1
12 changed files with 358 additions and 448 deletions

View file

@ -8,7 +8,6 @@
admin="john" (USER)
admin_password="Sup3rS3cr3t" (PASSWORD)
public_site="1" (PUBLIC|public=1|private=0)
architecture="x86-64"
; Checks
pkg_linter=1
setup_sub_dir=1

View file

@ -2,7 +2,7 @@ import json
with open("/etc/ssowat/conf.json.persistent", "r") as jsonFile:
data = json.load(jsonFile)
data["unprotected_urls"].append("/seafdav")
data["skipped_urls"].append("/seafdav")
with open("/etc/ssowat/conf.json.persistent", "w") as jsonFile:
jsonFile.write(json.dumps(data, indent=4, sort_keys=True))

View file

@ -1,28 +0,0 @@
SEAFILE_DIR/logs/seaf-server.log
{
daily
missingok
rotate 52
compress
delaycompress
notifempty
sharedscripts
postrotate
[ ! -f SEAFILE_DIR/pids/seaf-server.pid ] || kill -USR1 `cat SEAFILE_DIR/pids/seaf-server.pid`
endscript
}
SEAFILE_DIR/logs/ccnet.log
{
daily
missingok
rotate 52
compress
delaycompress
notifempty
sharedscripts
postrotate
[ ! -f SEAFILE_DIR/pids/ccnet.pid ] || kill -USR1 `cat SEAFILE_DIR/pids/ccnet.pid`
endscript
}

14
conf/update_sso_conf.py Normal file
View file

@ -0,0 +1,14 @@
import json
with open("/etc/ssowat/conf.json.persistent", "r") as jsonFile:
data = json.load(jsonFile)
data["unprotected_urls"].remove("/seafhttp")
data["unprotected_urls"].remove("/seafdav")
if "skipped_urls" in data:
data["skipped_urls"].append("/seafhttp")
else:
data["skipped_urls"] = ["/seafhttp"]
data["skipped_urls"].append("/seafdav")
with open("/etc/ssowat/conf.json.persistent", "w") as jsonFile:
jsonFile.write(json.dumps(data, indent=4, sort_keys=True))

12
conf/upgrade_6.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.1_6.0.sh
expect "to contiune"
send "\r";
interact

View file

@ -4,6 +4,7 @@
"packaging_format": 1,
"license": "free",
"url": "https://www.seafile.com",
"version": "6.1.1",
"description": {
"en": "Open Source Cloud Storage",
"fr": "Stockage Cloud Open Source"
@ -18,7 +19,7 @@
"mysql"
],
"requirements": {
"yunohost": ">= 2.4.0"
"yunohost": ">= 2.6.4"
},
"arguments": {
"install": [
@ -76,15 +77,6 @@
"fr": "Est-ce un site public ? Pour utiliser un client sur PC ou l'application mobile, Seafile doit être public"
},
"default": "1"
},
{
"name": "architecture",
"ask": {
"en": "What is the server architecture?",
"fr": "Quelle est l'architecture du serveur ?"
},
"choices": ["x86-64", "i386", "rpi"],
"default": "x86-64"
}
]
}

View file

@ -1,84 +1,98 @@
#!/bin/bash
seafile_version=6.0.9
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
seafile_version=6.1.1
## Adapt md5sum while you update app
x86_64sum="8d1547c51feecaff757eb64381ce154c"
i386sum="8a0b9e08d9c80790752b435c3e148328"
armsum="15ca4b69585a990e00474e4cfc4be9eb"
x86_64sum="3f887d018bd7eaa8b4e1e7830f365802311686636227f1c08a8c48e89aefc35c"
i386sum="6d236c93f5a5f674c52b943428995cfe046965f17f2df9f644e17a704072603b"
armsum="e40a8f3a91a4629428288aaabe4a2d6906dd00afc08faf08916f30b8c5a312e4"
init_script() {
# Exit on command errors and treat unset variables as an error
set -eu
# Detect the system architecture to download the right tarball
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
if [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
your hardware and the result of the command \"uname -m\"." 1
fi
# Source YunoHost helpers
source /usr/share/yunohost/helpers
get_configuration() {
final_path=$(ynh_app_setting_get $app final_path)
seafile_user=$(ynh_app_setting_get $app seafile_user)
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
if [[ -z $final_path ]] || [[ -z $seafile_user ]]
then
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
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app seafile_user $seafile_user
fi
}
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
config_nginx() {
ynh_replace_string PATHTOCHANGE1 $path ../conf/nginx.conf
ynh_replace_string PATHTOCHANGE2 $path2 ../conf/nginx.conf
ynh_replace_string ALIASTOCHANGE $final_path/ ../conf/nginx.conf
ynh_replace_string SEAHUB_PORT $seahub_port ../conf/nginx.conf
ynh_replace_string SEAFILE_FILESERVER_PORT $fileserver_port ../conf/nginx.conf
ynh_replace_string WEBDAV_PORT $webdav_port ../conf/nginx.conf
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/seafile.conf
systemctl reload nginx.service
}
get_source() {
if [[ $1 == 'rpi' ]]
if [[ $1 == 'arm' ]]
then
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
sha256sum=$armsum
elif [[ $1 == 'x86-64' ]]
then
wget -q -O '/tmp/seafile_src.tar.gz' 'https://download.seadrive.org/seafile-server_'$2'_x86-64.tar.gz'
md5sum=$x86_64sum
sha256sum=$x86_64sum
else
wget -q -O '/tmp/seafile_src.tar.gz' 'https://download.seadrive.org/seafile-server_'$2'_i386.tar.gz'
md5sum=$i386sum
sha256sum=$i386sum
fi
if [[ ! -e '/tmp/seafile_src.tar.gz' ]] || [[ $(md5sum '/tmp/seafile_src.tar.gz' | cut -d' ' -f1) != $md5sum ]]
if [[ ! -e '/tmp/seafile_src.tar.gz' ]] || [[ $(sha256sum '/tmp/seafile_src.tar.gz' | cut -d' ' -f1) != $sha256sum ]]
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)
extract_source() {
mkdir -p $final_path/seafile-server-$seafile_version
tar xzf '/tmp/seafile_src.tar.gz'
mv seafile-server-$seafile_version/* $final_path/seafile-server-$seafile_version
mv '/tmp/seafile_src.tar.gz' $final_path/installed/seafile-server_${seafile_version}.tar.gz
}
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
install_dependance() {
ynh_install_app_dependencies python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect ffmpeg python-requests
pip install pillow moviepy
}
# Find a free port and return it
#
# example: port=$(ynh_find_port 8080)
#
# usage: ynh_find_port begin_port
# | arg: begin_port - port to start to search
ynh_find_port () {
port=$1
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
while netcat -z 127.0.0.1 $port # Check if the port is free
do
port=$((port+1)) # Else, pass to next port
done
echo $port
ynh_clean_setup () {
killall seafile-controller
killall seaf-server
killall ccnet-server
kill $(ps -C python2.7 -o pid,cmd | grep "python2.7 $final_path/seafile-server-$seafile_version/seahub/manage.py" | cut -d' ' -f1)
}

View file

@ -1,70 +1,47 @@
#!/bin/bash
######## 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
#
# Source YunoHost helpers
source /usr/share/yunohost/helpers
######## We implement manually this fonctions
# Stop script if errors
ynh_abort_if_errors
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
}
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
}
######## End of common fonctions
# Init script
init_script
# Import common cmd
source ../settings/scripts/_common.sh
# Set configuration for user and final path
set_configuration
get_configuration
# The parameter $1 is the backup directory location dedicated to the app
BACKUP_DIR=$1
# The parameter $2 is the id of the app instance ex: strut__2
APP=$2
# retrieve useful param
domain=$(ynh_app_setting_get ${APP} domain)
db_pwd=$(ynh_app_setting_get ${APP} mysqlpwd)
domain=$(ynh_app_setting_get ${app} domain)
db_pwd=$(ynh_app_setting_get ${app} mysqlpwd)
# Backup app files
sudo mkdir -p "${BACKUP_DIR}/www"
sudo cp -a $final_path/. "${BACKUP_DIR}/www"
# # Backup app files
# Backup conf files
sudo mkdir -p "${BACKUP_DIR}/conf"
sudo cp -a /etc/nginx/conf.d/$domain.d/${APP}.conf "${BACKUP_DIR}/conf/${APP}.conf"
sudo cp -a /etc/logrotate.d/${APP} "${BACKUP_DIR}/conf/${APP}"
sudo cp -a /etc/init.d/seafile-server "${BACKUP_DIR}/conf/seafile-server"
# mkdir -p "${BACKUP_DIR}/www"
# cp -a $final_path/. "${BACKUP_DIR}/www"
#
# # Backup conf files
# mkdir -p "${BACKUP_DIR}/conf"
# cp -a /etc/nginx/conf.d/$domain.d/${APP}.conf "${BACKUP_DIR}/conf/${APP}.conf"
# cp -a /etc/init.d/seafile-server "${BACKUP_DIR}/conf/seafile-server"
#
# # Backup data
# mkdir -p "${BACKUP_DIR}/data"
# cp -a /home/yunohost.app/seafile-data/. "${BACKUP_DIR}/data"
# Backup data
sudo mkdir -p "${BACKUP_DIR}/data"
sudo cp -a /home/yunohost.app/seafile-data/. "${BACKUP_DIR}/data"
ynh_backup $final_path
ynh_backup /home/yunohost.app/seafile-data "data" 1
ynh_backup /etc/nginx/conf.d/$domain.d/${APP}.conf
ynh_backup /etc/init.d/seafile-server
# 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
ynh_mysql_dump_db
ynh_mysql_dump_db ccnetdb > ${YNH_CWD}/ccnetdb.dmp
ynh_mysql_dump_db seafiledb > ${YNH_CWD}/seafiledb.dmp
ynh_mysql_dump_db seahubdb > ${YNH_CWD}/seahubdb.dmp

View file

@ -1,29 +1,47 @@
#!/bin/bash
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
# Import common cmd
source ./_common.sh
# Init script
init_script
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
path=$(ynh_normalize_url_path $YNH_APP_ARG_PATH)
server_name=$YNH_APP_ARG_SERVER_NAME
admin=$YNH_APP_ARG_ADMIN
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
is_public=$YNH_APP_ARG_PUBLIC_SITE
architecture=$YNH_APP_ARG_ARCHITECTURE
seafile_data=/home/yunohost.app/seafile-data
final_path=/var/www/$app
seafile_user=www-data
# Correct path if it is not correct
CHECK_PATH
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
test $(ynh_webpath_available $domain $path) == 'True' || ynh_die "$domain$path is not available, please use an other domain or path."
ynh_webpath_register $app $domain $path
# Check Final Path availability
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Find available ports
seahub_port=$(ynh_find_port 8000)
fileserver_port=$(ynh_find_port 8082)
webdav_port=$(ynh_find_port 8080)
# store config in yunohost
ynh_app_setting_set $app server_name $server_name
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app seafile_user $seafile_user
ynh_app_setting_set $app admin $admin
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 installed_version $seafile_version
# Create special path with / at the end
if [[ $path == '/' ]]
@ -37,36 +55,19 @@ fi
get_source $architecture $seafile_version
# Retrieve admin email
admin_email=$(sudo yunohost user info $admin | grep mail: | sed "s/mail: //g")
admin_email=$(yunohost user info $admin | grep mail: | sed "s/mail: //g")
# Check dependencies
sudo apt-get update
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
install_dependance
# Copy files to the right place
test -e $final_path && sudo rm -rf "$final_path"
test -e $seafile_data && sudo rm -rf "$seafile_data"
sudo mkdir -p $final_path
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 '/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
# Find available ports
seahub_port=$(ynh_find_port 8000)
fileserver_port=$(ynh_find_port 8082)
webdav_port=$(ynh_find_port 8080)
# store config in yunohost
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
test -e $final_path && rm -rf "$final_path"
test -e $seafile_data && rm -rf "$seafile_data"
mkdir -p $final_path
mkdir -p $final_path/installed
mkdir -p $final_path/logs
mkdir -p $final_path/seafile-data
extract_source
# init databases
dbuser=seafile
@ -77,72 +78,69 @@ 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
sudo chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
sudo ../conf/install.exp $final_path/seafile-server-$seafile_version $server_name $domain $seafile_data $fileserver_port $db_pwd
chmod +x ../conf/install.exp
chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
../conf/install.exp $final_path/seafile-server-$seafile_version $server_name $domain $seafile_data $fileserver_port $db_pwd
# Update seafile config
sudo sed -i "s@http://@https://@g" $final_path/conf/ccnet.conf
sudo sed -i "s@:8000@$path@g" $final_path/conf/ccnet.conf
echo 'FILE_SERVER_ROOT = "https://'$domain'/seafhttp"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'SITE_ROOT = "'$path2'"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'SERVE_STATIC = False' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'MEDIA_URL = "'$path2'media/"' | sudo tee -a $final_path/conf/seahub_settings.py
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
echo "LOGIN_URL = '"$path2"accounts/login/'" | sudo tee -a $final_path/conf/seahub_settings.py
ynh_replace_string http:// https:// $final_path/conf/ccnet.conf
ynh_replace_string :8000 $path $final_path/conf/ccnet.conf
echo 'FILE_SERVER_ROOT = "https://'$domain'/seafhttp"' | tee -a $final_path/conf/seahub_settings.py
echo 'SITE_ROOT = "'$path2'"' | tee -a $final_path/conf/seahub_settings.py
echo 'SERVE_STATIC = False' | tee -a $final_path/conf/seahub_settings.py
echo 'MEDIA_URL = "'$path2'media/"' | tee -a $final_path/conf/seahub_settings.py
echo 'COMPRESS_URL = MEDIA_URL' | tee -a $final_path/conf/seahub_settings.py
echo "STATIC_URL = MEDIA_URL + 'assets/'" | tee -a $final_path/conf/seahub_settings.py
echo "LOGIN_URL = '"$path2"accounts/login/'" | tee -a $final_path/conf/seahub_settings.py
# Email configuration
echo 'EMAIL_USE_TLS = False' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_HOST = "localhost"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_HOST_USER = "seafile@'$domain'"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_HOST_PASSWORD = ""' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_PORT = "25"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'DEFAULT_FROM_EMAIL = "seafile@'$domain'"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'SERVER_EMAIL = "seafile@'$domain'"' | sudo tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_USE_TLS = False' | tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_HOST = "localhost"' | tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_HOST_USER = "seafile@'$domain'"' | tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_HOST_PASSWORD = ""' | tee -a $final_path/conf/seahub_settings.py
echo 'EMAIL_PORT = "25"' | tee -a $final_path/conf/seahub_settings.py
echo 'DEFAULT_FROM_EMAIL = "seafile@'$domain'"' | tee -a $final_path/conf/seahub_settings.py
echo 'SERVER_EMAIL = "seafile@'$domain'"' | tee -a $final_path/conf/seahub_settings.py
# LDAP configuration
echo '[LDAP]' | sudo tee -a $final_path/conf/ccnet.conf
echo 'HOST = ldap://localhost:389' | sudo tee -a $final_path/conf/ccnet.conf
echo 'BASE = ou=users,dc=yunohost,dc=org' | sudo tee -a $final_path/conf/ccnet.conf
echo 'LOGIN_ATTR = mail' | sudo tee -a $final_path/conf/ccnet.conf
echo '[LDAP]' | tee -a $final_path/conf/ccnet.conf
echo 'HOST = ldap://localhost:389' | tee -a $final_path/conf/ccnet.conf
echo 'BASE = ou=users,dc=yunohost,dc=org' | tee -a $final_path/conf/ccnet.conf
echo 'LOGIN_ATTR = mail' | tee -a $final_path/conf/ccnet.conf
# Add Seafile Server to startup
sudo cp ../conf/seafile-server /etc/init.d
sudo sed -i "s@SEAHUB_PORT@$seahub_port@g" /etc/init.d/seafile-server
sudo sed -i "s@SEAFILE_DIR@$final_path@g" /etc/init.d/seafile-server
sudo chmod +x /etc/init.d/seafile-server
sudo update-rc.d seafile-server defaults
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE1@$path@g" ../conf/nginx.conf
sed -i "s@PATHTOCHANGE2@$path2@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sed -i "s@SEAHUB_PORT@$seahub_port@g" ../conf/nginx.conf
sed -i "s@SEAFILE_FILESERVER_PORT@$fileserver_port@g" ../conf/nginx.conf
sed -i "s@WEBDAV_PORT@$webdav_port@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/seafile.conf
# Fix local warning
ynh_replace_string en_US.UTF-8 $LANG $final_path/seafile-server-$seafile_version/seahub.sh
# Add webdav
sudo cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
sudo sed -i "s@WEBDAV_PORT@$webdav_port@g" $final_path/conf/seafdav.conf
cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
ynh_replace_string WEBDAV_PORT $webdav_port $final_path/conf/seafdav.conf
# Add Seafile Server to startup
cp ../conf/seafile-server /etc/init.d
ynh_replace_string SEAHUB_PORT $seahub_port /etc/init.d/seafile-server
ynh_replace_string SEAFILE_DIR $final_path /etc/init.d/seafile-server
chmod +x /etc/init.d/seafile-server
update-rc.d seafile-server defaults
# Config nginx
config_nginx
# Copy first launch script
sudo cp ../conf/first_launch.exp $final_path
sudo chmod +x $final_path/first_launch.exp
cp ../conf/first_launch.exp $final_path
chmod +x $final_path/first_launch.exp
# Set permissions to seafile directory
sudo chown -R $seafile_user:$seafile_user $final_path
sudo chown -R $seafile_user:$seafile_user $seafile_data
chown -R $seafile_user:$seafile_user $final_path
chown -R $seafile_user:$seafile_user $seafile_data
# Start seafile, seahub and populate admin account
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"
su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-$seafile_version/seafile.sh start"
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
sudo cp ../conf/remove_sso_conf.py $final_path
sudo python $final_path/add_sso_conf.py
cp ../conf/add_sso_conf.py $final_path
cp ../conf/remove_sso_conf.py $final_path
python $final_path/add_sso_conf.py
# unprotect media
ynh_app_setting_set seafile unprotected_uris "/media"
@ -151,22 +149,17 @@ if [ "$is_public" = "0" ]
then
ynh_app_setting_delete seafile unprotected_uris
else
ynh_app_setting_set seafile unprotected_uris "/"
ynh_app_setting_set seafile unprotected_uris "/"
fi
# 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
ynh_use_logrotate $final_path/logs/seaf-server.log
ynh_use_logrotate $final_path/logs/ccnet.log
# register yunohost service
sudo yunohost service add seafile-server
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app ssowatconf
yunohost service add seafile-server
# Restart seafile
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
su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-latest/seahub.sh stop"
systemctl stop seafile-server.service
systemctl start seafile-server.service # || (sleep 2 && systemctl start seafile-server.service)

View file

@ -1,32 +1,46 @@
#!/bin/bash
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
set -u
# Import common cmd
source ./_common.sh
# Init script
init_script
# Init get Final path
get_configuration
sudo service seafile-server stop || true
# Retrieve arguments
domain=$(ynh_app_setting_get $app domain)
systemctl stop seafile-server.service
# remove sso config to unprotect domain.tld/seafhttp in /etc/ssowat/conf.json.persistent
test -e /var/www/$app/remove_sso_conf.py && sudo python /var/www/$app/remove_sso_conf.py
test -e /opt/yunohost/$app/remove_sso_conf.py && sudo python /opt/yunohost/$app/remove_sso_conf.py
sudo rm -rf /var/www/$app
sudo rm -rf /opt/yunohost/$app
sudo rm -f /etc/init.d/seafile-server
sudo rm -rf /home/yunohost.app/seafile-data
sudo rm -rf /tmp/seahub_cache
test -e /var/www/$app/remove_sso_conf.py && python /var/www/$app/remove_sso_conf.py
test -e /opt/yunohost/$app/remove_sso_conf.py && python /opt/yunohost/$app/remove_sso_conf.py
ynh_secure_remove /var/www/$app
ynh_secure_remove /opt/yunohost/$app
ynh_secure_remove /etc/init.d/seafile-server
ynh_secure_remove /home/yunohost.app/seafile-data
ynh_secure_remove /tmp/seahub_cache
# Remove databases
root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE ccnetdb ; DROP DATABASE seafiledb ; DROP DATABASE seahubdb ; DROP USER seafile@localhost ;" || true
ynh_mysql_drop_db ccnetdb
ynh_mysql_drop_db seafiledb
ynh_mysql_drop_db seahubdb
# Remove depandance
ynh_remove_app_dependencies
# Remove domain config
domain=$(ynh_app_setting_get seafile domain)
sudo rm -f /etc/nginx/conf.d/$domain.d/seafile.conf
ynh_secure_remove /etc/nginx/conf.d/$domain.d/seafile.conf
sudo yunohost service remove seafile-server
# Remove logrotate
ynh_remove_logrotate
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf
yunohost service remove seafile-server
# Reload nginx
systemctl reload nginx.service

View file

@ -1,145 +1,73 @@
#!/bin/bash
######## 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
#
# Source YunoHost helpers
source /usr/share/yunohost/helpers
######## We implement manually this fonctions
# Stop script if errors
ynh_abort_if_errors
seafile_version=6.0.9
# Import common cmd
source ../settings/scripts/_common.sh
## Adapt md5sum while you update app
x86_64sum="8d1547c51feecaff757eb64381ce154c"
i386sum="8a0b9e08d9c80790752b435c3e148328"
armsum="15ca4b69585a990e00474e4cfc4be9eb"
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
}
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() {
if [[ $1 == 'rpi' ]]
then
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)
}
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
}
######## End of common fonctions
# Init script
init_script
# Init get Final path
get_configuration
# Retrieve arguments
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_normalize_url_path $(ynh_app_setting_get $app path))
db_pwd=$(ynh_app_setting_get ${app} mysqlpwd)
final_path=/var/www/$app
seafile_user=www-data
# The parameter $1 is the backup directory location dedicated to the app
BACKUP_DIR=$1
# retrieve useful param
domain=$(ynh_app_setting_get ${app} domain)
db_pwd=$(ynh_app_setting_get ${app} mysqlpwd)
path=$(ynh_app_setting_get ${app} path)
# Correct path if it is not correct
CHECK_PATH
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a ${app} \
|| (echo "Path not available: $domain$path" && ynh_die "Error : path not available")
ynh_webpath_available $domain $path || ynh_die "$domain/$path is not available, please use an other domain or path."
# Restore dependencies
sudo apt-get update
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
install_dependance
# Restore app files
final_path=$final_path
sudo mkdir -p $final_path
sudo cp -a "${BACKUP_DIR}/www/." $final_path
sudo chown -R $seafile_user:$seafile_user $final_path
# # Restore app files
# final_path=$final_path
# mkdir -p $final_path
# cp -a "${BACKUP_DIR}/www/." $final_path
# chown -R $seafile_user:$seafile_user $final_path
#
# # Restore conf files
# cp -a "${BACKUP_DIR}/conf/${app}.conf" /etc/nginx/conf.d/$domain.d/${app}.conf
# cp -a "${BACKUP_DIR}/conf/${app}" /etc/logrotate.d/${app}
# cp -a "${BACKUP_DIR}/conf/seafile-server" /etc/init.d/seafile-server
# chmod +x /etc/init.d/seafile-server
#
# # Restore data
# seafile_data=/home/yunohost.app/seafile-data
# mkdir -p $seafile_data
# cp -a "${BACKUP_DIR}/data/." /home/yunohost.app/seafile-data/.
# chown -R $seafile_user:$seafile_user $seafile_data
# Restore conf files
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}
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
sudo mkdir -p $seafile_data
sudo cp -a "${BACKUP_DIR}/data/." /home/yunohost.app/seafile-data/.
sudo chown -R $seafile_user:$seafile_user $seafile_data
# Restore all config and data
ynh_restore
# Restore mysql dump
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"
su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${YNH_CWD}/ccnetdb.dmp"
su -c "mysql -u ${app} -p$db_pwd seafiledb < ${YNH_CWD}/seafiledb.dmp"
su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp"
# Restore sso persistent config
sudo python $final_path/add_sso_conf.py
python $final_path/add_sso_conf.py
# Add logrotate
ynh_use_logrotate $final_path/logs/seaf-server.log
ynh_use_logrotate $final_path/logs/ccnet.log
# Add Seafile to YunoHost's monitored services
sudo yunohost service add seafile-server
yunohost service add seafile-server
# Reload/restart services
sudo update-rc.d seafile-server defaults
sudo service rsyslog restart
sudo yunohost app ssowatconf
sudo service nginx reload
# Reload nginx
systemctl reload nginx.service
# start seafile
sudo service seafile-server start
systemctl start seafile-server.service

View file

@ -1,143 +1,138 @@
#!/bin/bash
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
# Import common cmd
source ./_common.sh
# Init script
init_script
# Init get Final path
get_configuration
# Retrieve settings
# Retrieve arguments
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_normalize_url_path $(ynh_app_setting_get $app path))
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)
root_pwd=$(cat /etc/yunohost/mysql)
# Set configuration for user and final path
set_configuration
# Get configuration for user and final path
get_configuration
# Download new version from sources
get_source $architecture $seafile_version
# stop seafile server
sudo service seafile-server stop
systemctl stop seafile-server.service
# 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
test -e $final_path/seafile-server-$seafile_version && rm -rf "$final_path/seafile-server-$seafile_version"
extract_source
# 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
chmod +x ../conf/upgrade_*.exp
chmod +x ../conf/minor-upgrade.exp
chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_*.sh
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
../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
../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
../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
../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
../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
../conf/upgrade_6.0.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
"6.0."* )
python ../conf/update_sso_conf.py
install_dependance
# Update seafile by script
../conf/upgrade_6.1.exp $final_path/seafile-server-$seafile_version $root_pwd
;&
esac
sudo ../conf/minor-upgrade.exp $final_path/seafile-server-$seafile_version $root_pwd
../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
webdav_port=$(ynh_find_port 8080)
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
yunohost firewall disallow Both $ccnet_port
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
ynh_replace_string WEBDAV_PORT $webdav_port ../conf/nginx_add_webdav
echo $(cat ../conf/nginx_add_webdav) | 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
cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
ynh_replace_string WEBDAV_PORT $webdav_port $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
cp ../conf/add_sso_conf.py $final_path
cp ../conf/add_sso_conf_webdav.py $final_path
cp ../conf/remove_sso_conf.py $final_path
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
echo 'COMPRESS_URL = MEDIA_URL' | tee -a $final_path/conf/seahub_settings.py
echo "STATIC_URL = MEDIA_URL + 'assets/'" | 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
ynh_use_logrotate $final_path/logs/seaf-server.log
ynh_use_logrotate $final_path/logs/ccnet.log
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 ]]
if [[ $(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
echo "LOGIN_URL = '"$path"/accounts/login/'" | tee -a $final_path/conf/seahub_settings.py
fi
# Fix local warning
ynh_replace_string en_US.UTF-8 $LANG $final_path/seafile-server-$seafile_version/seahub.sh
# restore correct permissions
sudo chown -R $seafile_user:$seafile_user $final_path
chown -R $seafile_user:$seafile_user $final_path
# delete seafile cache
sudo rm -rf /tmp/seahub_cache
rm -rf /tmp/seahub_cache
# restart seafile server
sudo service seafile-server start
systemctl start seafile-server.service
# 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
rm -f $final_path/installed/seafile-server_${installed_version}*.tar*
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
# Reload nginx
systemctl reload nginx.service