diff --git a/.gitignore b/.gitignore index 9a92f39..3b43377 100644 --- a/.gitignore +++ b/.gitignore @@ -221,3 +221,4 @@ pip-log.txt # From kateproject .kateproject .kateproject.d +.directory diff --git a/README.md b/README.md index c76c2d1..f888939 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,15 @@ sudo adduser seafile --disabled-login --ingroup seafile --system --quiet --shell # 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 +sudo sed -i "s@alias /var/www/seafile/@alias /opt/yunohost/seafile/@g" /etc/nginx/conf.d/$(sudo yunohost app setting seafile domain).d/seafile.conf + +# Set the good user for seafile +sudo chown seafile:seafile -R /opt/yunohost/seafile +sudo chown seafile:seafile -R /home/yunohost.app/seafile-data/ # Restart services +sudo rm -rf /tmp/seahub_cache +sudo systemctl daemon-reload sudo service nginx reload sudo service seafile-server start ``` diff --git a/scripts/_common.sh b/scripts/_common.sh index 0ea0676..4a2cf79 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,11 +1,39 @@ #!/bin/bash +seafile_version=6.0.7 + +## Adapt md5sum while you update app +x86_64sum="4ca3c1fc93e5b786eb5d3509f4a3b01a" +i386sum="743565be00189698318c8def0fbdaac0" +armsum="ee3ef5330a51498faf861594e0fe744a" + +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 +} + +correct_path() { + if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then + path="/$path" + fi + if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then + path="${path:0:${#path}-1}" + 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 @@ -13,16 +41,21 @@ set_configuration() { 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' + 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 -O '/tmp/seafile_src.tar.gz' 'https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_'$1'_'$2'.tar.gz' + 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' ]] + 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 diff --git a/scripts/backup b/scripts/backup index 2efaa52..1519bbc 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,10 +1,17 @@ #!/bin/bash -set -e +# Exit on command errors and treat unset variables as an error +set -eu + +# Source YunoHost helpers +source /usr/share/yunohost/helpers # Import common cmd source ./_common.sh +# Retrieve arguments +app=$YNH_APP_INSTANCE_NAME + # Set configuration for user and final path set_configuration diff --git a/scripts/install b/scripts/install index bb92157..24d1573 100644 --- a/scripts/install +++ b/scripts/install @@ -1,30 +1,29 @@ #!/bin/bash -app=seafile - -# Retrieve arguments -domain=$1 -path=$2 -server_name=$3 -admin=$4 -admin_password=$5 -is_public=$6 -architecture=$7 -seafile_data=/home/yunohost.app/seafile-data -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 +# Init script +init_script + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +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 +correct_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") +sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path}" # Download new version from sources get_source $architecture $seafile_version @@ -36,14 +35,9 @@ port='' findPort () { port=$1 - sudo yunohost app checkport $port - while [[ ! $? -eq 0 ]] - do - port=$(($port + 1)) - sudo yunohost app checkport $port - done - - return $port + while ! sudo yunohost app checkport $port ; do + port=$(($port + 1)) + done } # Check dependencies @@ -51,6 +45,8 @@ sudo apt-get update sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect # 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 @@ -58,7 +54,7 @@ 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 ../sources/'seafile-server_'$seafile_version'_'$architecture'.tar.gz' $final_path/installed +sudo mv '/tmp/seafile_src.tar.gz' $final_path/installed/seafile-server_${seafile_version}.tar.gz # Find available ports findPort 8000 @@ -98,6 +94,7 @@ echo 'SERVE_STATIC = False' | sudo tee -a $final_path/conf/seahub_settings.py echo 'MEDIA_URL = "'$path'/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 = '"$path"/accounts/login/'" | sudo tee -a $final_path/conf/seahub_settings.py # Email configuration echo 'EMAIL_USE_TLS = False' | sudo tee -a $final_path/conf/seahub_settings.py diff --git a/scripts/remove b/scripts/remove index 269756e..b9ed7eb 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,26 +1,29 @@ #!/bin/bash -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 +# Init script +init_script -sudo service seafile-server stop +sudo service seafile-server stop || true # remove sso config to unprotect domain.tld/seafhttp in /etc/ssowat/conf.json.persistent -sudo python $final_path/remove_sso_conf.py - -sudo rm -rf $final_path -sudo rm -f /etc/nginx/conf.d/$domain.d/seafile.conf +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 -r /tmp/seahub_cache +sudo rm -rf /tmp/seahub_cache # Remove databases -mysql -u root -p$root_pwd -e "DROP DATABASE ccnetdb ; DROP DATABASE seafiledb ; DROP DATABASE seahubdb ; DROP USER seafile@localhost ;" +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 + +# Remove domain config +domain=$(ynh_app_setting_get seafile domain) +sudo rm -f /etc/nginx/conf.d/$domain.d/seafile.conf sudo yunohost service remove seafile-server diff --git a/scripts/restore b/scripts/restore index fed7178..bd6478b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,12 +1,14 @@ #!/bin/bash -set -e - # Import common cmd source ./_common.sh -# Set configuration for user and final path -set_configuration +# Init script +init_script + +# Retrieve arguments +final_path=/var/www/$app +seafile_user=www-data # The parameter $1 is the backup directory location dedicated to the app BACKUP_DIR=$1 @@ -19,10 +21,13 @@ domain=$(ynh_app_setting_get ${APP} domain) db_pwd=$(ynh_app_setting_get ${APP} db_pwd) path=$(ynh_app_setting_get ${APP} path) +# Correct path if it is not correct +correct_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") - + # Restore dependencies sudo apt-get update sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect diff --git a/scripts/upgrade b/scripts/upgrade index dbb0b8c..6ca0716 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,33 +1,35 @@ #!/bin/bash -app=seafile - -# Retrieve settings -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=6.0.6 - -# Source YunoHost helpers -source /usr/share/yunohost/helpers - # Import common cmd source ./_common.sh +# Init script +init_script + +# Retrieve settings +installed_version=$(ynh_app_setting_get $app installed_version) +path=$(ynh_app_setting_get "$app" path) +architecture=$(ynh_app_setting_get $app architecture) +root_pwd=$(sudo cat /etc/yunohost/mysql) + +# Correct path if it is not correct +correct_path + # 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 ../sources/'seafile-server_'$seafile_version'_'$architecture'.tar.gz' $final_path/installed - -# stop seafile server -sudo service seafile-server stop +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_4.1.1.exp @@ -133,8 +135,8 @@ then sudo python $final_path/add_sso_conf_webdav.py # Update seafile config - echo 'COMPRESS_URL = MEDIA_URL' | sudo tee -a $final_path/seahub_settings.py - echo "STATIC_URL = MEDIA_URL + 'assets/'" | sudo tee -a $final_path/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 # Add logrotate sudo cp ../conf/logrotate /etc/logrotate.d/seafile @@ -142,21 +144,27 @@ then 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 -r /tmp/seahub_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_$architecture.tar* -sudo rm -f $final_path/seafile-server_$installed_version_$architecture +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 seafile installed_version -v $seafile_version +ynh_app_setting_set $app installed_version $seafile_version # Reload Nginx and regenerate SSOwat conf sudo service nginx reload